Replies: 1 comment 1 reply
-
Hi @dazy1030, this is happening because of these lines here: if let store = store.scope(state: \.second, action: \.second.presented) {
let vc = SecondViewController(store: store)
navigationController?.pushViewController(vc, animated: true)
} else {
navigationController?.popToViewController(self, animated: true)
}
if let store = store.scope(state: \.third, action: \.third.presented) {
let vc = ThirdViewController(store: store)
navigationController?.pushViewController(vc, animated: true)
} else {
navigationController?.popToViewController(self, animated: true)
} When the You need to follow the pattern we show in our Tic-Tac-Toe demo: You must keep track of the second and third view controllers so that you know whether or not it is currently presented. Here is how it should look in your situation: var secondViewController: SecondViewController?
var thirdViewController: ThirdViewController?
observe { [weak self] in
guard let self else { return }
if
secondViewController == nil,
let store = store.scope(state: \.second, action: \.second.presented)
{
let vc = SecondViewController(store: store)
secondViewController = vc
navigationController?.pushViewController(vc, animated: true)
} else if secondViewController != nil, store.second == nil {
navigationController?.popToViewController(self, animated: true)
secondViewController = nil
}
if
thirdViewController == nil,
let store = store.scope(state: \.third, action: \.third.presented)
{
let vc = ThirdViewController(store: store)
thirdViewController = vc
navigationController?.pushViewController(vc, animated: true)
} else if thirdViewController != nil, store.third == nil {
navigationController?.popToViewController(self, animated: true)
thirdViewController = nil
}
} I will also say that this is not correct: if !isMovingToParent {
store.send(.someViewDismissed)
} This is going to dismiss both controllers whenever this controller appears again. Again I encourage you to look at how we do this in the Tic-Tac-Toe demo: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm just checking the specifications for screen transitions in UINavigationController using the observe method, and I found a bug-like behaviour.
If I create multiple screen transition origins with a single observe method, the first transition I describe will immediately return to the screen from which I made the transition, as shown in the attached video.
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-04-14.at.00.04.01.mp4
I have prepared a minimal sample that confirms this problem.
https://github.com/dazy1030/UIKitPlayground/tree/tca/multi-navigation-observe
I have confirmed that this problem can be avoided by writing only one transition in the observe method and using two observe methods.
Thanks.
Environments
macOS 14.2.1, Xcode 15.2, iPhone 15 Pro(17.2 simulator)
Beta Was this translation helpful? Give feedback.
All reactions