Last active
July 6, 2023 03:34
-
-
Save Amzd/67bfd4b8e41ec3f179486e13e9892eeb to your computer and use it in GitHub Desktop.
Fix the back swipe gesture not working correctly in SwiftUI. https://stackoverflow.com/a/58345554/3393964
This file contains hidden or 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
struct ContentView: View { | |
@State var isPresented = false | |
var body: some View { | |
NavigationView { | |
VStack(alignment: .center, spacing: 30) { | |
NavigationLink(destination: Text("Detail"), label: { | |
Text("Show detail") | |
}) | |
Button(action: { | |
self.isPresented.toggle() | |
}, label: { | |
Text("Show modal") | |
}) | |
} | |
.navigationBarTitle("SwiftUI") | |
} | |
.edgesIgnoringSafeArea(.top) | |
.sheet(isPresented: $isPresented) { | |
Modal() | |
} | |
} | |
} | |
struct Modal: View { | |
@Environment(\.presentationMode) var presentationMode | |
var body: some View { | |
NavigationView { | |
VStack(alignment: .center, spacing: 30) { | |
NavigationLink(destination: Text("Detail"), label: { | |
Text("Show detail") | |
}) | |
Button(action: { | |
self.presentationMode.wrappedValue.dismiss() | |
}, label: { | |
Text("Dismiss modal") | |
}) | |
} | |
.navigationBarTitle("Modal") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please edit your comment to correct the code block formatting, it’s hard to read on mobile.