In my ParentView I have a NavigationLink that goes to a ChildView like so:
HStack {
NavigationLink(destination: AddMemberView(newMemberFirst: $NMFirst, newMemberLast: $NMLast, newMemberAge: $NMAge), label: {}).navigationBarHidden(true)
Text("\(NMFirst) \(NMLast)")
Image(systemName: "person.crop.circle.fill.badge.plus")
.renderingMode(.original)
.foregroundColor(Color(.systemBlue))
.font(.system(size: 30))
}
My goal here is that once the $newMemberFirst
TextField in the ChildView,AddMemberView()
has a value in it, the Image person.crop.circle.fill.badge.plus
will disappear in the ParentView. Thanks!
I would create a State var in ParentView
@State var imageVisible : Bool = true
Then test:
if imageVisible {
Image(systemName: "person.crop.circle.fill.badge.plus")
.renderingMode(.original)
.foregroundColor(Color(.systemBlue))
.font(.system(size: 30))
}
Example (with simply a button in child, to replace by test of the TextView):
struct ContentView: View {
@State private var activeLink = false
@State var isVisible = true
var body: some View {
NavigationView {
NavigationLink(
destination: ChildView(onDone: { isVisible.toggle()}),
isActive: $activeLink,
label: { Text("Go Child view")})
.navigationBarHidden(true)
}
if isVisible {
Image(systemName: "person.crop.circle.fill.badge.plus")
.renderingMode(.original)
.foregroundColor(Color(.systemBlue))
.font(.system(size: 30))
}
}
}
struct ChildView: View {
let onDone: () -> Void
var body: some View {
Text("Hello, Child!")
Button(action: onDone, label: { Text("Done") })
}
}