Handling coordination result when pushing view controller
DocMacFain opened this issue · 4 comments
Hello, first thank you very much for share you idea about MVVM-C!
I would like to use this approach, but I face such problem like handling coordination result when I push some view controller inside of navigation stack. If I would use present(_ viewControllerToPresent) of second view controller, I will handle cancel tab bar item action and emit some event likes CoordinationResult.cancel, but how I should handle situation with pushing?
Sorry, I don't completely understand your question. Could you provide some basic code showing what you are trying to do?
@mgacy Thank you for your attention!
If we would ignore it we will catch memory leak.
Sometimes I have two cases when Im going to another VC - 1) I have some coordination result; 2) I don't have any result, and I don't need emit some events (likes just pressing back button at navigation controller) .
override func start() -> Observable<Void> {
...
return viewModel.signInAction
.asObservable()
.flatMap({ [weak self] _ -> Observable<AuthCoordinationResult> in
guard let `self` = self else { return Observable.empty() }
return self.showSiteAuthScene(on: navigationController)
})
.filter({ $0 == .signedIn })
.mapToVoid()
.take(1)
}
override func start() -> Observable<AuthCoordinationResult> {
...
rootViewController.pushViewController(authViewController, animated: true)
let complete = viewModel.authCompleteAction
.asObservable()
.map({ SiteAuthCoordinationResult.canceled })
let cancelled = %some code to understand that user pressed back button / used back swipe%
// but what we should to do, if we don't need any results?
return Observable.merge(complete, cancelled)
.take(1)
}
I'm still not sure that I completely understand your question, but I think you are asking about how to handle horizontal flows where we push a child coordinator. This is one of the primary problems with the coordinator pattern and I honestly haven't needed to develop a complete solution to it. You can find some discussions of the problem in the following, though none of them address it in the context of RxSwift:
@mgacy Right, thank you for links! I tried to make some same solution