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") | |
} | |
} | |
} |
And without my code it works?
And without my code it works?
Yes
Could you please edit your comment to correct the code block formatting, it’s hard to read on mobile.
This code works without overriding NavigationLink
, NavigationView
is enough. @Amzd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. Thx for solution, but:
...
@State var cartCount: Int = 0
...
.navigationBarItems(
trailing: (
NavigationLink(destination: CartView()) {
Image(systemName: "bag.fill")
.imageScale(.large)
.foregroundColor(Color.init(hex: "858ac1"))
}
.overlay(
Text(self.cartCount.description)
.foregroundColor(Color.white)
.font(.system(size: 10))
.frame(width: 15.0, height: 15.0)
.background(Color.init(hex: "e80063"))
.cornerRadius(15), alignment: .topTrailing)
)
)
...
if i change "cartCount", view didn't change...