Baseflow / Xamarin-Sidebar

A slideout navigation control for Xamarin.iOS
https://baseflow.com
Apache License 2.0
113 stars 67 forks source link

Blank menu content when used with Xamarin Forms #31

Open johnnysbug opened 9 years ago

johnnysbug commented 9 years ago

Here's how I am setting up the SideBarController for one of my Xamarin Forms pages (via a renderer):

My Renderer:

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

            var nativeView = NativeView;
            if (nativeView != null)
            {
                var rootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                Sidebar = new SidebarController(rootViewController, this, new MenuViewController());
            }
        }

When I slide the menu out, it is a blank white view. I've tried other options, like just newing up a view controller and passing that in as the root view controller, but I see the same results. I've tried moving this code to the OnElementChanged method, but still the same problem.

Have you or anyone else had any success when integrating with Xamarin Forms?

johnnysbug commented 9 years ago

I have had success in another renderer, but only because the content view controller was pulled from a Storyboard, like so:

        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            var hostViewController = ViewController;

            var storyboard = UIStoryboard.FromName("Main_iPhone", null);
            var viewController = storyboard.InstantiateViewController("MyTabBarController") as MyTabBarController;

            Sidebar = new SidebarController(this, viewController, new MenuViewController());

            hostViewController.AddChildViewController(viewController);
            hostViewController.View.Add(viewController.View);

            viewController.DidMoveToParentViewController(hostViewController);
        }

The above does work and I can see menu content. However, in my other renderer, the content view is an actual XF Page.

eusebiu commented 8 years ago

In my app I got the same behaviour with the following code:

var formsPage = (Page)this.Element;
//var navigationController = new UINavigationController { NavigationBarHidden = true };
//navigationController.PushViewController(formsPage.CreateViewController(), false);
var sidebarController = new SidebarNavigation.SidebarController(
                                        formsPage.CreateViewController(), this, new SideMenuController());
jdehlin commented 8 years ago

I have a working example using Xamarin Forms here: https://github.com/jdehlin/Xamarin-Sidebar/tree/master/XamarinFormsSample

Have you taken a look at that?

eusebiu commented 8 years ago

Yes, but the difference is that in your samples you are new-ing a ContentController or a page and then create a view controller. In my code I am using an existing formsPage and then call the CreateViewController in the renderer.