From c63779ce1b0c266c54bf4f02e9717f0a49912099 Mon Sep 17 00:00:00 2001 From: Anass Bouassaba Date: Wed, 27 Nov 2024 13:26:15 +0100 Subject: [PATCH 1/2] feat: full screen viewer --- Sources/Screens/File/FileGrid.swift | 8 +++++-- Sources/Screens/File/FileList.swift | 8 +++++-- Sources/Screens/Viewer/Viewer.swift | 37 ++++++++++++++++------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Sources/Screens/File/FileGrid.swift b/Sources/Screens/File/FileGrid.swift index 0d97c51..82f14ec 100644 --- a/Sources/Screens/File/FileGrid.swift +++ b/Sources/Screens/File/FileGrid.swift @@ -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 @@ -36,6 +37,7 @@ struct FileGrid: View, ListItemScrollable { Button { if file.snapshot?.status == .ready { tappedItem = file + viewerIsPresented = true } } label: { FileCell(file, fileStore: fileStore) @@ -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) diff --git a/Sources/Screens/File/FileList.swift b/Sources/Screens/File/FileList.swift index 42cbb5a..f4d23b1 100644 --- a/Sources/Screens/File/FileList.swift +++ b/Sources/Screens/File/FileList.swift @@ -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 @@ -29,6 +30,7 @@ struct FileList: View, ListItemScrollable { Button { if file.snapshot?.status == .ready { tappedItem = file + viewerIsPresented = true } } label: { FileRow(file) @@ -52,8 +54,10 @@ struct FileList: View, ListItemScrollable { } } .listStyle(.inset) - .navigationDestination(item: $tappedItem) { - Viewer($0) + .fullScreenCover(isPresented: $viewerIsPresented) { + if let tappedItem { + Viewer(tappedItem) + } } } } diff --git a/Sources/Screens/Viewer/Viewer.swift b/Sources/Screens/Viewer/Viewer.swift index a1f44b4..3643429 100644 --- a/Sources/Screens/Viewer/Viewer.swift +++ b/Sources/Screens/Viewer/Viewer.swift @@ -12,6 +12,8 @@ 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) { @@ -19,24 +21,27 @@ struct Viewer: View { } 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(action: { + presentationMode.wrappedValue.dismiss() + }) { + Image(systemName: "xmark") + } + } + } + .edgesIgnoringSafeArea(.bottom) } } } From e34dcf698c6f651a1ffdf06369666538da36c689 Mon Sep 17 00:00:00 2001 From: Anass Bouassaba Date: Wed, 27 Nov 2024 13:28:28 +0100 Subject: [PATCH 2/2] refactor: improve syntax --- Sources/Screens/Viewer/Viewer.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Screens/Viewer/Viewer.swift b/Sources/Screens/Viewer/Viewer.swift index 3643429..d51cad4 100644 --- a/Sources/Screens/Viewer/Viewer.swift +++ b/Sources/Screens/Viewer/Viewer.swift @@ -34,9 +34,9 @@ struct Viewer: View { .navigationTitle(file.name) .toolbar { ToolbarItem(placement: .topBarLeading) { - Button(action: { + Button { presentationMode.wrappedValue.dismiss() - }) { + } label: { Image(systemName: "xmark") } }