Ejemplo n.º 1
0
        void Destroy()
        {
            ((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this);

            if (_shellContent != null)
            {
                ((IShellContentController)_shellContent).RecyclePage(_page);
                _page.ClearValue(AppCompat.Platform.RendererProperty);
                _page = null;
            }

            if (_shellPageContainer != null)
            {
                _shellPageContainer.RemoveAllViews();

                if (_root is ViewGroup vg)
                {
                    vg.RemoveView(_shellPageContainer);
                }
            }

            _renderer?.Dispose();
            _root?.Dispose();
            _toolbarTracker?.Dispose();
            _appearanceTracker?.Dispose();


            _appearanceTracker = null;
            _toolbarTracker    = null;
            _toolbar           = null;
            _root         = null;
            _renderer     = null;
            _shellContent = null;
        }
Ejemplo n.º 2
0
        void Destroy()
        {
            if (_rootView != null)
            {
                UnhookEvents();

                _viewPager.RemoveOnPageChangeListener(this);
                var adapter = _viewPager.Adapter;
                _viewPager.Adapter = null;
                adapter.Dispose();

                _tablayout.LayoutChange -= OnTabLayoutChange;
                _toolbarAppearanceTracker.Dispose();
                _tabLayoutAppearanceTracker.Dispose();
                _toolbarTracker.Dispose();
                _tablayout.Dispose();
                _toolbar.Dispose();
                _viewPager.Dispose();
                _rootView.Dispose();
            }

            _toolbarAppearanceTracker   = null;
            _tabLayoutAppearanceTracker = null;
            _toolbarTracker             = null;
            _tablayout = null;
            _toolbar   = null;
            _viewPager = null;
            _rootView  = null;
        }
Ejemplo n.º 3
0
        void Destroy()
        {
            if (_rootView != null)
            {
                UnhookEvents();

                _shellContext?.Shell?.Toolbar?.Handler?.DisconnectHandler();

                //_viewPager.RemoveOnPageChangeListener(this);
                var adapter = _viewPager.Adapter;
                _viewPager.Adapter = null;
                adapter.Dispose();

                _tablayout.LayoutChange -= OnTabLayoutChange;
                _toolbarAppearanceTracker.Dispose();
                _tabLayoutAppearanceTracker.Dispose();
                _toolbarTracker.Dispose();
                _tablayout.Dispose();
                _toolbar.Dispose();
                _viewPager.Dispose();
                _rootView.Dispose();
            }

            _toolbarAppearanceTracker   = null;
            _tabLayoutAppearanceTracker = null;
            _toolbarTracker             = null;
            _tablayout = null;
            _toolbar   = null;
            _viewPager = null;
            _rootView  = null;
        }
Ejemplo n.º 4
0
        // Use OnDestroy instead of OnDestroyView because OnDestroyView will be
        // called before the animation completes. This causes tons of tiny issues.
        public override void OnDestroy()
        {
            base.OnDestroy();

            if (_rootView != null)
            {
                UnhookEvents();

                var adapter = _viewPager.Adapter;
                _viewPager.Adapter = null;
                adapter.Dispose();

                _toolbarAppearanceTracker.Dispose();
                _tabLayoutAppearanceTracker.Dispose();
                _viewPager.RemoveOnPageChangeListener(this);
                _rootView.Dispose();
                _toolbarTracker.Dispose();

                _tablayout.Dispose();
                _toolbar.Dispose();
                _viewPager.Dispose();
                _rootView.Dispose();
            }

            _toolbarAppearanceTracker   = null;
            _tabLayoutAppearanceTracker = null;
            _toolbarTracker             = null;
            _toolbar   = null;
            _tablayout = null;
            _rootView  = null;
            _viewPager = null;
        }
Ejemplo n.º 5
0
        void Destroy()
        {
            ((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this);

            if (_shellContent != null)
            {
                ((IShellContentController)_shellContent).RecyclePage(_page);
                _page.Handler = null;
            }

            if (_shellPageContainer != null)
            {
                _shellPageContainer.RemoveAllViews();

                if (_root is ViewGroup vg)
                {
                    vg.RemoveView(_shellPageContainer);
                }

                _shellPageContainer.Dispose();
            }

            _root?.Dispose();
            _toolbarTracker?.Dispose();
            _appearanceTracker?.Dispose();


            _appearanceTracker = null;
            _toolbarTracker    = null;
            _toolbar           = null;
            _root               = null;
            _viewhandler        = null;
            _shellContent       = null;
            _shellPageContainer = null;
        }
Ejemplo n.º 6
0
        // Use OnDestroy instead of OnDestroyView because OnDestroyView will be
        // called before the animation completes. This causes tons of tiny issues.
        public override void OnDestroy()
        {
            base.OnDestroy();

            _shellPageContainer.RemoveAllViews();
            _renderer?.Dispose();
            _root?.Dispose();
            _toolbarTracker.Dispose();
            _appearanceTracker.Dispose();

            ((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this);

            if (_shellContent != null)
            {
                ((IShellContentController)_shellContent).RecyclePage(_page);
                _page.ClearValue(Platform.RendererProperty);
                _page = null;
            }

            _appearanceTracker = null;
            _toolbar           = null;
            _toolbarTracker    = null;
            _root     = null;
            _renderer = null;
        }
Ejemplo n.º 7
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_shellContent != null)
            {
                _page = ((IShellContentController)_shellContent).GetOrCreateContent();
            }

            _root = inflater.Inflate(Resource.Layout.ShellContent, null).JavaCast <CoordinatorLayout>();

            var scrollview = _root.FindViewById <NestedScrollView>(Resource.Id.shellcontent_scrollview);

            _toolbar = _root.FindViewById <Toolbar>(Resource.Id.shellcontent_toolbar);

            _renderer = Platform.CreateRenderer(_page, Context);
            Platform.SetRenderer(_page, _renderer);

            _shellPageContainer = new ShellPageContainer(Context, _renderer);

            scrollview.AddView(_shellPageContainer);

            _toolbarTracker      = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.Page = _page;
            // this is probably not the most ideal way to do that
            _toolbarTracker.CanNavigateBack = _shellContent == null;

            _appearanceTracker = _shellContext.CreateToolbarAppearanceTracker();

            ((IShellController)_shellContext.Shell).AddAppearanceObserver(this, _page);

            return(_root);
        }
Ejemplo n.º 8
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var shellSection = ShellSection;

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

            var root = inflater.Inflate(Resource.Layout.RootLayout, null).JavaCast <CoordinatorLayout>();

            _toolbar = root.FindViewById <Toolbar>(Resource.Id.main_toolbar);
            var scrollview = root.FindViewById <NestedScrollView>(Resource.Id.main_scrollview);

            _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout);

            _viewPager = new FormsViewPager(Context)
            {
                LayoutParameters = new LP(LP.MatchParent, LP.MatchParent),
            };

            _viewPager.AddOnPageChangeListener(this);
            _viewPager.Id = Platform.GenerateViewId();

            _viewPager.Adapter        = new ShellFragmentPagerAdapter(shellSection, ChildFragmentManager);
            _viewPager.OverScrollMode = OverScrollMode.Never;

            _tablayout.SetupWithViewPager(_viewPager);

            var currentPage  = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();
            var currentIndex = ShellSection.Items.IndexOf(ShellSection.CurrentItem);

            _toolbarTracker      = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.Page = currentPage;

            _viewPager.CurrentItem = currentIndex;
            scrollview.AddView(_viewPager);

            if (shellSection.Items.Count == 1)
            {
                _tablayout.Visibility = ViewStates.Gone;
            }

            _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
            _toolbarAppearanceTracker   = _shellContext.CreateToolbarAppearanceTracker();

            HookEvents();

            scrollview.Dispose();

            return(_rootView = root);
        }
