I\'m trying to build a custom NavBar
with some optional Views
, like a searchbar (but only if the view needs to display it).
I need to pass
So below is example to use optional Binding and how to access the binding and toggle to show some view:
struct NavBar: View {
@Binding var showUser: Bool
var showOptional: Binding?
var body: some View {
VStack {
Button(action: { showUser.toggle() },
label: { Text("NOT OPTIONAL") })
Button(action: { showSelectBuddy?.wrappedValue.toggle()) },
label: { Text("NOT OPTIONAL") })
}
}
}
struct UseNavbar: View {
@State var showoptional = false
@State var show = false
var body: some View {
Text("Optional")
.navigationBarItems(leading:
NavBar(showUser: show), trailing: NavBar(showUser: show, showOptional: showoptional))
}
}