void RemovePage(Page page) { IVisualElementRenderer rendererToRemove = Platform.GetRenderer(page); PageContainer containerToRemove = rendererToRemove == null ? null : (PageContainer)rendererToRemove.View.Parent; containerToRemove.RemoveFromParent(); if (rendererToRemove != null) { rendererToRemove.View.RemoveFromParent(); rendererToRemove.Dispose(); } containerToRemove?.Dispose(); UpdateActionBar(); }
public override Object InstantiateItem(ViewGroup container, int position) { ContentPage child = _page.Children.ElementAt(position); if (Platform.GetRenderer(child) == null) { Platform.SetRenderer(child, Platform.CreateRenderer(child)); } IVisualElementRenderer renderer = Platform.GetRenderer(child); renderer.View.RemoveFromParent(); ViewGroup frame = new PageContainer(_context, renderer); container.AddView(frame); return(new ObjectJavaBox <Tuple <ViewGroup, Page, int> >(new Tuple <ViewGroup, Page, int>(frame, child, position))); }
void RemovePage(Page page) { IVisualElementRenderer rendererToRemove = Platform.GetRenderer(page); PageContainer containerToRemove = rendererToRemove == null ? null : (PageContainer)rendererToRemove.ViewGroup.Parent; containerToRemove.RemoveFromParent(); if (rendererToRemove != null) { rendererToRemove.ViewGroup.RemoveFromParent(); rendererToRemove.Dispose(); } containerToRemove?.Dispose(); Device.StartTimer(TimeSpan.FromMilliseconds(0), () => { ((Platform)Element.Platform).UpdateNavigationTitleBar(); return(false); }); }
Task <bool> SwitchContentAsync(Page view, bool animated, bool removed = false) { Context.HideKeyboard(this); IVisualElementRenderer rendererToAdd = Platform.GetRenderer(view); bool existing = rendererToAdd != null; if (!existing) { Platform.SetRenderer(view, rendererToAdd = Platform.CreateRenderer(view)); } Page pageToRemove = _current; IVisualElementRenderer rendererToRemove = pageToRemove == null ? null : Platform.GetRenderer(pageToRemove); PageContainer containerToRemove = rendererToRemove == null ? null : (PageContainer)rendererToRemove.ViewGroup.Parent; PageContainer containerToAdd = (PageContainer)rendererToAdd.ViewGroup.Parent ?? new PageContainer(Context, rendererToAdd); containerToAdd.SetWindowBackground(); _current = view; ((Platform)Element.Platform).NavAnimationInProgress = true; var tcs = new TaskCompletionSource <bool>(); if (animated) { if (s_currentAnimation != null) { s_currentAnimation.Cancel(); } if (removed) { // animate out if (containerToAdd.Parent != this) { AddView(containerToAdd, Element.LogicalChildren.IndexOf(rendererToAdd.Element)); } else { ((Page)rendererToAdd.Element).SendAppearing(); } containerToAdd.Visibility = ViewStates.Visible; if (containerToRemove != null) { Action <AndroidAnimation.Animator> done = a => { containerToRemove.Visibility = ViewStates.Gone; containerToRemove.Alpha = 1; containerToRemove.ScaleX = 1; containerToRemove.ScaleY = 1; RemoveView(containerToRemove); tcs.TrySetResult(true); ((Platform)Element.Platform).NavAnimationInProgress = false; VisualElement removedElement = rendererToRemove.Element; rendererToRemove.Dispose(); if (removedElement != null) { Platform.SetRenderer(removedElement, null); } }; // should always happen s_currentAnimation = containerToRemove.Animate().Alpha(0).ScaleX(0.8f).ScaleY(0.8f).SetDuration(250).SetListener(new GenericAnimatorListener { OnEnd = a => { s_currentAnimation = null; done(a); }, OnCancel = done }); } } else { bool containerAlreadyAdded = containerToAdd.Parent == this; // animate in if (!containerAlreadyAdded) { AddView(containerToAdd); } else { ((Page)rendererToAdd.Element).SendAppearing(); } if (existing) { Element.ForceLayout(); } containerToAdd.Alpha = 0; containerToAdd.ScaleX = containerToAdd.ScaleY = 0.8f; containerToAdd.Visibility = ViewStates.Visible; s_currentAnimation = containerToAdd.Animate().Alpha(1).ScaleX(1).ScaleY(1).SetDuration(250).SetListener(new GenericAnimatorListener { OnEnd = a => { if (containerToRemove != null && containerToRemove.Handle != IntPtr.Zero) { containerToRemove.Visibility = ViewStates.Gone; if (pageToRemove != null) { pageToRemove.SendDisappearing(); } } s_currentAnimation = null; tcs.TrySetResult(true); ((Platform)Element.Platform).NavAnimationInProgress = false; } }); } } else { // just do it fast if (containerToRemove != null) { if (removed) { RemoveView(containerToRemove); } else { containerToRemove.Visibility = ViewStates.Gone; } } if (containerToAdd.Parent != this) { AddView(containerToAdd); } else { ((Page)rendererToAdd.Element).SendAppearing(); } if (containerToRemove != null && !removed) { pageToRemove.SendDisappearing(); } if (existing) { Element.ForceLayout(); } containerToAdd.Visibility = ViewStates.Visible; tcs.SetResult(true); ((Platform)Element.Platform).NavAnimationInProgress = false; } return(tcs.Task); }
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; } }