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

Can a custom init function be added to `NavigationControllerStep` & `TabBarControllerStep`? #74

Closed wwdc14yh closed 2 years ago

wwdc14yh commented 2 years ago

I have a CustomNavigationController must be call custom init function, but NavigationControllerStep does not provide custom initialization. Now i have to Now I have to re-instantiate SingleContainerStep to use the custom initialization function

Or you can set the access permission of NavigationControllerStep to open. I can override it.

Do you have any good ideas?

ekazaev commented 2 years ago

@wwdc14 Hi I see your point but technically this is exactly what is SingleContainerStep for and this is expected. Because you can be not happy with the factory or a finder in NavigationControllerStep and it is absolutely normal. So SingleContainerStep step allows you to configure both of them the way you want. I am very against any inheritance it this case, so I reserved it to be used only within the library. If you want to be able to write your SingleContainerStep by calling just one instance in a similar manner like NavigationControllerStep - just wrap it in to a function like this:

func MyNavigationControllerStep<C>(parameters: Whatever) -> SingleContainerStep<NilFinder<MyNavigationController, C>, MyNavigationControllerFactory<MyNavigationController, C>> {
    return SingleContainerStep(finder: NilFinder(), factory: MyNavigationControllerFactory<C>(parameters: parameters))
}

and then use it like NavigationControllerStep with the same purpose:

        StepAssembly(Whatever Factory/Finder)
            .using(MyNavigationController.push())
            .from(MyNavigationControllerStep(parameters: Whatever))
            .using(GeneralAction.presentModally())
            .from(GeneralStep.current())
            .assemble()

I assume this is what you want

wwdc14yh commented 2 years ago

Awesome! thanks