I was looking into TicTacToe project. Is there any simpler example in how to use navigation link with binding.
In this example, when the user clicks on the login button. If the information is correct, a binding is needed to navigate to the next screen. Code snippet from the project:
NavigationLink(
destination: IfLetStore(
self.store.scope(state: \.twoFactor, action: Login.Action.twoFactor)
) {
TwoFactorView(store: $0)
},
isActive: viewStore.binding(
get: \.isTwoFactorActive,
send: {
_ = UIApplication.shared.sendAction(
#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil
)
return $0 ? .loginButtonTapped : .twoFactorDismissed
}
)
) {
Text("Log in")
if viewStore.isActivityIndicatorVisible {
Spacer()
ProgressView()
}
}
.disabled(viewStore.isLoginButtonDisabled)
I'm finding it difficult to follow how this is actually navigating to NewGameView
if the user did not have to go through 2FA
. It looks likes it will always go to TwoFactorView
and then navigate to NewGameView
? I'm really confused tbh.
Is there an associated PointFree video for this project? The decision making while writing this feature might help in understanding this logic.
Essentially, isn't it possible to just have a state e.g. state.loginSuccessful
, which is flipped to true
at successful login. We can then maybe use this state to flip a @State
binding to true and navigate to another screen?
Example:
if viewStore.loginSuccessful {
loginSuccessful = true // State variable
}