Skip to content

Instantly share code, notes, and snippets.

@gevorgyanvahagn
Last active August 2, 2020 17:45
Show Gist options
  • Save gevorgyanvahagn/3f60543a8a5ed5a40edabe00a2d770da to your computer and use it in GitHub Desktop.
Save gevorgyanvahagn/3f60543a8a5ed5a40edabe00a2d770da to your computer and use it in GitHub Desktop.
SwiftUI - Navigation bar button issue workaround.
import SwiftUI
struct ContentView: View {
// If the next line is commented, the button will become not clickable after the presentation.
@Environment(\.presentationMode) var presentation
@State var showSheet = false
var body: some View {
NavigationView {
VStack {
Text("Test")
}.sheet(isPresented: self.$showSheet) {
ModalView()
}.navigationBarItems(trailing:
Button(action: {
self.showSheet = true
}) {
Text("SecondView")
}
)
}
}
}
struct ModalView: View {
@Environment(\.presentationMode) var presentation
var body: some View {
VStack {
Button(action: {
self.presentation.wrappedValue.dismiss()
}) {
Text("Dismiss")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment