Skip to content

Commit

Permalink
feat: full screen viewer (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba authored Nov 27, 2024
1 parent 8d66833 commit 3bc7b75
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
8 changes: 6 additions & 2 deletions Sources/Screens/File/FileGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct FileGrid: View, ListItemScrollable {
@ObservedObject private var fileStore: FileStore
@ObservedObject private var workspaceStore: WorkspaceStore
@State private var tappedItem: VOFile.Entity?
@State private var viewerIsPresented: Bool = false

init(fileStore: FileStore, workspaceStore: WorkspaceStore) {
self.fileStore = fileStore
Expand All @@ -36,6 +37,7 @@ struct FileGrid: View, ListItemScrollable {
Button {
if file.snapshot?.status == .ready {
tappedItem = file
viewerIsPresented = true
}
} label: {
FileCell(file, fileStore: fileStore)
Expand All @@ -58,8 +60,10 @@ struct FileGrid: View, ListItemScrollable {
}
}
}
.navigationDestination(item: $tappedItem) {
Viewer($0)
.fullScreenCover(isPresented: $viewerIsPresented) {
if let tappedItem {
Viewer(tappedItem)
}
}
.modifierIfPhone {
$0.padding(.vertical, VOMetrics.spacing)
Expand Down
8 changes: 6 additions & 2 deletions Sources/Screens/File/FileList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct FileList: View, ListItemScrollable {
@ObservedObject private var fileStore: FileStore
@ObservedObject private var workspaceStore: WorkspaceStore
@State private var tappedItem: VOFile.Entity?
@State private var viewerIsPresented: Bool = false

init(fileStore: FileStore, workspaceStore: WorkspaceStore) {
self.fileStore = fileStore
Expand All @@ -29,6 +30,7 @@ struct FileList: View, ListItemScrollable {
Button {
if file.snapshot?.status == .ready {
tappedItem = file
viewerIsPresented = true
}
} label: {
FileRow(file)
Expand All @@ -52,8 +54,10 @@ struct FileList: View, ListItemScrollable {
}
}
.listStyle(.inset)
.navigationDestination(item: $tappedItem) {
Viewer($0)
.fullScreenCover(isPresented: $viewerIsPresented) {
if let tappedItem {
Viewer(tappedItem)
}
}
}
}
Expand Down
37 changes: 21 additions & 16 deletions Sources/Screens/Viewer/Viewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,36 @@ import SwiftUI
import VoltaserveCore

struct Viewer: View {
@Environment(\.presentationMode) private var presentationMode
@State private var isImmersiveMode: Bool = false
private let file: VOFile.Entity

init(_ file: VOFile.Entity) {
self.file = file
}

var body: some View {
VStack {
ViewerPDF(file)
ViewerImage(file)
ViewerVideo(file)
ViewerAudio(file)
Viewer3D(file)
if UIDevice.current.userInterfaceIdiom == .pad {
NavigationView {
VStack {
ViewerPDF(file)
ViewerImage(file)
ViewerVideo(file)
ViewerAudio(file)
Viewer3D(file)
ViewerMosaic(file)
.edgesIgnoringSafeArea(.bottom)
} else {
ViewerMosaic(file)
.edgesIgnoringSafeArea(.horizontal)
}
}
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(file.name)
.modifierIfPad {
$0.edgesIgnoringSafeArea(.bottom)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(file.name)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button {
presentationMode.wrappedValue.dismiss()
} label: {
Image(systemName: "xmark")
}
}
}
.edgesIgnoringSafeArea(.bottom)
}
}
}

0 comments on commit 3bc7b75

Please sign in to comment.