From 346aaec441f5ab010735b6f38bdda9a6aca5df23 Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 5 Nov 2024 13:27:05 +0100 Subject: [PATCH] Reuse PurchaseButtonModifier in restricted areas (#815) Fixes #687 --- .../Views/Modules/OnDemandView.swift | 27 +++--- .../AppUIMain/Views/Modules/OpenVPNView.swift | 1 - .../Views/Profile/AppleTVSection.swift | 17 ++-- .../Provider/ProviderContentModifier.swift | 17 ++-- .../Modules/OpenVPNView+Credentials.swift | 23 ++--- .../Views/Paywall/PaywallModifier.swift | 10 +- .../Views/Paywall/PaywallView.swift | 0 .../Views/UI/PurchaseButtonModifier.swift | 91 +++++++++++++++++++ 8 files changed, 133 insertions(+), 53 deletions(-) rename Passepartout/Library/Sources/{AppUIMain => UILibrary}/Views/Paywall/PaywallModifier.swift (91%) rename Passepartout/Library/Sources/{AppUIMain => UILibrary}/Views/Paywall/PaywallView.swift (100%) create mode 100644 Passepartout/Library/Sources/UILibrary/Views/UI/PurchaseButtonModifier.swift diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Modules/OnDemandView.swift b/Passepartout/Library/Sources/AppUIMain/Views/Modules/OnDemandView.swift index 294b8371..a629f0fa 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Modules/OnDemandView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Modules/OnDemandView.swift @@ -60,6 +60,12 @@ struct OnDemandView: View, ModuleDraftEditing { Group { enabledSection restrictedArea + .modifier(PurchaseButtonModifier( + Strings.Modules.OnDemand.purchase, + feature: .onDemand, + showsIfRestricted: false, + paywallReason: $paywallReason + )) } .moduleView(editor: editor, draft: draft.wrappedValue) .modifier(PaywallModifier(reason: $paywallReason)) @@ -81,22 +87,11 @@ private extension OnDemandView { @ViewBuilder var restrictedArea: some View { - switch iapManager.paywallReason(forFeature: .onDemand) { - case .purchase(let feature): - Button(Strings.Modules.OnDemand.purchase) { - paywallReason = .purchase(feature) - } - - case .restricted: - EmptyView() - - default: - if draft.wrappedValue.isEnabled { - policySection - if draft.wrappedValue.policy != .any { - networkSection - wifiSection - } + if draft.wrappedValue.isEnabled { + policySection + if draft.wrappedValue.policy != .any { + networkSection + wifiSection } } } diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Modules/OpenVPNView.swift b/Passepartout/Library/Sources/AppUIMain/Views/Modules/OpenVPNView.swift index 23f9ded9..d480f3db 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Modules/OpenVPNView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Modules/OpenVPNView.swift @@ -234,7 +234,6 @@ private extension OpenVPNView { .navigationTitle(Strings.Modules.Openvpn.credentials) .themeForm() .themeAnimation(on: draft.wrappedValue.isInteractive, category: .modules) - .modifier(PaywallModifier(reason: $paywallReason)) } } } diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Profile/AppleTVSection.swift b/Passepartout/Library/Sources/AppUIMain/Views/Profile/AppleTVSection.swift index 575555b6..1faa565d 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Profile/AppleTVSection.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Profile/AppleTVSection.swift @@ -53,17 +53,14 @@ private extension AppleTVSection { Toggle(Strings.Modules.General.Rows.appleTv(Strings.Unlocalized.appleTV), isOn: $profileEditor.isAvailableForTV) } - @ViewBuilder var purchaseButton: some View { - switch iapManager.paywallReason(forFeature: .appleTV) { - case .purchase(let feature): - Button(Strings.Modules.General.Rows.AppleTv.purchase) { - paywallReason = .purchase(feature) - } - - default: - EmptyView() - } + EmptyView() + .modifier(PurchaseButtonModifier( + Strings.Modules.General.Rows.AppleTv.purchase, + feature: .appleTV, + showsIfRestricted: true, + paywallReason: $paywallReason + )) } var footer: String { diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Provider/ProviderContentModifier.swift b/Passepartout/Library/Sources/AppUIMain/Views/Provider/ProviderContentModifier.swift index 740bda01..56627af5 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Provider/ProviderContentModifier.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Provider/ProviderContentModifier.swift @@ -132,17 +132,14 @@ private extension ProviderContentModifier { ) } - @ViewBuilder var purchaseButton: some View { - switch iapManager.paywallReason(forFeature: .providers) { - case .purchase(let feature): - Button(Strings.Providers.Picker.purchase) { - paywallReason = .purchase(feature) - } - - default: - EmptyView() - } + EmptyView() + .modifier(PurchaseButtonModifier( + Strings.Providers.Picker.purchase, + feature: .providers, + showsIfRestricted: true, + paywallReason: $paywallReason + )) } func refreshButton