Ejemplo n.º 9
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var shellSection = ShellSection;

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

            if (shellSection.CurrentItem == null)
            {
                throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}.");
            }

            var root = inflater.Inflate(Resource.Layout.RootLayout, null).JavaCast <CoordinatorLayout>();

            _toolbar   = root.FindViewById <Toolbar>(Resource.Id.main_toolbar);
            _viewPager = root.FindViewById <FormsViewPager>(Resource.Id.main_viewpager);
            _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout);

            _viewPager.EnableGesture = false;

            _viewPager.AddOnPageChangeListener(this);
            _viewPager.Id = Platform.GenerateViewId();

            _viewPager.Adapter        = new ShellFragmentPagerAdapter(shellSection, ChildFragmentManager);
            _viewPager.OverScrollMode = OverScrollMode.Never;

            _tablayout.SetupWithViewPager(_viewPager);

            var currentPage  = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();
            var currentIndex = SectionController.GetItems().IndexOf(ShellSection.CurrentItem);

            _toolbarTracker      = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.Page = currentPage;

            _viewPager.CurrentItem = currentIndex;

            if (SectionController.GetItems().Count == 1)
            {
                _tablayout.Visibility = ViewStates.Gone;
            }

            _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
            _toolbarAppearanceTracker   = _shellContext.CreateToolbarAppearanceTracker();

            HookEvents();

            return(_rootView = root);
        }
