Home > Net >  How to make a view gone in swiftui
How to make a view gone in swiftui

Time:04-26

I was trying to hide view but noticed that view.hidden() will only hide the view but but the space remains.

I also tried some of the suggestions on this link hidden

CodePudding user response:

I created an extension function as below

extension View {
    @ViewBuilder func hiddenConditionally(isHidden: Binding<Bool>) -> some View {
        isHidden.wrappedValue ? self  :  self.hidden() as? Self
    }
}

and you can call it as below

         TextField("Pin", text: $pin)
                .hiddenConditionally(isHidden: $showPinField)
  • Related