Sidemenu: Global implementation of SideMenu in project

Created on 7 Jul 2017  路  3Comments  路  Source: jonkykong/SideMenu

New Issue Checklist


I have read the guidelines for contributing and I understand:

  • [x] My issue is happening in the latest version of SideMenu.
  • [x] My issue was not solved in the README.
  • [x] My issue can not be answered on stackoverflow.com.
  • [x] My issue is not a request for new functionality that I am unwilling to build and contribute with a pull request.
  • [x] My issue is reproducible in the demo project.

Issue Description

First, thank you for making this public, it is incredible.

Anyway, here we go, I initiated SideMenu via the storyboard. When I tap on the "menu" button in my view controller the menu slides in perfectly with the added modifications available through SideMenuManager. When I select an option in the menu I have it presenting modally another view controller. The issue comes from hitting the "menu" button on this new view controller--the menu is no longer presented as it was the first time (sliding in from left to right), instead it appears to just appear modally over the top of the view controller. I get the same warning you spoke to before --> (https://github.com/jonkykong/SideMenu/issues/194) ("SideMenu Warning: menuLeftNavigationController cannot be modified while it's presented."). I tried to initialize the menuLeftNavigationController in the AppDelegate as suggested but it still is "ignoring" the presentation properties. I have tried calling the menuLeftViewController from the new view controller a few different ways but still am getting the same result. Am I interpreting the error message wrong? Or, am I just an idiot missing something simple? lol! Thank you in advance for any insight here!

Most helpful comment

       let newViewController = storyBoard.instantiateViewController(withIdentifier: controller)

        self.dismiss(animated: true) { () -> Void in
            //Perform segue or push some view with your code
            UIApplication.shared.keyWindow?.rootViewController = newViewController
        }

All 3 comments

For simplicity, SideMenu is a singleton, meaning it is globally defined once. When you modally present a screen over SideMenu, the menu is still in the view hierarchy, even though visually it appears not to be through the animations. Therefor when you try to present the menu again from the modal screen, it can't be shown because it is already being displayed. It will only stop being displayed once you dismiss the modal screen.

From a design perspective, this is desirable since showing the same menu from a modal screen can create havoc from the user's perspective since they can get buried in a stack of modal or pushed screens without a clear idea of how to get back where they were, and it can also keep many view controllers in memory. The simple way to think of it is that the menu 'belongs' to the level of the hierarchy in which it is displayed like a TabBarController, and shouldn't be used in other levels (displaying a modal screen creates a new level).

If you must change this behavior, your options are:

  1. Redesign SideMenu away from the singleton approach, so you can instantiate many different SideMenuManagers.
  2. Ensure that the menu is fully dismissed before presenting your modal screen. You will have to avoid using segues in storyboard, and instead dismiss SideMenu when an item is tapped, and only once it is fully dismissed then present the desired screen from the view controller that showed SideMenu. This will have the unfortunate side effect of a slightly longer animation, since you'll need to wait for SideMenu to fully disappear before the modal screen can start appearing.
       let newViewController = storyBoard.instantiateViewController(withIdentifier: controller)

        self.dismiss(animated: true) { () -> Void in
            //Perform segue or push some view with your code
            UIApplication.shared.keyWindow?.rootViewController = newViewController
        }
       let newViewController = storyBoard.instantiateViewController(withIdentifier: controller)

        self.dismiss(animated: true) { () -> Void in
            //Perform segue or push some view with your code
            UIApplication.shared.keyWindow?.rootViewController = newViewController
        }

@j0cker MAN!!! THANK YOU SO MUCH 馃檹馃徏馃檶

Was this page helpful?
0 / 5 - 0 ratings