Ejemplo n.º 10
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_shellContent != null)
            {
                _page = ((IShellContentController)_shellContent).GetOrCreateContent();
            }

            _root = inflater.Inflate(Controls.Resource.Layout.shellcontent, null).JavaCast <CoordinatorLayout>();

            var shellContentMauiContext = MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager);

            Maui.IElement parentElement = (_shellContent as Maui.IElement) ?? _page;
            var           shellToolbar  = new Toolbar(parentElement);

            ShellToolbarTracker.ApplyToolbarChanges(_shellContext.Shell.Toolbar, shellToolbar);
            _toolbar = (AToolbar)shellToolbar.ToPlatform(shellContentMauiContext);

            var appBar = _root.FindViewById <AppBarLayout>(Resource.Id.shellcontent_appbar);

            appBar.AddView(_toolbar);
            _viewhandler = _page.ToHandler(shellContentMauiContext);

            _shellPageContainer = new ShellPageContainer(Context, _viewhandler);

            if (_root is ViewGroup vg)
            {
                vg.AddView(_shellPageContainer);
            }

            _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.SetToolbar(shellToolbar);
            _toolbarTracker.Page = _page;
            // this is probably not the most ideal way to do that
            _toolbarTracker.CanNavigateBack = _shellContent == null;

            _appearanceTracker = _shellContext.CreateToolbarAppearanceTracker();

            ((IShellController)_shellContext.Shell).AddAppearanceObserver(this, _page);

            if (_shellPageContainer.LayoutParameters is CoordinatorLayout.LayoutParams layoutParams)
            {
                layoutParams.Behavior = new AppBarLayout.ScrollingViewBehavior();
            }

            return(_root);
        }
Ejemplo n.º 11
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_shellContent != null)
            {
                _page = ((IShellContentController)_shellContent).GetOrCreateContent();
            }

            _root = inflater.Inflate(Resource.Layout.ShellContent, null).JavaCast <CoordinatorLayout>();

            _toolbar = _root.FindViewById <Toolbar>(Resource.Id.shellcontent_toolbar);

            _renderer = AppCompat.Platform.CreateRenderer(_page, Context);
            AppCompat.Platform.SetRenderer(_page, _renderer);

            _shellPageContainer = new ShellPageContainer(Context, _renderer);

            if (_root is ViewGroup vg)
            {
                vg.AddView(_shellPageContainer);
            }

            _toolbarTracker      = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.Page = _page;
            // this is probably not the most ideal way to do that
            _toolbarTracker.CanNavigateBack = _shellContent == null;

            _appearanceTracker = _shellContext.CreateToolbarAppearanceTracker();

            ((IShellController)_shellContext.Shell).AddAppearanceObserver(this, _page);

            if (_shellPageContainer.LayoutParameters is CoordinatorLayout.LayoutParams layoutParams)
            {
                layoutParams.Behavior = new AppBarLayout.ScrollingViewBehavior();
            }

            return(_root);
        }
