I am trying to create a button an want to do some stuff before navigating to another view. But if I use a Button, I can't navigate to another view and if I user NavigationLink, I can't do anything except navigating.
I am adding button and navigation link below.
I am trying to do firebase authentication with this button and after completing authentication I want to navigate to another view.
Button(action: {print("Hi")}) {
Text("Create Account")
.font(.system(size: 20))
.foregroundColor(Color("GreyLabel0"))
}
NavigationLink(destination: WelcomeView()) {
Text("Create Account")
.font(.system(size: 20))
.foregroundColor(Color("GreyLabel0"))
}
In beta 6, DynamicNavigationDestinationLink is gone, so I am updating the answer to use NavigationLink instead.
Note that at the moment there is a bug in NavigationLink, which is addressed here: https://stackoverflow.com/a/57274613/7786555
import SwiftUI
struct ContentView: View {
@State private var presentMe = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: DetailView(), isActive: $presentMe) { EmptyView() }
Button(action: {
print("hi")
self.presentMe = true
}, label: {
Text("Present Now!")
})
Spacer()
}.navigationBarTitle(Text("Top View"))
}
}
}
struct DetailView: View {
var body: some View {
Text("Detailed View")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With