I have a view, created separately in another file, that I want to show and hide conditionally when a button is pressed.
I tried several techniques like changing the opacity or offset depending on a boolean, but it doesn't work once I put the view in another SwiftUI file.
My project looks like this:
In ContentView.swift, inside var body: some View
@State var doIWantThisViewToShow: Bool = false
MyView()
.padding()
.opacity(doIWantThisViewToShow ? 1 : 0)
In MyView.swift
struct MyView: View {
var body: some View {
Text("Text")
}
}
Thanks in advance!