void DisposeChildRenderers() { IVisualElementRenderer childRenderer = APlatform.GetRenderer(_childView); childRenderer?.Dispose(); _childView?.ClearValue(APlatform.RendererProperty); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { if (_childView == null) { return; } Rectangle bounds = GetBounds(_isFlyout, l, t, r, b); if (_isFlyout) { FlyoutPageController.FlyoutBounds = bounds; } else { FlyoutPageController.DetailBounds = bounds; } IVisualElementRenderer renderer = APlatform.GetRenderer(_childView); renderer?.UpdateLayout(); // If we're using a PageContainer (i.e., we've wrapped our contents in a Fragment), // Make sure that it gets laid out if (_pageContainer != null) { if (_isFlyout) { var controller = (IFlyoutPageController)_parent; var width = (int)Context.ToPixels(controller.FlyoutBounds.Width); // When the base class computes the size of the Flyout container, it starts at the top of the // screen and adds padding (_parent.FlyoutBounds.Top) to leave room for the status bar // When this container is laid out, it's already starting from the adjusted y value of the parent, // so we subtract _parent.FlyoutBounds.Top from our starting point (to get 0) and add it to the // bottom (so the flyout page stretches to the bottom of the screen) var height = (int)Context.ToPixels(controller.FlyoutBounds.Height + controller.FlyoutBounds.Top); _pageContainer.Layout(0, 0, width, height); } else { _pageContainer.Layout(l, t, r, b); } _pageContainer.Child.UpdateLayout(); } }
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); }
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.SetOnItemSelectedListener(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); }
protected virtual void AddChildView(VisualElement childView) { _pageContainer = null; Page page = childView as NavigationPage ?? (Page)(childView as TabbedPage); if (page == null) { // The thing we're adding is not a NavigationPage or TabbedPage, so we can just use the old AddChildView if (_currentFragment != null) { if (!_parent.IsAttachedToRoot()) { return; } // But first, if the previous occupant of this container was a fragment, we need to remove it properly FragmentTransaction transaction = FragmentManager.BeginTransactionEx(); transaction.RemoveEx(_currentFragment); transaction.SetTransitionEx((int)FragmentTransit.None); if (IsAttachedToWindow) { ExecuteTransaction(transaction); } else { _transaction = transaction; } _currentFragment = null; } IVisualElementRenderer renderer = APlatform.GetRenderer(childView); if (renderer == null) { APlatform.SetRenderer(childView, renderer = APlatform.CreateRenderer(childView, Context)); } if (renderer.View.Parent != this) { if (renderer.View.Parent != null) { renderer.View.RemoveFromParent(); } SetDefaultBackgroundColor(renderer); AddView(renderer.View); renderer.UpdateLayout(); } } else { if (!_parent.IsAttachedToRoot()) { return; } // The renderers for NavigationPage and TabbedPage both host fragments, so they need to be wrapped in a // FragmentContainer in order to get isolated fragment management Fragment fragment = FragmentContainer.CreateInstance(page); var fc = fragment as FragmentContainer; fc?.SetOnCreateCallback(pc => { _pageContainer = pc; UpdateFlowDirection(); SetDefaultBackgroundColor(pc.Child); }); FragmentTransaction transaction = FragmentManager.BeginTransactionEx(); if (_currentFragment != null) { transaction.RemoveEx(_currentFragment); } transaction.AddEx(Id, fragment); transaction.SetTransitionEx((int)FragmentTransit.None); if (IsAttachedToWindow) { ExecuteTransaction(transaction); } else { _transaction = transaction; } _currentFragment = fragment; } }