Onboarding: permission prompts fire on page arrival, not just Continue

Swiping past the Location/Notifications pages never triggered the system
prompts — only tapping Continue did. The prompt now fires the moment its
page comes into view (onChange(of: page)): swipe, auto-advance after a
grant, or Continue all land on the page and request the permission. Both
request methods are idempotent (already-determined → status refresh, no
duplicate alert), so replay and the auto-advance path stay clean.
This commit is contained in:
FuelBoard Contributor
2026-08-15 14:34:24 +01:00
parent 485ef782b6
commit b634c0686d
+16 -5
View File
@@ -47,15 +47,25 @@ struct OnboardingView: View {
.padding(.horizontal, 20) .padding(.horizontal, 20)
.padding(.bottom, 24) .padding(.bottom, 24)
} }
// Auto-advance once the user grants a permission the prompt itself // Auto-advance once the user grants a permission.
// only fires when the Continue button is tapped (after reading the
// page's description), never when the page merely appears.
.onChange(of: prompter.locationGranted) { _, granted in .onChange(of: prompter.locationGranted) { _, granted in
if granted, page == 1 { page = 2 } if granted, page == 1 { page = 2 }
} }
.onChange(of: prompter.notificationsGranted) { _, granted in .onChange(of: prompter.notificationsGranted) { _, granted in
if granted, page == 2 { page = 3 } if granted, page == 2 { page = 3 }
} }
// Fire the permission the moment its page comes into view swiping
// must trigger the prompt exactly like tapping Continue does. Both
// request methods are idempotent: an already-determined permission
// just refreshes the status (no duplicate system alert), so this is
// safe for replay and for the auto-advance path.
.onChange(of: page) { _, newPage in
if newPage == 1 {
prompter.requestLocation()
} else if newPage == 2 {
prompter.requestNotifications()
}
}
// No data-permission step: prices download from the internet (GitHub // No data-permission step: prices download from the internet (GitHub
// mirror) with no permission at all Local Network was removed from // mirror) with no permission at all Local Network was removed from
// the app when the relay left the consumer chain. // the app when the relay left the consumer chain.
@@ -237,8 +247,9 @@ struct OnboardingView: View {
if prompter.locationDenied { if prompter.locationDenied {
openSettings() openSettings()
} else if !prompter.locationGranted { } else if !prompter.locationGranted {
// The system prompt fires HERE after the user has read // Safety net the prompt already fired when this page
// the description and tapped Continue not on page appear. // came into view (see onChange(of: page)); re-requesting
// is a no-op unless the status is still undetermined.
prompter.requestLocation() prompter.requestLocation()
} else { } else {
page = 2 page = 2