diff --git a/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift b/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift index 8778babb..6f5a4fe7 100644 --- a/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift +++ b/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift @@ -84,7 +84,7 @@ struct AddProviderView: View { .navigationTitle(L10n.AddProfile.Shared.title) .sheet(isPresented: $viewModel.isPaywallPresented) { NavigationView { - PaywallView() + PaywallView(isPresented: $viewModel.isPaywallPresented) }.themeGlobal() }.onAppear { refreshProviders() diff --git a/Passepartout/App/iOS/Views/OrganizerView.swift b/Passepartout/App/iOS/Views/OrganizerView.swift index 388c7cb3..d83d1b68 100644 --- a/Passepartout/App/iOS/Views/OrganizerView.swift +++ b/Passepartout/App/iOS/Views/OrganizerView.swift @@ -164,7 +164,10 @@ extension OrganizerView { case .presentPaywallShortcuts: NavigationView { - PaywallView(feature: .siriShortcuts) + PaywallView( + modalType: $modalType, + feature: .siriShortcuts + ) }.themeGlobal() } } diff --git a/Passepartout/App/iOS/Views/Paywall/PaywallView+Purchase.swift b/Passepartout/App/iOS/Views/Paywall/PaywallView+Purchase.swift index ef75ca94..25a42db3 100644 --- a/Passepartout/App/iOS/Views/Paywall/PaywallView+Purchase.swift +++ b/Passepartout/App/iOS/Views/Paywall/PaywallView+Purchase.swift @@ -53,9 +53,9 @@ extension PaywallView { @Environment(\.scenePhase) private var scenePhase - @Environment(\.presentationMode) private var presentationMode - @ObservedObject private var productManager: ProductManager + + @Binding private var isPresented: Bool private let feature: LocalProduct? @@ -63,8 +63,9 @@ extension PaywallView { @State private var purchaseState: PurchaseState? - init(feature: LocalProduct? = nil) { + init(isPresented: Binding, feature: LocalProduct? = nil) { productManager = .shared + _isPresented = isPresented self.feature = feature } @@ -149,7 +150,7 @@ extension PaywallView.PurchaseView { case .success(let result): switch result { case .done: - presentationMode.wrappedValue.dismiss() + isPresented = false case .cancelled: break @@ -172,7 +173,7 @@ extension PaywallView.PurchaseView { alertType = .restoreFailed(error) return } - presentationMode.wrappedValue.dismiss() + isPresented = false purchaseState = nil } } diff --git a/Passepartout/App/iOS/Views/Paywall/PaywallView.swift b/Passepartout/App/iOS/Views/Paywall/PaywallView.swift index 3128d928..61dd240f 100644 --- a/Passepartout/App/iOS/Views/Paywall/PaywallView.swift +++ b/Passepartout/App/iOS/Views/Paywall/PaywallView.swift @@ -28,10 +28,24 @@ import SwiftUI struct PaywallView: View { @ObservedObject private var productManager: ProductManager - private let feature: LocalProduct? + @Binding private var isPresented: Bool - init(feature: LocalProduct? = nil) { + private let feature: LocalProduct? + + init(modalType: Binding, feature: LocalProduct? = nil) { + let isPresented = Binding { + modalType.wrappedValue != nil + } set: { + if !$0 { + modalType.wrappedValue = nil + } + } + self.init(isPresented: isPresented, feature: feature) + } + + init(isPresented: Binding, feature: LocalProduct? = nil) { productManager = .shared + _isPresented = isPresented self.feature = feature } @@ -40,7 +54,10 @@ struct PaywallView: View { if productManager.cfg.appType == .beta { BetaView() } else { - PurchaseView(feature: feature) + PurchaseView( + isPresented: $isPresented, + feature: feature + ) } }.themeSecondaryView() } diff --git a/Passepartout/App/iOS/Views/ProfileView.swift b/Passepartout/App/iOS/Views/ProfileView.swift index 638c1826..a4dfe52e 100644 --- a/Passepartout/App/iOS/Views/ProfileView.swift +++ b/Passepartout/App/iOS/Views/ProfileView.swift @@ -126,6 +126,7 @@ struct ProfileView: View { case .paywallTrustedNetworks: NavigationView { PaywallView( + modalType: $modalType, feature: .trustedNetworks ) }.themeGlobal()