Baseflow/Xamarin-Sidebar

Add sidebar after login

javal-idyllic opened this issue · 10 comments

Hi,
I have a storyboard project and in my application I have few screens (Register/login) and after these screens I want Sidebar to be available on the main landing page, so it will not be a rootViewController of the application.

I have a landingPageViewController which will act as a rootViewController and in its viewDidload I am doing following things to setup sidebar controller:

var reservationStepOneController = (ReservationStepOneViewController)Storyboard.InstantiateViewController("reservationOne");
            var menuController = (MenuViewController)Storyboard.InstantiateViewController("menuViewController");

            // create a slideout navigation controller with the top navigation controller and the menu view controller
            this.NavController = new UINavigationController();
            NavController.PushViewController(reservationStepOneController, false);
            SidebarController = new SidebarNavigation.SidebarController(this, this.NavController, menuController);
            SidebarController.MenuWidth = 220;
            SidebarController.ReopenOnRotate = false;
            SidebarController.MenuLocation = SidebarNavigation.SidebarController.MenuLocations.Left;

After this point, I am not able to set left bar button item in the navigation bar neither I can set the title to it. Sidebar is accessible via swiping but not via navigation bar as not able to add items to the navigation bar.
How can I achieve this? Is it mandatory to have sidebar added to the rootController of applicaiton?

Do you have code like the following in your content controllers (e.g. ReservationStepOneController)?

public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.SetRightBarButtonItem(
                new UIBarButtonItem(UIImage.FromBundle("threelines")
                    , UIBarButtonItemStyle.Plain
                    , (sender,args) => {
                        SidebarController.ToggleMenu();
                    }), true);
        }

Yes, I tried that way and also tried the same code to be part of baseviewcontroller and ReservationStepOneController inherits BaseViewController. But no effect on the navigation bar with either of the approach. Bar button item does not appear. Same issue with setting navigation title.

@jdehlin Any suggestions for the same? Is it mandatory for the sidebar to be in the root controller only?

@jdehlin Any suggestion on this? If you can provide workaround for this, it would be helpful.

I am after the same. Can we use this plugin, not from the rootview controller

@libin85 I struggled a lot around the same. Expecting some workaround from @jdehlin.
Currently, to make it work, instead of navigating using segue or navigationcontroller, I am changing the rootviewcontroller of the application at the point where it is required to navigate to a controller which has sidebar plugin.

var controller = new LandingPageViewController();
                var storyboard = this.Storyboard;
                UIApplication.SharedApplication.KeyWindow.RootViewController = controller;

Here LandingPageViewController is same as the RootViewController in the Storyboard sample of this plugin. Using this method still I am facing some issue related to appearance of Navigation bar, but atleast now I am able to set title and barbuttonItem

@javal-idyllic : But doing that, we got to set the page that has the sidebar as our initial page right. I have gone past that. I can have the sidebar within a inside page, and I can slide the sidebar to reveal it. But if i click on the menu button., it throws a null exception. Working on that now. If i get it sorted , I will share the code.

@libin85 @javal-idyllic Is the problem solved? Could you share the code? I am facing the same issue. Thanks, not sure how to sub rootviewController to my landingpagecontroller after login.

@jdehlin Could you help me with the similar issue? I want to have the sidenavigationbar after login, which I have the storyboard set segue root to my loginviewcontroller, and from your emaple (with storyboart) I set the rootviewcontroller in AppDelegate.cs, and then BaseController has something borrow from delegate like

protected SidebarNavigation.SidebarController SidebarController
{
get
{
return (UIApplication.SharedApplication.Delegate as AppDelegate).RootViewController.SidebarController;
}
}
In this way, I am not able to see the login page, and if I command
//Window = new UIWindow(UIScreen.MainScreen.Bounds);
//Window.RootViewController = new HomeViewController();
//Window.MakeKeyAndVisible();

I can only see the login page. Any help? Thanks!

I'm not very familiar with Storyboards. It would seem to me that you need to have your login view be the main entry point for the Storyboard and then segue to the SidebarController on login. Unfortunately I can't offer much help other than that.