From b1aa99e405cd63e8b3314b5da6cdcb290210ee27 Mon Sep 17 00:00:00 2001 From: Daniel Bernal Date: Mon, 6 May 2024 11:56:19 +0200 Subject: [PATCH] Fix subscriptions glitch in Settings (#2828) Task/Issue URL: https://app.asana.com/0/414235014887631/1207214261396124/f Description: Caches subscription availability state in the view, so is not refreshed on view rendering. --- .../xcshareddata/swiftpm/Package.resolved | 2 +- DuckDuckGo/SettingsSubscriptionView.swift | 81 ++++++++++--------- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4fd4e1e7f8..656e1d194b 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -129,7 +129,7 @@ { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser.git", + "location" : "https://github.com/apple/swift-argument-parser", "state" : { "revision" : "46989693916f56d1186bd59ac15124caef896560", "version" : "1.3.1" diff --git a/DuckDuckGo/SettingsSubscriptionView.swift b/DuckDuckGo/SettingsSubscriptionView.swift index eda08bd7bb..2f47a54247 100644 --- a/DuckDuckGo/SettingsSubscriptionView.swift +++ b/DuckDuckGo/SettingsSubscriptionView.swift @@ -34,6 +34,7 @@ struct SettingsSubscriptionView: View { @State var isShowingGoogleView = false @State var isShowingStripeView = false @State var isShowingSubscriptionError = false + @State var isShowingPrivacyPro = false enum Constants { static let purchaseDescriptionPadding = 5.0 @@ -205,47 +206,53 @@ struct SettingsSubscriptionView: View { } var body: some View { - if viewModel.state.subscription.enabled && viewModel.state.subscription.canPurchase { - - Section(header: Text(UserText.settingsPProSection)) { - - switch ( - viewModel.state.subscription.isSignedIn, - viewModel.state.subscription.hasActiveSubscription, - viewModel.state.subscription.entitlements.isEmpty - ) { - - // Signed In, Subscription Expired - case (true, false, _): - subscriptionExpiredView - - // Signed in, Subscription Active, Valid entitlements - case (true, true, false): - subscriptionDetailsView // View for valid subscription details - - // Signed in, Subscription Active, Empty Entitlements - case (true, true, true): - noEntitlementsAvailableView // View for no entitlements - - // Signed out - case (false, _, _): - purchaseSubscriptionView // View for signing up or purchasing a subscription + Group { + if isShowingPrivacyPro { + + Section(header: Text(UserText.settingsPProSection)) { + + switch ( + viewModel.state.subscription.isSignedIn, + viewModel.state.subscription.hasActiveSubscription, + viewModel.state.subscription.entitlements.isEmpty + ) { + + // Signed In, Subscription Expired + case (true, false, _): + subscriptionExpiredView + + // Signed in, Subscription Active, Valid entitlements + case (true, true, false): + subscriptionDetailsView // View for valid subscription details + + // Signed in, Subscription Active, Empty Entitlements + case (true, true, true): + noEntitlementsAvailableView // View for no entitlements + + // Signed out + case (false, _, _): + purchaseSubscriptionView // View for signing up or purchasing a subscription + } } - } - - .onChange(of: viewModel.state.subscription.shouldDisplayRestoreSubscriptionError) { value in - if value { - isShowingSubscriptionError = true + + .onChange(of: viewModel.state.subscription.shouldDisplayRestoreSubscriptionError) { value in + if value { + isShowingSubscriptionError = true + } } - } - - .onReceive(subscriptionNavigationCoordinator.$shouldPopToAppSettings) { shouldDismiss in - if shouldDismiss { - isShowingRestoreFlow = false - isShowingSubscribeFlow = false + + .onReceive(subscriptionNavigationCoordinator.$shouldPopToAppSettings) { shouldDismiss in + if shouldDismiss { + isShowingRestoreFlow = false + isShowingSubscribeFlow = false + } } + + } + }.onReceive(viewModel.$state) { state in + if state.subscription.enabled && state.subscription.canPurchase { + isShowingPrivacyPro = true } - } } }