Пример #1
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                if (_currentFragment != null && !FragmentManager.IsDestroyed)
                {
                    FragmentTransaction transaction = FragmentManager.BeginTransactionEx();
                    transaction.RemoveEx(_currentFragment);
                    transaction.SetTransitionEx((int)FragmentTransit.None);
                    transaction.CommitAllowingStateLossEx();
                    FragmentManager.ExecutePendingTransactionsEx();

                    _currentFragment = null;
                }

                _parent          = null;
                _pageContainer   = null;
                _fragmentManager = null;
                RemoveAllViews();
                DisposeChildRenderers();
            }

            base.Dispose(disposing);
        }
Пример #2
0
        void ExecuteTransaction(FragmentTransaction transaction)
        {
            // We don't currently support fragment restoration
            // So we don't need to worry about loss of this fragment's state
            transaction.CommitAllowingStateLossEx();

            // The transaction need to be executed after View has been attached
            // So Fragment Manager can find the View being added
            FragmentManager.ExecutePendingTransactionsEx();
        }
Пример #3
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                DeviceDisplay.MainDisplayInfoChanged -= 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 FlyoutPage (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);
        }