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 Java.Lang.Object InstantiateItem(ViewGroup container, int position) { ContentPage child = _page.Children.ElementAt(position); if (AppCompat.Platform.GetRenderer(child) == null) { AppCompat.Platform.SetRenderer(child, AppCompat.Platform.CreateRenderer(child, _context)); } IVisualElementRenderer renderer = AppCompat.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))); }
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, Context)); } Page pageToRemove = _current; IVisualElementRenderer rendererToRemove = pageToRemove == null ? null : Platform.GetRenderer(pageToRemove); PageContainer containerToRemove = rendererToRemove == null ? null : (PageContainer)rendererToRemove.View.Parent; PageContainer containerToAdd = (PageContainer)rendererToAdd.View.Parent ?? new PageContainer(Context, rendererToAdd); containerToAdd.SetWindowBackground(); _current = view; if (Platform != null) { 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) { var indexRenderToAdd = Math.Min(ChildCount, ((IElementController)Element).LogicalChildren.IndexOf(rendererToAdd.Element)); AddView(containerToAdd, indexRenderToAdd); } else { ((IPageController)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); 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 { ((IPageController)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; ((IPageController)pageToRemove)?.SendDisappearing(); } s_currentAnimation = null; tcs.TrySetResult(true); } }); } } else { // just do it fast if (containerToRemove != null) { if (removed) { RemoveView(containerToRemove); } else { containerToRemove.Visibility = ViewStates.Gone; } } if (containerToAdd.Parent != this) { AddView(containerToAdd); } else { ((IPageController)rendererToAdd.Element).SendAppearing(); } if (containerToRemove != null && !removed) { ((IPageController)pageToRemove).SendDisappearing(); } if (existing) { Element.ForceLayout(); } containerToAdd.Visibility = ViewStates.Visible; tcs.SetResult(true); } return(tcs.Task.ContinueWith(task => { if (Platform != null) { Platform.NavAnimationInProgress = false; } return task.Result; })); }