My swiftui application structure looks like this
When I use a sole standalone navigation link inside tab view screens to direct to another screen programatically, it navigates succesfully to the mentioned destination, but my binding doesn't work to come back to the previous screen.
Parent View
@State var showCameraPreviewView : Bool = false
ZStack{
Button("Show camera") {
showCameraPreviewView = true
}
NavigationLink(destination: CameraView(showCameraPreviewView: $showCameraPreviewView),isActive: $showCameraPreviewView){
EmptyView()
}
}
Child View
@Binding var showCameraPreviewView
Button("Assume capture success"){
self.showCameraPreviewView = false
}
Toggling showCameraPreviewView binding to false in the destination doesn't get me back to the current screen. Looks straight forward, but doesn't work ! anything that I'm doing wrong ?
I can reproduce your issue, quite strange ... seems like the change of showCameraPreviewView
is not accepted because the view is still visible. But I found a workaround with dismiss
:
EDIT for iOS 14:
struct ChildView: View {
@Environment(\.presentationMode) var presentationMode
@Binding var show: Bool
var body: some View {
Button("Assume capture success"){
show = false
presentationMode.wrappedValue.dismiss()
}
}
}