Last active
August 2, 2020 17:45
-
-
Save gevorgyanvahagn/3f60543a8a5ed5a40edabe00a2d770da to your computer and use it in GitHub Desktop.
SwiftUI - Navigation bar button issue workaround.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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