mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-25 04:48:16 -04:00
Merge pull request #716 from kiwix/714-ios-opening-the-main-page-from-the-zimfile-details-dont-close-the-presented-sheet
Dismiss modals on iOS when opening main page
This commit is contained in:
commit
c8bac02c4c
@ -143,7 +143,7 @@ struct RootView: View {
|
||||
case .bookmarks:
|
||||
Bookmarks()
|
||||
case .opened:
|
||||
ZimFilesOpened().modifier(LibraryZimFileDetailSidePanel())
|
||||
ZimFilesOpened(dismiss: nil).modifier(LibraryZimFileDetailSidePanel())
|
||||
case .categories:
|
||||
ZimFilesCategories().modifier(LibraryZimFileDetailSidePanel())
|
||||
case .downloads:
|
||||
|
@ -113,6 +113,10 @@ private struct CompactView: View {
|
||||
case library, settings
|
||||
}
|
||||
|
||||
private func dismiss() {
|
||||
presentedSheet = nil
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if case let .tab(tabID) = navigation.currentItem {
|
||||
Content()
|
||||
@ -148,7 +152,7 @@ private struct CompactView: View {
|
||||
.sheet(item: $presentedSheet) { presentedSheet in
|
||||
switch presentedSheet {
|
||||
case .library:
|
||||
Library()
|
||||
Library(dismiss: dismiss)
|
||||
case .settings:
|
||||
NavigationView {
|
||||
Settings().toolbar {
|
||||
|
@ -113,7 +113,7 @@ final class SplitViewController: UISplitViewController {
|
||||
}()
|
||||
setViewController(UINavigationController(rootViewController: controller), for: .secondary)
|
||||
case .opened:
|
||||
let controller = UIHostingController(rootView: ZimFilesOpened())
|
||||
let controller = UIHostingController(rootView: ZimFilesOpened(dismiss: nil))
|
||||
setViewController(UINavigationController(rootViewController: controller), for: .secondary)
|
||||
case .categories:
|
||||
let controller = UIHostingController(rootView: ZimFilesCategories())
|
||||
|
@ -18,9 +18,11 @@ struct Library: View {
|
||||
|
||||
private let defaultTabItem: LibraryTabItem?
|
||||
private let categories: [Category]
|
||||
let dismiss: (() -> Void)?
|
||||
|
||||
init(tabItem: LibraryTabItem? = nil) {
|
||||
init(dismiss: (() -> Void)?, tabItem: LibraryTabItem? = nil) {
|
||||
self.defaultTabItem = tabItem
|
||||
self.dismiss = dismiss
|
||||
categories = CategoriesToLanguages.allCategories()
|
||||
}
|
||||
|
||||
@ -30,7 +32,7 @@ struct Library: View {
|
||||
SheetContent {
|
||||
switch tabItem {
|
||||
case .opened:
|
||||
ZimFilesOpened()
|
||||
ZimFilesOpened(dismiss: dismiss)
|
||||
case .categories:
|
||||
List(categories) { category in
|
||||
NavigationLink {
|
||||
@ -68,7 +70,7 @@ struct Library: View {
|
||||
struct Library_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
Library()
|
||||
Library(dismiss: nil)
|
||||
.environmentObject(LibraryViewModel())
|
||||
.environment(\.managedObjectContext, Database.viewContext)
|
||||
}
|
||||
@ -88,7 +90,7 @@ struct LibraryZimFileDetailSidePanel: ViewModifier {
|
||||
HStack(spacing: 0) {
|
||||
Divider()
|
||||
if let zimFile = viewModel.selectedZimFile {
|
||||
ZimFileDetail(zimFile: zimFile)
|
||||
ZimFileDetail(zimFile: zimFile, dismissParent: nil)
|
||||
} else {
|
||||
Message(text: "library.zim_file_details.side_panel.message".localized)
|
||||
.background(.thickMaterial)
|
||||
@ -106,7 +108,13 @@ struct LibraryZimFileContext: ViewModifier {
|
||||
@EnvironmentObject private var viewModel: LibraryViewModel
|
||||
|
||||
let zimFile: ZimFile
|
||||
|
||||
let dismiss: (() -> Void)? // iOS only
|
||||
|
||||
init(zimFile: ZimFile, dismiss: (() -> Void)? = nil) {
|
||||
self.zimFile = zimFile
|
||||
self.dismiss = dismiss
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
Group {
|
||||
#if os(macOS)
|
||||
@ -117,7 +125,7 @@ struct LibraryZimFileContext: ViewModifier {
|
||||
}.buttonStyle(.plain)
|
||||
#elseif os(iOS)
|
||||
NavigationLink {
|
||||
ZimFileDetail(zimFile: zimFile)
|
||||
ZimFileDetail(zimFile: zimFile, dismissParent: dismiss)
|
||||
} label: {
|
||||
content
|
||||
}
|
||||
|
@ -15,13 +15,14 @@ import Defaults
|
||||
/// Detail about one single zim file.
|
||||
struct ZimFileDetail: View {
|
||||
@Default(.downloadUsingCellular) private var downloadUsingCellular
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@ObservedObject var zimFile: ZimFile
|
||||
@State private var isPresentingDeleteAlert = false
|
||||
@State private var isPresentingDownloadAlert = false
|
||||
@State private var isPresentingFileLocator = false
|
||||
@State private var isPresentingUnlinkAlert = false
|
||||
|
||||
let dismissParent: (() -> Void)? // iOS only
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
List {
|
||||
@ -89,6 +90,9 @@ struct ZimFileDetail: View {
|
||||
Action(title: "zim_file.action.open_main_page.title".localized) {
|
||||
guard let url = ZimFileService.shared.getMainPageURL(zimFileID: zimFile.fileID) else { return }
|
||||
NotificationCenter.openURL(url, inNewTab: true)
|
||||
#if os(iOS)
|
||||
dismissParent?()
|
||||
#endif
|
||||
}
|
||||
#if os(macOS)
|
||||
Action(title: "zim_file.action.reveal_in_finder.title".localized) {
|
||||
@ -123,7 +127,7 @@ struct ZimFileDetail: View {
|
||||
primaryButton: .destructive(Text("zim_file.action.unlink.button.title".localized)) {
|
||||
LibraryOperations.unlink(zimFileID: zimFile.fileID)
|
||||
#if os(iOS)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
dismiss()
|
||||
#endif
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
@ -141,7 +145,7 @@ struct ZimFileDetail: View {
|
||||
primaryButton: .destructive(Text("zim_file.action.delete.button.title".localized)) {
|
||||
LibraryOperations.delete(zimFileID: zimFile.fileID)
|
||||
#if os(iOS)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
dismiss()
|
||||
#endif
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
@ -347,6 +351,6 @@ struct ZimFileDetail_Previews: PreviewProvider {
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
ZimFileDetail(zimFile: zimFile).frame(width: 300).previewLayout(.sizeThatFits)
|
||||
ZimFileDetail(zimFile: zimFile, dismissParent: nil).frame(width: 300).previewLayout(.sizeThatFits)
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ struct ZimFilesOpened: View {
|
||||
animation: .easeInOut
|
||||
) private var zimFiles: FetchedResults<ZimFile>
|
||||
@State private var isFileImporterPresented = false
|
||||
|
||||
let dismiss: (() -> Void)? // iOS only
|
||||
|
||||
var body: some View {
|
||||
LazyVGrid(
|
||||
columns: ([GridItem(.adaptive(minimum: 250, maximum: 500), spacing: 12)]),
|
||||
@ -26,7 +27,8 @@ struct ZimFilesOpened: View {
|
||||
spacing: 12
|
||||
) {
|
||||
ForEach(zimFiles) { zimFile in
|
||||
ZimFileCell(zimFile, prominent: .name).modifier(LibraryZimFileContext(zimFile: zimFile))
|
||||
ZimFileCell(zimFile, prominent: .name).modifier(LibraryZimFileContext(zimFile: zimFile,
|
||||
dismiss: self.dismiss))
|
||||
}
|
||||
}
|
||||
.modifier(GridCommon(edges: .all))
|
||||
|
@ -58,7 +58,7 @@ struct Welcome: View {
|
||||
}
|
||||
#if os(iOS)
|
||||
.sheet(isPresented: $isLibraryPresented) {
|
||||
Library(tabItem: .categories)
|
||||
Library(dismiss: { isLibraryPresented = false }, tabItem: .categories)
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user