コード例 #1
0
        void RegisterToolbar()
        {
            Context  context = Context;
            AToolbar bar     = _toolbar;
            Element  page    = Element.RealParent;

            _masterDetailPage = null;
            while (page != null)
            {
                if (page is MasterDetailPage)
                {
                    _masterDetailPage = page as MasterDetailPage;
                    break;
                }
                page = page.RealParent;
            }

            if (_masterDetailPage == null)
            {
                _masterDetailPage = PageController.InternalChildren[0] as MasterDetailPage;
                if (_masterDetailPage == null)
                {
                    return;
                }
            }

            if (((IMasterDetailPageController)_masterDetailPage).ShouldShowSplitMode)
            {
                return;
            }

            var renderer = Android.Platform.GetRenderer(_masterDetailPage) as MasterDetailPageRenderer;

            if (renderer == null)
            {
                return;
            }

            _drawerLayout = renderer;

            FastRenderers.AutomationPropertiesProvider.GetDrawerAccessibilityResources(context, _masterDetailPage, out int resourceIdOpen, out int resourceIdClose);

            _drawerToggle = new ActionBarDrawerToggle((Activity)context, _drawerLayout, bar,
                                                      resourceIdOpen == 0 ? global::Android.Resource.String.Ok : resourceIdOpen,
                                                      resourceIdClose == 0 ? global::Android.Resource.String.Ok : resourceIdClose)
            {
                ToolbarNavigationClickListener = new ClickListener(Element)
            };

            if (_drawerListener != null)
            {
                _drawerLayout.RemoveDrawerListener(_drawerListener);
            }

            _drawerListener = new DrawerMultiplexedListener {
                Listeners = { _drawerToggle, renderer }
            };
            _drawerLayout.AddDrawerListener(_drawerListener);
        }
コード例 #2
0
        void RegisterToolbar()
        {
            Context  context = Context;
            AToolbar bar     = _toolbar;
            Element  page    = Element.RealParent;

            MasterDetailPage masterDetailPage = null;

            while (page != null)
            {
                if (page is MasterDetailPage)
                {
                    masterDetailPage = page as MasterDetailPage;
                    break;
                }
                page = page.RealParent;
            }

            if (masterDetailPage == null)
            {
                masterDetailPage = PageController.InternalChildren[0] as MasterDetailPage;
                if (masterDetailPage == null)
                {
                    return;
                }
            }

            if (((IMasterDetailPageController)masterDetailPage).ShouldShowSplitMode)
            {
                return;
            }

            var renderer = Android.Platform.GetRenderer(masterDetailPage) as MasterDetailPageRenderer;

            if (renderer == null)
            {
                return;
            }

            _drawerLayout = renderer;
            _drawerToggle = new ActionBarDrawerToggle((Activity)context, _drawerLayout, bar, global::Android.Resource.String.Ok, global::Android.Resource.String.Ok)
            {
                ToolbarNavigationClickListener = new ClickListener(Element)
            };

            if (_drawerListener != null)
            {
                _drawerLayout.RemoveDrawerListener(_drawerListener);
            }

            _drawerListener = new DrawerMultiplexedListener {
                Listeners = { _drawerToggle, renderer }
            };
            _drawerLayout.AddDrawerListener(_drawerListener);

            _drawerToggle.DrawerIndicatorEnabled = true;
        }
コード例 #3
0
        private void InitDrawer()
        {
            Messenger.Default.Register <PageTitleMessage>(this, OnNewPageTitle);
            Messenger.Default.Register <ToolbarRequestMessage>(this, OnNewToolbarRequest);

            NavigationRecyclerView.SetAdapter(
                new RecyclerViewAdapterBuilder <HamburgerMenuEntryViewModel, HamburgerEntryHolder>()
                .WithContentStretching()
                .WithItems(ViewModel.HamburgerItems)
                .WithResourceId(LayoutInflater, Resource.Layout.nav_item)
                .WithDataTemplate(HamburgerItemDataTemplate)
                .WithHolderTemplate((parent, type, view) => new HamburgerEntryHolder(view, this))
                .Build());

            var divider = new DividerItemDecoration(this, DividerItemDecoration.Vertical);

            divider.SetDrawable(Resources.GetDrawable(Resource.Drawable.separator_transparent, Theme));
            NavigationRecyclerView.AddItemDecoration(divider);
            NavigationRecyclerView.SetLayoutManager(new LinearLayoutManager(this));

            SetUpHamburgerButton();
            Toolbar.MenuItemClick += ToolbarOnMenuItemClick;

            Bindings.Add(this.SetBinding(() => ViewModel.IsDrawerEnabled).WhenSourceChanges(() =>
            {
                if (ViewModel.IsDrawerEnabled)
                {
                    DrawerLayout.SetDrawerLockMode(global::Android.Support.V4.Widget.DrawerLayout.LockModeUndefined);
                    DrawerLayout.AddDrawerListener(_hamburgerToggle);
                    _hamburgerToggle.SyncState();
                    _hamburgerButtonAdded = true;
                }
                else
                {
                    DrawerLayout.SetDrawerLockMode(global::Android.Support.V4.Widget.DrawerLayout.LockModeLockedClosed);
                    if (_hamburgerButtonAdded)
                    {
                        DrawerLayout.RemoveDrawerListener(_hamburgerToggle);
                    }
                }
            }));

            //Don't use object initializer
            _settingsButtonHolder           = new HamburgerEntryHolder(SettingsNavButton, this);
            _settingsButtonHolder.ViewModel = ViewModel.SettingsButtonViewModel;
        }
コード例 #4
0
        void RegisterToolbar()
        {
            Context  context = NavigationLayout.Context;
            AToolbar bar     = Toolbar;
            Element  page    = NavigationView.RealParent;

            _flyoutPage = null;
            while (page != null)
            {
                if (page is FlyoutPage)
                {
                    _flyoutPage = page as FlyoutPage;
                    break;
                }
                page = page.RealParent;
            }

            if (_flyoutPage == null)
            {
                if (PageController.InternalChildren.Count > 0)
                {
                    _flyoutPage = PageController.InternalChildren[0] as FlyoutPage;
                }

                if (_flyoutPage == null)
                {
                    return;
                }
            }

            if (((IFlyoutPageController)_flyoutPage).ShouldShowSplitMode)
            {
                return;
            }

            var renderer = _flyoutPage.ToNative(NavigationView.Handler.MauiContext) as DrawerLayout;

            if (renderer == null)
            {
                return;
            }

            _drawerLayout = renderer;

            AutomationPropertiesProvider.GetDrawerAccessibilityResources(context, _flyoutPage, out int resourceIdOpen, out int resourceIdClose);

            if (_drawerToggle != null)
            {
                _drawerToggle.ToolbarNavigationClickListener = null;
                _drawerToggle.Dispose();
            }

            _drawerToggle = new ActionBarDrawerToggle(context.GetActivity(), _drawerLayout, bar,
                                                      resourceIdOpen == 0 ? global::Android.Resource.String.Ok : resourceIdOpen,
                                                      resourceIdClose == 0 ? global::Android.Resource.String.Ok : resourceIdClose)
            {
                ToolbarNavigationClickListener = new ClickListener(NavigationView)
            };

            if (_drawerListener != null)
            {
                _drawerLayout.RemoveDrawerListener(_drawerListener);
                _drawerListener.Dispose();
            }

            _drawerListener = new DrawerMultiplexedListener {
                Listeners = { _drawerToggle, (DrawerLayout.IDrawerListener)_drawerLayout }
            };
            _drawerLayout.AddDrawerListener(_drawerListener);
        }