From 05cdd7734a2303aef4210af3e5b65f74f2a01b21 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 27 Mar 2024 10:37:03 +0800 Subject: [PATCH] Handle push notifications from the tab view on iOS --- .../Sources/App/Views/LibraryTabView.swift | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift b/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift index 0c23137de..f8a16d598 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift @@ -23,6 +23,8 @@ struct LibraryTabView: View { @State var isEditMode: EditMode = .inactive @State var showExpandedAudioPlayer = false + @State var presentPushContainer = true + @State var pushLinkRequest: String? private let syncManager = LibrarySyncManager() @@ -77,13 +79,34 @@ struct LibraryTabView: View { var body: some View { VStack(spacing: 0) { WindowLink(level: .alert, transition: .move(edge: .bottom), isPresented: $showOperationToast) { - OperationToast(operationMessage: $operationMessage, + OperationToast(operationMessage: $operationMessage, showOperationToast: $showOperationToast, operationStatus: $operationStatus) } label: { EmptyView() }.buttonStyle(.plain) + if let pushLinkRequest = pushLinkRequest { + PresentationLink( + transition: PresentationLinkTransition.slide( + options: PresentationLinkTransition.SlideTransitionOptions( + edge: .trailing, + options: PresentationLinkTransition.Options( + modalPresentationCapturesStatusBarAppearance: true, + preferredPresentationBackgroundColor: ThemeManager.currentBgColor + ))), + isPresented: $presentPushContainer, + destination: { + WebReaderLoadingContainer(requestID: pushLinkRequest) + .background(ThemeManager.currentBgColor) + .environmentObject(dataService) + .environmentObject(audioController) + }, label: { + EmptyView() + } + ) + } + TabView(selection: $selectedTab) { if !hideFollowingTab { NavigationView { @@ -145,15 +168,9 @@ struct LibraryTabView: View { } } .onReceive(NotificationCenter.default.publisher(for: Notification.Name("PushLibraryItem"))) { notification in - guard let folder = notification.userInfo?["libraryItemId"] as? String else { return } guard let libraryItemId = notification.userInfo?["libraryItemId"] as? String else { return } - if folder == "following" { - selectedTab = "following" - followingViewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId)) - } else { - selectedTab = "inbox" - inboxViewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId)) - } + pushLinkRequest = libraryItemId + presentPushContainer = true } .onOpenURL { url in inboxViewModel.linkRequest = nil