0

In this code, the edit button presents the modal window as expected. On dismissal, the interface does not accept further input. In other words it only works once. Is this another bug in SwiftUI?

import SwiftUI

struct ContentView: View {
    @State var showModal:Bool = false
    var body: some View {
        NavigationView{
            Text("Sample")
            .navigationBarTitle("List")
            .navigationBarItems(leading:Button("Edit"){
                    self.showModal = true
                })
        }.sheet(isPresented: self.$showModal) {
            Modal(isOn: self.$showModal)
        }
    }
}

struct Modal: View {
    @Binding var isOn:Bool
    var body: some View {
        Text("Dismiss Modal View").onTapGesture {
            self.isOn = false
        }
    }
}
Michael Rivers
  • 920
  • 2
  • 10
  • 17
  • This is working fine for me on Xcode Version 11.2 beta (11B41) w/ iOS 13.1.2. I can open and dismiss the modal several times without any issues. – gotnull Oct 13 '19 at 23:26
  • Working for me too on Xcode 11.0 (11A420a) with iOS 13.0 simulator. – meaning-matters Oct 14 '19 at 07:04
  • 1
    Might also want to look into the environment variable `presentationMode` for a built in way to dismiss modals. Example: https://stackoverflow.com/a/56563652/5140471, docs: https://developer.apple.com/documentation/swiftui/presentationmode – RPatel99 Oct 14 '19 at 07:19

0 Answers0