How Best Value works: a Setup Best Value button, and a clean hand-off to Settings
The explanation sheet now carries a full-width button that closes it and the sheet it was opened from, then lands on Settings — whose Best Value section is the first thing in its list, so the controls are on screen on arrival. It uses .controlSize(.large), the standard iOS button height. Both the More info sheet and the Key sheet are presented by StationsView, and FavouritesView presents its own More info sheet — not ContentView's monitor as assumed — so each host closes whichever sheet it owns on the notification. Before this, one of them stayed up over the Settings tab. The button now announces itself half a second after its own dismissal, so the child and parent dismissals cannot race and drop one of the two.
This commit is contained in:
@@ -16,6 +16,22 @@ struct HowBestValueSheet: View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("Best Value compares each station with the closest station by journey distance. It works out what you could save at the pump, then takes off the fuel used for the extra return journey.")
|
||||
Text("Your fill-up amount and MPG are used to show whether you could save overall.")
|
||||
// The whole point of the sheet is to explain the feature,
|
||||
// so the way to switch it on lives here rather than only
|
||||
// in Settings. Full-width: this is the card's one action.
|
||||
Button {
|
||||
openBestValueSettings()
|
||||
} label: {
|
||||
Text("Setup Best Value")
|
||||
.font(.subheadline.weight(.semibold))
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
// `.large` is the standard iOS button height (~50pt): the
|
||||
// default `.borderedProminent` is considerably shorter and
|
||||
// read as a compact control rather than a button.
|
||||
.buttonStyle(.borderedProminent)
|
||||
.controlSize(.large)
|
||||
.padding(.top, 2)
|
||||
}
|
||||
.font(.subheadline)
|
||||
.padding(.vertical, 4)
|
||||
@@ -63,6 +79,33 @@ struct HowBestValueSheet: View {
|
||||
}
|
||||
.presentationDetents([.fraction(0.72)])
|
||||
.presentationBackground(Color(UIColor.systemGroupedBackground))
|
||||
#if DEBUG
|
||||
// QA hook: `-qaSetupBestValue` runs the Setup Best Value action without a
|
||||
// tap (simctl cannot tap), so the tab switch can be screenshotted.
|
||||
.task {
|
||||
guard ProcessInfo.processInfo.arguments.contains("-qaSetupBestValue") else { return }
|
||||
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
||||
openBestValueSettings()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Closes this sheet and asks the app to land on Settings → Best Value, whose
|
||||
/// section is the first thing in its list and holds the fill-up amount, MPG
|
||||
/// and minimum saving. This sheet sits two levels below the tab view — More
|
||||
/// info sheet, or the Key sheet — so it cannot switch tabs itself: it closes
|
||||
/// itself and posts, and ContentView does the rest.
|
||||
private func openBestValueSettings() {
|
||||
dismiss()
|
||||
// Announce only once this sheet has animated away. The host then closes
|
||||
// the sheet this one was presented from — the More info sheet, or the Key
|
||||
// sheet — and switches to Settings. Asking for that while the child was
|
||||
// still dismissing could drop one of the two dismissals, which is what
|
||||
// left the Settings tab covered by a sheet.
|
||||
Task { @MainActor in
|
||||
try? await Task.sleep(nanoseconds: 500_000_000)
|
||||
NotificationCenter.default.post(name: .fuelBoardOpenBestValueSettings, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
/// One numbered step: a lead-in, then the plain explanation. Same words
|
||||
|
||||
Reference in New Issue
Block a user