The following code works:
struct SelectBatteryChemistryView: View {
@ObservedObject var model: SelectBatteryChemistryViewModel = .init()
@Environment(\.presentationMode) private var presentationMode
var body: some View {
VStack {
Spacer()
TitleText("BATTERY MODE")
SimpleModeSelectorView(
selected: $model.batteryChemistry
)
.pickerStyle(.inline)
.frame(minHeight: 300)
PrimaryTitleButton(title: "SELECT") {
if model.batteryChemistry == .user {
model.customChemistryFlow = true
} else {
model.confirmBatterySettings()
}
}
NavigationLink(
destination: CustomBatteryChemistryView(),
isActive: $model.customChemistryFlow
) { EmptyView() }
.isDetailLink(false)
}
.onReceive(model.$batterySettingsConfirmed) { batterySettingsConfirmed in
if batterySettingsConfirmed {
//dismiss()
}
}
.onAppear() {
model.customChemistryFlow = false
}
}
}
The following code causes an infinite loop in the CustomBatteryChemistryView() initialiser.
struct SelectBatteryChemistryView: View {
@ObservedObject var model: SelectBatteryChemistryViewModel = .init()
@Environment(\.dismiss) private var dismiss
var body: some View {
VStack {
Spacer()
TitleText("BATTERY MODE")
SimpleModeSelectorView(
selected: $model.batteryChemistry
)
.pickerStyle(.inline)
.frame(minHeight: 300)
PrimaryTitleButton(title: "SELECT") {
if model.batteryChemistry == .user {
model.customChemistryFlow = true
} else {
model.confirmBatterySettings()
}
}
NavigationLink(
destination: CustomBatteryChemistryView(),
isActive: $model.customChemistryFlow
) { EmptyView() }
.isDetailLink(false)
}
.onReceive(model.$batterySettingsConfirmed) { batterySettingsConfirmed in
if batterySettingsConfirmed {
//dismiss()
}
}
.onAppear() {
model.customChemistryFlow = false
}
}
}
Adding the @Environment(.dismiss) object prevents the use of a navigation link. The program sits there with the stack infinitely calling the getter for the NavigationLink.
It looks like an infinite loop on the accessor due to some strangeness related to the magic of the Dismiss environment object.
How do we pass this on to the Dev team at Apple?