title: Hide/show views on button tap - SwiftUI
body: <p>I have a view, created separately in another file, that I want to show and hide conditionally when a button is pressed.</p>
  <p>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.</p>
  <p>My project looks like this:</p>
  <p><strong>In ContentView.swift, inside <em>var body: some View</em></strong></p>
  <pre><code>@State var doIWantThisViewToShow: Bool = false
  
  MyView()
          .padding()
          .opacity(doIWantThisViewToShow ? 1 : 0)
  </code></pre>
  <p><strong>In MyView.swift</strong></p>
  <pre><code>struct MyView: View {
      var body: some View {
          Text(&quot;Text&quot;)
      }
  }
  </code></pre>
  <p>Thanks in advance!</p>