Esempio n. 1
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);
                    }
                }
            }
Esempio n. 2
0
        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);
        }