Dismiss paywall predictably with Binding<Bool>
This commit is contained in:
parent
e7a5d82056
commit
320513dd38
|
@ -84,7 +84,7 @@ struct AddProviderView: View {
|
||||||
.navigationTitle(L10n.AddProfile.Shared.title)
|
.navigationTitle(L10n.AddProfile.Shared.title)
|
||||||
.sheet(isPresented: $viewModel.isPaywallPresented) {
|
.sheet(isPresented: $viewModel.isPaywallPresented) {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
PaywallView()
|
PaywallView(isPresented: $viewModel.isPaywallPresented)
|
||||||
}.themeGlobal()
|
}.themeGlobal()
|
||||||
}.onAppear {
|
}.onAppear {
|
||||||
refreshProviders()
|
refreshProviders()
|
||||||
|
|
|
@ -164,7 +164,10 @@ extension OrganizerView {
|
||||||
|
|
||||||
case .presentPaywallShortcuts:
|
case .presentPaywallShortcuts:
|
||||||
NavigationView {
|
NavigationView {
|
||||||
PaywallView(feature: .siriShortcuts)
|
PaywallView(
|
||||||
|
modalType: $modalType,
|
||||||
|
feature: .siriShortcuts
|
||||||
|
)
|
||||||
}.themeGlobal()
|
}.themeGlobal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ extension PaywallView {
|
||||||
|
|
||||||
@Environment(\.scenePhase) private var scenePhase
|
@Environment(\.scenePhase) private var scenePhase
|
||||||
|
|
||||||
@Environment(\.presentationMode) private var presentationMode
|
|
||||||
|
|
||||||
@ObservedObject private var productManager: ProductManager
|
@ObservedObject private var productManager: ProductManager
|
||||||
|
|
||||||
|
@Binding private var isPresented: Bool
|
||||||
|
|
||||||
private let feature: LocalProduct?
|
private let feature: LocalProduct?
|
||||||
|
|
||||||
|
@ -63,8 +63,9 @@ extension PaywallView {
|
||||||
|
|
||||||
@State private var purchaseState: PurchaseState?
|
@State private var purchaseState: PurchaseState?
|
||||||
|
|
||||||
init(feature: LocalProduct? = nil) {
|
init(isPresented: Binding<Bool>, feature: LocalProduct? = nil) {
|
||||||
productManager = .shared
|
productManager = .shared
|
||||||
|
_isPresented = isPresented
|
||||||
self.feature = feature
|
self.feature = feature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ extension PaywallView.PurchaseView {
|
||||||
case .success(let result):
|
case .success(let result):
|
||||||
switch result {
|
switch result {
|
||||||
case .done:
|
case .done:
|
||||||
presentationMode.wrappedValue.dismiss()
|
isPresented = false
|
||||||
|
|
||||||
case .cancelled:
|
case .cancelled:
|
||||||
break
|
break
|
||||||
|
@ -172,7 +173,7 @@ extension PaywallView.PurchaseView {
|
||||||
alertType = .restoreFailed(error)
|
alertType = .restoreFailed(error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
presentationMode.wrappedValue.dismiss()
|
isPresented = false
|
||||||
purchaseState = nil
|
purchaseState = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,24 @@ import SwiftUI
|
||||||
struct PaywallView: View {
|
struct PaywallView: View {
|
||||||
@ObservedObject private var productManager: ProductManager
|
@ObservedObject private var productManager: ProductManager
|
||||||
|
|
||||||
private let feature: LocalProduct?
|
@Binding private var isPresented: Bool
|
||||||
|
|
||||||
init(feature: LocalProduct? = nil) {
|
private let feature: LocalProduct?
|
||||||
|
|
||||||
|
init<MT>(modalType: Binding<MT?>, feature: LocalProduct? = nil) {
|
||||||
|
let isPresented = Binding<Bool> {
|
||||||
|
modalType.wrappedValue != nil
|
||||||
|
} set: {
|
||||||
|
if !$0 {
|
||||||
|
modalType.wrappedValue = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.init(isPresented: isPresented, feature: feature)
|
||||||
|
}
|
||||||
|
|
||||||
|
init(isPresented: Binding<Bool>, feature: LocalProduct? = nil) {
|
||||||
productManager = .shared
|
productManager = .shared
|
||||||
|
_isPresented = isPresented
|
||||||
self.feature = feature
|
self.feature = feature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +54,10 @@ struct PaywallView: View {
|
||||||
if productManager.cfg.appType == .beta {
|
if productManager.cfg.appType == .beta {
|
||||||
BetaView()
|
BetaView()
|
||||||
} else {
|
} else {
|
||||||
PurchaseView(feature: feature)
|
PurchaseView(
|
||||||
|
isPresented: $isPresented,
|
||||||
|
feature: feature
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}.themeSecondaryView()
|
}.themeSecondaryView()
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,7 @@ struct ProfileView: View {
|
||||||
case .paywallTrustedNetworks:
|
case .paywallTrustedNetworks:
|
||||||
NavigationView {
|
NavigationView {
|
||||||
PaywallView(
|
PaywallView(
|
||||||
|
modalType: $modalType,
|
||||||
feature: .trustedNetworks
|
feature: .trustedNetworks
|
||||||
)
|
)
|
||||||
}.themeGlobal()
|
}.themeGlobal()
|
||||||
|
|
Loading…
Reference in New Issue