taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit cfa93217e17bcb31a0300d950bb78a2fde61746f
parent d8fa902d8e62859039f11eecd9c694299394d592
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 18 Apr 2026 11:57:09 +0200

Share via notification

Diffstat:
MTalerWallet1/Controllers/PublicConstants.swift | 2++
MTalerWallet1/Views/HelperViews/CopyShare.swift | 16+++++++++++++++-
MTalerWallet1/Views/Main/MainView.swift | 7+++++++
MTalerWallet1/Views/ViewModifier/View+dismissTop.swift | 2+-
4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift @@ -185,6 +185,7 @@ public let TRANSACTIONID = "transactionID" public let NOTIFICATIONTIME = "notif.time" public let NOTIFICATIONERROR = "notif.error" public let NOTIFICATIONANIMATION = "notif.animation" +public let NOTIFICATIONSHARE = "notif.share" /// Notifications sent by wallet-core extension Notification.Name { @@ -226,4 +227,5 @@ extension Notification.Name { static let WithdrawAction = Notification.Name("withdrawAction") static let QrScanAction = Notification.Name("qrScanAction") static let SettingsAction = Notification.Name("settingsAction") + static let ShareAction = Notification.Name("shareAction") } diff --git a/TalerWallet1/Views/HelperViews/CopyShare.swift b/TalerWallet1/Views/HelperViews/CopyShare.swift @@ -145,6 +145,11 @@ struct CopyButton: View { } } // MARK: - +struct ShareType: Hashable { + let textToShare: String + let image: UIImage? +} +// MARK: - @MainActor struct ShareButton: View { private let symLog = SymLogV(0) @@ -168,6 +173,14 @@ struct ShareButton: View { @Environment(\.isEnabled) private var isEnabled: Bool @EnvironmentObject private var controller: Controller + @MainActor + func dismissAndPost() { + dismissTop() + let shareType = ShareType(textToShare: textToShare, image: image) + let userInfo = [NOTIFICATIONSHARE: shareType] + NotificationCenter.default.post(name: .ShareAction, object: nil, userInfo: userInfo) // will trigger NavigationLink + } + func shareAction() -> Void { symLog.log(textToShare) controller.hapticFeedback(.soft) @@ -181,7 +194,8 @@ struct ShareButton: View { withAnimation(.easeOut(duration: 0.25)) { scale = 1.15 } - ShareSheet.shareSheet(textToShare: textToShare, image: image) +// ShareSheet.shareSheet(textToShare: textToShare, image: image) + dismissAndPost() } // Finally settle to normal DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) { diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -589,6 +589,13 @@ extension MainView { } } } + .onNotification(.ShareAction){ notification in + if let actionData = notification.userInfo?[NOTIFICATIONSHARE] as? ShareType { + let textToShare = actionData.textToShare + let image = actionData.image + ShareSheet.shareSheet(textToShare: textToShare, image: image) + } + } .alert("You need to pass a legitimization procedure.", isPresented: $showKycAlert, actions: { openKycButton diff --git a/TalerWallet1/Views/ViewModifier/View+dismissTop.swift b/TalerWallet1/Views/ViewModifier/View+dismissTop.swift @@ -23,7 +23,7 @@ import SwiftUI /// so we are walking the view stack to find the top presentedViewController (UIKit) and dismiss it. extension View { @MainActor @discardableResult - func dismissTop(_ stack: CallStack, animated: Bool = true) -> Bool { + func dismissTop(_ stack: CallStack? = nil, animated: Bool = true) -> Bool { let windows = UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow // TODO: iPad might have more than 1 window }