ekazaev/route-composer

Best way to hide a side menu when no action is taken by the Router

bennnjamin opened this issue · 3 comments

I have a Side Menu which is essentially a Container View Controller that has a Menu Controller (never really changes) and a Content Controller. Whenever a menu item is selected, it replaces the main content on the screen, with a new Content View Controller. My issue is when the user opens the side menu, and selects the current menu item, no action is taken by the Router because the Content View Controller is already on screen. This is good, and expected. My question is, where is the best place to hide the menu after the user selects a menu item to navigate to? Is it a PostRouterTask? I need to hide the menu in both these cases:

  1. User selects a new menu item and the router takes an action to replace the Content View Controller
  2. User selects the same menu item on the screen and router takes no action.

I have considered hiding it in

  1. Right before calling router.navigate(to: ...) in my View Controller
  2. Using a PostRouterTask

@bennnjamin

Hi,

Id say there are multiple places where you can do it. Both places are correct technically. But I would probably add a global interceptor to the router instead. Which uses a ClassFinder to find your SideManuContainerController and if it is showing the Menu at this moment - hide it (animated or not) and only then continue the navigation. That will cover all the possible cases including the case when user opened the side menu and then, lets say, he received a push notification with some deep link and clicked on it. That probably will give you the best visual behaviour and cover all the cases.

Use GlobalInterceptorRouter proxy to add such global interceptor that will be applied to every navigation by default.

Thank you, that's a good idea I hadn't considered. I will close and reopen if I have issues with it but think I can get it working by referencing the example project.

@bennnjamin

Check the usage of ContainerViewController and ConcreteContainerAdapter protocols in the example app as your Slide menu is potentially a custom container view controller. Possibly you want to adapt them.