void SetupToolbar()
        {
            if (_stackNavigationManager == null || _navController == null)
            {
                return;
            }

            var appbarConfigBuilder =
                new AppBarConfiguration
                .Builder(_stackNavigationManager.NavGraph);

            if (_drawerLayout != null)
            {
                appbarConfigBuilder = appbarConfigBuilder.SetOpenableLayout(_drawerLayout);
            }

            var appbarConfig =
                appbarConfigBuilder.Build();

            NavigationUI
            .SetupWithNavController(PlatformView, _navController, appbarConfig);

            // the call to SetupWithNavController resets the Navigation Icon
            UpdateValue(nameof(IToolbar.BackButtonVisible));
            PlatformView.SetNavigationOnClickListener(BackNavigationClick);
        }
        private void SetupNavigationMenu(NavController navController)
        {
            var sideNavView = FindViewById <NavigationView>(Resource.Id.nav_view);

            if (sideNavView != null)
            {
                NavigationUI.SetupWithNavController(sideNavView, navController);
            }
        }
        private void SetupBottomNavMenu(NavController navController)
        {
            var bottomNav = FindViewById <BottomNavigationView>(Resource.Id.bottom_nav_view);

            if (bottomNav != null)
            {
                NavigationUI.SetupWithNavController(bottomNav, navController);
            }
        }
Exemple #4
0
            public override void OnFragmentResumed(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f)
            {
                if (f is NavigationViewFragment pf)
                {
                    _stackNavigationManager.OnNavigationViewFragmentResumed(fm, pf);
                }

                AToolbar?nativeToolbar = null;
                IToolbar?toolbar       = null;

                if (_stackNavigationManager.NavigationView?.Toolbar is IToolbar tb &&
                    tb?.Handler?.NativeView is AToolbar ntb)
                {
                    nativeToolbar = ntb;
                    toolbar       = tb;
                }

                // Wire up the toolbar to the currently made visible Fragment
                var controller          = NavHostFragment.FindNavController(f);
                var appbarConfigBuilder =
                    new AppBarConfiguration
                    .Builder(_stackNavigationManager.NavGraph);

                if (nativeToolbar != null && toolbar != null)
                {
                    // TODO: MAUI Hackey way of wiring up Drawer Layout
                    // But currently you can only have a nav bar with a Navigation View
                    if (nativeToolbar.Parent is DrawerLayout dl1)
                    {
                        appbarConfigBuilder = appbarConfigBuilder.SetOpenableLayout(dl1);
                    }
                    else if (nativeToolbar.Parent?.Parent is DrawerLayout dl2)
                    {
                        appbarConfigBuilder = appbarConfigBuilder.SetOpenableLayout(dl2);
                    }
                    else if (nativeToolbar.Parent?.Parent?.Parent is DrawerLayout dl3)
                    {
                        appbarConfigBuilder = appbarConfigBuilder.SetOpenableLayout(dl3);
                    }

                    var appbarConfig =
                        appbarConfigBuilder.Build();

                    NavigationUI
                    .SetupWithNavController(nativeToolbar, controller, appbarConfig);

                    // the call to SetupWithNavController resets the Navigation Icon
                    toolbar.Handler?.UpdateValue(nameof(IToolbar.BackButtonVisible));

                    if (toolbar.BackButtonVisible && toolbar.IsVisible)
                    {
                        // Wiring up to this will break the Drawer Toggle button if it's visible
                        nativeToolbar.SetNavigationOnClickListener(_stackNavigationManager.BackClick);
                    }
                }
            }
        private void SetupNavigation()
        {
            var             bottomNavigationView = FindViewById <BottomNavigationView>(Resource.Id.main_bottom_navigation_view);
            NavHostFragment navHostFragment      = (NavHostFragment)SupportFragmentManager
                                                   .FindFragmentById(Resource.Id.fragNavHost);

            NavigationUI.SetupWithNavController(
                bottomNavigationView,
                navHostFragment.NavController);
        }
 protected override void OnCreate(Android.OS.Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     SetContentView(Resource.Layout.main);
     HostFragment  = (NavHostFragment)SupportFragmentManager.FindFragmentById(Resource.Id.main_fragment);
     Controller    = HostFragment.NavController;
     NavigationBar = FindViewById <BottomNavigationView>(Resource.Id.main_navigation);
     NavigationUI.SetupWithNavController(NavigationBar, Controller);
     Controller.DestinationChanged += OnDestinationChange;
 }
            public override void OnFragmentViewCreated(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f, AView v, Bundle savedInstanceState)
            {
                base.OnFragmentViewCreated(fm, f, v, savedInstanceState);

                var controller   = NavHostFragment.FindNavController(f);
                var appbarConfig =
                    new AppBarConfiguration
                    .Builder(controller.Graph)
                    .Build();

                // These have to get called/wired up every time a new fragment view is created
                // I'm not clear why this can't just be done once
                NavigationUI
                .SetupWithNavController(_navigationManager.Toolbar, controller, appbarConfig);

                _navigationManager.Toolbar.SetNavigationOnClickListener(_navigationManager.BackClick);
            }
Exemple #8
0
        public override void OnViewCreated(AView view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);

            var controller   = NavHostFragment.FindNavController(this);
            var appbarConfig =
                new AppBarConfiguration
                .Builder(controller.Graph)
                .Build();

            NavigationUI
            .SetupWithNavController(NavDestination.NavigationPageHandler.Toolbar, controller, appbarConfig);

            HasOptionsMenu = true;

            NavDestination.NavigationPageHandler.Toolbar.SetNavigationOnClickListener(BackClick);

            UpdateToolbar();
            NavDestination.NavigationPageHandler.Toolbar
            .Title = NavDestination.Page.Title;

            if (Context.GetActivity() is AppCompatActivity aca)
            {
                aca.SupportActionBar.Title = NavDestination.Page.Title;

                // TODO MAUI put this elsewhere once we figure out how attached property handlers work
                bool showNavBar = false;
                if (NavDestination.Page is BindableObject bo)
                {
                    showNavBar = NavigationPage.GetHasNavigationBar(bo);
                }

                var appBar = NavDestination.NavigationPageHandler.AppBar;
                if (!showNavBar)
                {
                    if (appBar.LayoutParameters is CoordinatorLayout.LayoutParams cl)
                    {
                        cl.Height = 0;
                        appBar.LayoutParameters = cl;
                    }
                }
                else
                {
                    if (appBar.LayoutParameters is CoordinatorLayout.LayoutParams cl)
                    {
                        cl.Height = ActionBarHeight();
                        appBar.LayoutParameters = cl;
                    }
                }
            }


            int ActionBarHeight()
            {
                int attr = Resource.Attribute.actionBarSize;

                int actionBarHeight = (int)Context.GetThemeAttributePixels(Resource.Attribute.actionBarSize);

                //if (actionBarHeight <= 0)
                //	return Device.Info.CurrentOrientation.IsPortrait() ? (int)Context.ToPixels(56) : (int)Context.ToPixels(48);

                //if (Context.GetActivity().Window.Attributes.Flags.HasFlag(WindowManagerFlags.TranslucentStatus) || Context.GetActivity().Window.Attributes.Flags.HasFlag(WindowManagerFlags.TranslucentNavigation))
                //{
                //	if (_toolbar.PaddingTop == 0)
                //		_toolbar.SetPadding(0, GetStatusBarHeight(), 0, 0);

                //	return actionBarHeight + GetStatusBarHeight();
                //}

                return(actionBarHeight);
            }
        }