Beispiel #1
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                Device.Info.PropertyChanged -= DeviceInfoPropertyChanged;

                if (NavigationPageController != null)
                {
                    var navController = NavigationPageController;

                    navController.PushRequested             -= OnPushed;
                    navController.PopRequested              -= OnPopped;
                    navController.PopToRootRequested        -= OnPoppedToRoot;
                    navController.InsertPageBeforeRequested -= OnInsertPageBeforeRequested;
                    navController.RemovePageRequested       -= OnRemovePageRequested;
                }

                if (Current != null)
                {
                    Current.PropertyChanged -= CurrentOnPropertyChanged;
                }

                FragmentManager fm = FragmentManager;

                if (!fm.IsDestroyed)
                {
                    FragmentTransaction trans = fm.BeginTransactionEx();
                    foreach (Fragment fragment in _fragmentStack)
                    {
                        trans.RemoveEx(fragment);
                    }
                    trans.CommitAllowingStateLossEx();
                    fm.ExecutePendingTransactionsEx();
                }

                _toolbar.RemoveView(_titleView);
                _titleView?.Dispose();
                _titleView = null;

                if (_titleViewRenderer != null)
                {
                    Platform.ClearRenderer(_titleViewRenderer.View);
                    _titleViewRenderer.Dispose();
                    _titleViewRenderer = null;
                }

                _toolbar.RemoveView(_titleIconView);
                _titleIconView?.Dispose();
                _titleIconView = null;

                _imageSource = null;

                if (_toolbarTracker != null)
                {
                    _toolbarTracker.CollectionChanged -= ToolbarTrackerOnCollectionChanged;

                    _toolbar.DisposeMenuItems(_currentToolbarItems, OnToolbarItemPropertyChanged);

                    _toolbarTracker.Target = null;
                    _toolbarTracker        = null;
                }

                if (_currentMenuItems != null)
                {
                    _currentMenuItems.Clear();
                    _currentMenuItems = null;
                }

                if (_currentToolbarItems != null)
                {
                    _currentToolbarItems.Clear();
                    _currentToolbarItems = null;
                }

                if (_toolbar != null)
                {
                    _toolbar.SetNavigationOnClickListener(null);
                    _toolbar.Menu.Clear();

                    RemoveView(_toolbar);

                    _toolbar.Dispose();
                    _toolbar = null;
                }

                if (_drawerLayout.IsAlive() && _drawerListener.IsAlive())
                {
                    _drawerLayout.RemoveDrawerListener(_drawerListener);

                    RemoveView(_drawerLayout);
                }

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

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

                if (_backgroundDrawable != null)
                {
                    _backgroundDrawable.Dispose();
                    _backgroundDrawable = null;
                }

                Current = null;

                // We dispose the child renderers after cleaning up everything related to DrawerLayout in case
                // one of the children is a MasterDetailPage (which may dispose of the DrawerLayout).
                if (Element != null)
                {
                    foreach (Element element in PageController.InternalChildren)
                    {
                        var child = element as VisualElement;
                        if (child == null)
                        {
                            continue;
                        }

                        IVisualElementRenderer renderer = Platform.GetRenderer(child);
                        renderer?.Dispose();
                    }
                }
            }

            base.Dispose(disposing);
        }
Beispiel #2
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)
            {
                if (PageController.InternalChildren.Count > 0)
                {
                    _masterDetailPage = PageController.InternalChildren[0] as MasterDetailPage;
                }

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

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

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

            if (renderer == null)
            {
                return;
            }

            _drawerLayout = renderer;

            FastRenderers.AutomationPropertiesProvider.GetDrawerAccessibilityResources(context, _masterDetailPage, 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(Element)
            };

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

            _drawerListener = new DrawerMultiplexedListener {
                Listeners = { _drawerToggle, renderer }
            };
            _drawerLayout.AddDrawerListener(_drawerListener);
        }
Beispiel #3
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                _disposed = true;

                if (Element != null)
                {
                    PageController.InternalChildren.CollectionChanged -= OnChildrenCollectionChanged;

                    foreach (Page pageToRemove in Element.Children)
                    {
                        TeardownPage(pageToRemove);
                    }
                }

                RemoveAllViews();

                if (_viewPager != null)
                {
                    _viewPager.ClearOnPageChangeListeners();
                    _viewPager.Adapter.Dispose();
                    _viewPager.Dispose();
                    _viewPager = null;
                }

                if (_tabLayout != null)
                {
                    _tabLayout.ClearOnTabSelectedListeners();
                    _tabLayout.Dispose();
                    _tabLayout = null;
                }

                if (_bottomNavigationView != null)
                {
                    _bottomNavigationView.SetOnNavigationItemSelectedListener(null);
                    _bottomNavigationView.Dispose();
                    _bottomNavigationView = null;
                }

                if (_relativeLayout != null)
                {
                    _relativeLayout.Dispose();
                    _relativeLayout = null;
                }

                if (Element != null)
                {
                    foreach (Page pageToRemove in Element.Children)
                    {
                        IVisualElementRenderer pageRenderer = Platform.GetRenderer(pageToRemove);

                        pageRenderer?.Dispose();

                        pageToRemove.ClearValue(Platform.RendererProperty);
                    }
                }

                _previousPage = null;
            }

            base.Dispose(disposing);
        }