ekazaev / route-composer

Protocol oriented, Cocoa UI abstractions based library that helps to handle view controllers composition, navigation and deep linking tasks in the iOS application. Can be used as the universal replacement for the Coordinator pattern.
MIT License
896 stars 63 forks source link

need enlightenment from heaven #68

Closed bagusandinata closed 3 years ago

bagusandinata commented 3 years ago

RouteComposer was awesome, I switched from RxFlow. I'm slowly understanding RouteComposer, can you provide an example/code how to support navigation with below scheme

root(UINavigationController) -> Login -> Register Email -> Register Final (completed some field)

if register final submit and success, I want to back navigation to Login, can i use RouteComposer ?

or

just check

if let viewController = navigationController?.viewControllers.filter({$0 is LoginViewController}).first as? LoginViewController navigationController?.popToViewController(viewController, animated: true) } else { navigationController?.popToRootViewController(animated: true) }

thanks

ekazaev commented 3 years ago

Hi @bagusandinata

Thank you very much.

You don't really need to do what you wrote in the code snippet. You should be able to call login configuration directly and it should bring you back to login - basically router will do the pop action for you.

Can you please provide the StepAssembly how your Login view controller is configured?

bagusandinata commented 3 years ago

var mainScreen = CompleteFactoryAssembly(factory: NavigationControllerFactory()) .with(OnboardingControllerFactory(), using: AppearanceNavigationController.push()) .assemble()

var loginScreen: DestinationStep<LoginViewController, Any?> { StepAssembly(finder: NilFinder(), factory: LoginControllerFactory()) .using(AppearanceNavigationController.push()) .from(GeneralStep.custom(using: ClassFinder<AppearanceNavigationController, Any?>())) .assemble() }

var registerEmailScreen: DestinationStep<RegisterEmailViewController, Any?> { StepAssembly(finder: NilFinder(), factory: RegisterEmailControllerFactory()) .using(AppearanceNavigationController.push()) .from(GeneralStep.custom(using: ClassFinder<AppearanceNavigationController, Any?>())) .assemble() }

var registerScreen: DestinationStep<RegisterViewController, Email> { StepAssembly(finder: NilFinder(), factory: RegisterControllerFactory()) .using(AppearanceNavigationController.push()) .from(GeneralStep.custom(using: ClassFinder<AppearanceNavigationController, Email>())) .assemble() }

ekazaev commented 3 years ago

@bagusandinata NilFinder is the reason you can not reuse your configuration to return to LoginViewController. Router can not find existing view controller in the stack and will create another one. Change it to ClassFinder for example, and you will be able to return from RegisterCompleteViewController back to LoginVewController just by calling this configuration again. Router uses finder of every step to find the starting point from top to the bottom. Of the top finder succeeds - it just goes there and doesn’t do anything else. NilFinder should be used in case you want router to create a new version of the view controller even if such view controller already exists. here is the simple description how the router goes through the steps: https://github.com/ekazaev/route-composer#configuring-step

NB: I would recommend you to play around with finders in the example app to understand them better, and also notice that they may have options for a fine tuning. You can also create your own finders if the ones bundled with the library are not enough. But from my experience it is usually the last resort.

bagusandinata commented 3 years ago

whoaa thanks @ekazaev !!!

it's simple when implemented. Maybe later I'll come back again if I have any questions, one more time your library is amazing 😀

ekazaev commented 3 years ago

@bagusandinata You are welcome. Surely. Ill try to help if you'll have any other questions