Closed bennnjamin closed 1 year ago
@bennnjamin Hi. Sorry for the late reply. Yes, it is absolutely fine. Finder answers you a question what you should do depending on the current step of the app. You can also use SwitchAssembly
if needed. There should be a few examples in the Example app to be able to reuse the pieces of the configuration if needed. But logic will be more or less the same. Of course you can bring some kinda state variable to your app and istead of checking if some view controller is present or not - use that variable and choose the correct configuration to use. But usually just knowing that some view controller is present or not is enough.
Something like:
let screen = StepAssembly(
finder: ClassFinder<ProductViewController, Any?>(),
factory: ClassFactory())
.using(UINavigationController.push())
.from(SwitchAssembly<UINavigationController, Any?>()
.addCase(expecting: ClassFinder<UINavigationController, Any?>(options: .visible)) // If found - just push into it
.assemble(default: { // else
return ChainAssembly()
.from(SingleContainerStep(finder: NilFinder(), factory: NavigationControllerFactory()))
.using(GeneralAction.presentModally())
.from(GeneralStep.current())
.assemble()
})
).assemble()
But again, there is nothing wrong with the approach you are using.
Thanks for your help, I was looking for a way to do this with SwitchAssembly but it's good to know my approach is fine as well.
I have a DestinationStep that requires coming from two different places. What's the best way to handle this? Here is some example code for how I thought I could accomplish it:
I have a Study list controller, which is the root view controller. When you select a study from the list, it will replace the root view controller with the StudyTabBar. But if you come from a deeplink or notification, the StudyListController might not be on the screen (perhaps the user is on a StudyTabBar screen for a different ID). I need to replace the root view controller with this new StudyTabBar.
I use a Finder to check if the StudyListController exists first, and if it does I can use the Step to replace the view controller with the study. If the view controller doesn't exist, then I create a different step which builds the navigation controller and replaces root with the study tab bar.
Is this a good way to do it or is there a better way?