Splash 화면이 로드된 후, nextStep으로 .loginRequired 를 전달하였는데 로그인 화면으로 전환되지 않는 문제가 발생했다.
final class SplashViewController: BaseViewController {
...
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
validateSession()
}
private func validateSession() {
Task {
let nextStep = await authService.resolveInitialStep() // nextStep이 .loginRequired임을 확인함
self.steps.accept(nextStep)
}
}
}
브레이크 포인트를 걸어 nextStep 값이 .loginRequired 로 할당되는 것은 확인하였다.
finali class AppFlow: Flow {
let window: UIWindow
let splashViewController = SplashViewController()
var root: any RxFlow.Presentable { window }
init(windowScene: UIWindowScene) {
self.window = UIWindow(windowScene: windowScene)
self.window.rootViewController = splashViewController
self.window.makeKeyAndVisible()
}
func navigate(to step: any RxFlow.STep) -> RxFlow.FlowContributors {
guard let step = step as? AppStep else {
return .none
}
switch step {
case .splash:
let viewController = SplashViewController()
return .one(
flowContributor: .contribute(
withNextPresentable: viewController,
withNextStepper: viewController
)
)
...
}
}
}
AppFlow에서 root를 splashViewController로 사용하고 있다.
그런데 splash 스텝에서 SplashViewController를 새로이 생성하여 flowContributor로 넘겨주고 있다.
즉, 화면에 보이는 뷰컨트롤러(root)와 실제로 새로운 스텝을 뱉어낸 viewController(SplashViewController)가 달랐던 것이다!
그때문에 화면에 보이지 않는 viewController(SplashViewController)가 loginViewController로 전환되어 시뮬레이터 화면 상에는 아무 동작이 일어나지 않은 것처럼 보인 것이었다.
서로 달랐던 root와 contributor를 일치화시켜주었다.
final class AppFlow: Flow {
let window: UIWindow
var root: any RxFlow.Presentable { window } // root를 window로 변경
init(windowScene: UIWindowScene) {
self.window = UIWindow(windowScene: windowScene)
self.window.makeKeyAndVisible()
}
func navigate(to step: anyu RxFlow.Step) -> RxFlow.FlowContributors {
guard let step = step as? AppStep else {
return .none
}
switch step {
case .splash:
let splashController = SplashViewController()
window.rootViewController = splashController // rootViewController 설정
return .one(
flowContributor: .contribute(
withNextPresentable: splashController,
withNextStepper: splashViewController
)
)
...
}
}
}
화면에 보이는 ViewController와 다음 step을 방출하는 viewController가 일치화되었다.
로그인 화면으로 정상적으로 넘어가는 것을 확인하였다.