From 3778eebb6a4d66e57e543b0c2b5b0286c5241e88 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Mon, 28 Oct 2024 14:47:03 -0400 Subject: [PATCH] [iOS] Fix P3A toggle flipping back on incorrectly in new onboarding --- .../WelcomeFocus/FocusP3AScreenView.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift index 0729d6ae7b9a..36ec2bc4d982 100644 --- a/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift +++ b/ios/brave-ios/Sources/Onboarding/WelcomeFocus/FocusP3AScreenView.swift @@ -16,6 +16,7 @@ struct FocusP3AScreenView: View { @State private var isP3AHelpPresented = false @State private var isSystemSettingsViewPresented = false + @State private var isP3AEnabled: Bool = false @Binding var shouldDismiss: Bool @@ -105,12 +106,7 @@ struct FocusP3AScreenView: View { .dynamicTypeSize(dynamicTypeRange) .padding(.bottom, shouldUseExtendedDesign ? 46 : 16) - Toggle( - isOn: Binding( - get: { p3aUtilities?.isP3AEnabled ?? true }, - set: { newValue in p3aUtilities?.isP3AEnabled = newValue } - ) - ) { + Toggle(isOn: $isP3AEnabled) { VStack(alignment: .leading, spacing: 8) { Text(Strings.FocusOnboarding.p3aToggleTitle) .font( @@ -129,6 +125,12 @@ struct FocusP3AScreenView: View { .padding(.vertical, 16) .padding(.horizontal, 20) } + .onAppear { + isP3AEnabled = p3aUtilities?.isP3AEnabled ?? true + } + .onChange(of: isP3AEnabled) { newValue in + p3aUtilities?.isP3AEnabled = newValue + } .padding(.bottom, shouldUseExtendedDesign ? 20 : 16) .padding(.trailing, 36) .toggleStyle(SwitchToggleStyle(tint: Color(braveSystemName: .buttonBackground)))