Help how to close the current screen or pop to previous screen in Route Composer?
RauanBImat opened this issue · comments
help
Can you tell me how to implement a function in Route Composer that simply closes the screen, or I approximately implemented the transition to the previous screen, but it is not correct
var back: DestinationStep<UIViewController, NavigationControllerFactory> {
StepAssembly(
finder: ClassFinder<UIViewController, NavigationControllerFactory.Context>(),
factory: NavigationControllerFactory()
)
.using(UINavigationController.pop())
.assemble()
}
struct NavigationControllerFactory: Factory {
typealias ViewController = UINavigationController
typealias Context = Any?
func build(with context: Any?) throws -> UINavigationController {
return UINavigationController()
}
}
@RauanBImat Hi,
There is no such function as there is no such navigation pattern as 'just closing the screen'.
Ill try to explain why. The easiest way to look at it is a deep-linking. You have URLs that lead user to some screens in the app. How you can describe in deeplinking that closes the screen? Where does it lead to? 'just closing the screen' has no destination. That is why the way you askedthe question has no answer in the way how RouteComposer look at the navigation. And this is why the code you provided even if it works has no sense. If you want to pop view controller to close - just call pop directly on UINavigationController - why do you need routers envolvment? Or if you want to dismiss presented modally view controller just call dismiss on that view controller.
As an illustration have a look at this example:
After completing the task on the success screen there are 2 buttons "Close" and "View Checklist". "View Checklist" has a destination - we need to present a checklist that this task belongs to. So routers involvement is necessary. But close button just needs to dismiss the view controller without carring where user lands at. So it just calls view controller's dissmiss method.
Howerer: If you want to control the dismissal behaviour from the presentation configuration and lets call it "keep everything in one place" - look at the example app and check the usage of DismissalMethodProvidingContextTask
in colorScreen
configuration example. This way you can see how the presented screen can dismiss itself and change that behaviour if needed.
@RauanBImat Please let me know if you have any further questions.