Ejemplo n.º 12
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var shellSection = ShellSection;

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

            if (shellSection.CurrentItem == null)
            {
                throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}.");
            }

            var context         = Context;
            var root            = PlatformInterop.CreateShellCoordinatorLayout(context);
            var appbar          = PlatformInterop.CreateShellAppBar(context, Resource.Attribute.appBarLayoutStyle, root);
            int actionBarHeight = context.GetActionBarHeight();

            _toolbar   = PlatformInterop.CreateShellToolbar(context, appbar, actionBarHeight, Resource.Style.ThemeOverlay_AppCompat_Light);
            _tablayout = PlatformInterop.CreateShellTabLayout(context, appbar, actionBarHeight);

            var pagerContext        = MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager);
            var adapter             = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, pagerContext);
            var pageChangedCallback = new ViewPagerPageChanged(this);

            _viewPager = PlatformInterop.CreateShellViewPager(context, root, _tablayout, this, adapter, pageChangedCallback);

            Page currentPage  = null;
            int  currentIndex = -1;
            var  currentItem  = shellSection.CurrentItem;
            var  items        = SectionController.GetItems();

            while (currentIndex < 0 && items.Count > 0 && shellSection.CurrentItem != null)
            {
                currentItem = shellSection.CurrentItem;
                currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();

                // current item hasn't changed
                if (currentItem == shellSection.CurrentItem)
                {
                    currentIndex = items.IndexOf(currentItem);
                }
            }

            _toolbarTracker      = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.Page = currentPage;

            _viewPager.CurrentItem = currentIndex;

            if (items.Count == 1)
            {
                UpdateTablayoutVisibility();
            }

            _tablayout.LayoutChange += OnTabLayoutChange;

            _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
            _toolbarAppearanceTracker   = _shellContext.CreateToolbarAppearanceTracker();

            HookEvents();

            return(_rootView = root);
        }
Ejemplo n.º 13
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var shellSection = ShellSection;

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

            if (shellSection.CurrentItem == null)
            {
                throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}.");
            }

            var root = inflater.Inflate(Resource.Layout.shellrootlayout, null).JavaCast <CoordinatorLayout>();

            _toolbar = root.FindViewById <Toolbar>(Resource.Id.maui_toolbar);
            if (Context.GetActivity() is AppCompatActivity aca)
            {
                aca.SetSupportActionBar(_toolbar);
            }

            _viewPager = root.FindViewById <ViewPager2>(Resource.Id.main_viewpager);
            _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout);

            //_viewPager.EnableGesture = false;

            //_viewPager.AddOnPageChangeListener(this);
            _viewPager.Id = AView.GenerateViewId();

            _viewPager.Adapter        = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, MauiContext);
            _viewPager.OverScrollMode = OverScrollMode.Never;

            new TabLayoutMediator(_tablayout, _viewPager, this)
            .Attach();

            //_tablayout.SetupWithViewPager(_viewPager);

            Page currentPage  = null;
            int  currentIndex = -1;
            var  currentItem  = ShellSection.CurrentItem;

            while (currentIndex < 0 && SectionController.GetItems().Count > 0 && ShellSection.CurrentItem != null)
            {
                currentItem = ShellSection.CurrentItem;
                currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();

                // current item hasn't changed
                if (currentItem == shellSection.CurrentItem)
                {
                    currentIndex = SectionController.GetItems().IndexOf(currentItem);
                }
            }

            _toolbarTracker      = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.Page = currentPage;

            _viewPager.CurrentItem = currentIndex;

            if (SectionController.GetItems().Count == 1)
            {
                UpdateTablayoutVisibility();
            }

            _tablayout.LayoutChange += OnTabLayoutChange;

            _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
            _toolbarAppearanceTracker   = _shellContext.CreateToolbarAppearanceTracker();

            HookEvents();

            return(_rootView = root);
        }