protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); // 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 (_isMaster) { var controller = (IMasterDetailPageController)_parent; var width = (int)Context.ToPixels(controller.MasterBounds.Width); // When the base class computes the size of the Master container, it starts at the top of the // screen and adds padding (_parent.MasterBounds.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.MasterBounds.Top from our starting point (to get 0) and add it to the // bottom (so the master page stretches to the bottom of the screen) var height = (int)Context.ToPixels(controller.MasterBounds.Height + controller.MasterBounds.Top); _pageContainer.Layout(0, 0, width, height); } else { _pageContainer.Layout(l, t, r, b); } _pageContainer.Child.UpdateLayout(); } }
void ToggleShowing(bool isShowing, bool animated) { if (_contentPage == null) { _contentPage = new YoutubeStyleContentPage(); _contentPage.ParentHeight = Height; PageContainer.Content = _contentPage; _panGesture = new PanGestureRecognizer(); _panGesture.OnAction += Gesture_OnAction; _panGesture.IsConsumingTouchesInParallel = true; _contentPage.VideoPlayerView.AddGestureRecognizer(_panGesture); } var minHeight = _contentPage.MinimumHeightRequest; var minWidth = _contentPage.MinimumWidthRequest; _contentBounds.Y = isShowing ? 0 : Height - minHeight; _contentBounds.X = isShowing ? 0 : Width - minWidth; _contentBounds.Width = isShowing ? Width : minWidth; _contentBounds.Height = isShowing ? Height : minHeight; if (MediaItemsListView.SelectedItem != null) { _contentPage.Item = MediaItemsListView.SelectedItem as MediaItem; } if (animated) { PageContainer.LayoutTo(_contentBounds); } else { PageContainer.Layout(_contentBounds); } }
void MainLayout_OnLayoutChildren(double x, double y, double width, double height) { MediaItemsListView.Layout(new Rectangle(0, 0, Width, Height)); if (!_didLayoutContainer) { _contentBounds.Y = height - 100; _contentBounds.X = width - 160; _contentBounds.Width = 160; _contentBounds.Height = 100; _didLayoutContainer = true; } PageContainer.Layout(_contentBounds); }
void Gesture_OnAction(BaseGestureRecognizer recgonizer, GestureRecognizerState state) { if (recgonizer.View != _contentPage.VideoPlayerView) { return; } var panGesture = recgonizer as PanGestureRecognizer; Point translation = panGesture.GetTranslationInView(MainLayout); Point velocity = panGesture.GetVelocityInView(MainLayout); panGesture.SetTranslationInView(new Point(0, 0), MainLayout); switch (panGesture.State) { case GestureRecognizerState.Began: break; case GestureRecognizerState.Changed: var newY = _contentBounds.Y + translation.Y; if (newY > 0 && newY < Height - _contentPage.MinimumHeightRequest) { var minHeight = _contentPage.MinimumHeightRequest; var minWidth = _contentPage.MinimumWidthRequest; _contentBounds.Y = newY; var complete = Math.Min(1, (Height - (_contentBounds.Y + minHeight)) / Height); // Debug.WriteLine ("complete {0} newY {1} h{2}", complete, newY, Height); var inverseCompletion = 1 - complete; _contentBounds.X = (Width - minWidth) * inverseCompletion; _contentBounds.Width = (minWidth) + ((Width - minWidth) * complete); _contentBounds.Height = Math.Max(minHeight, (Height + minHeight) * complete); PageContainer.Layout(_contentBounds); } break; case GestureRecognizerState.Cancelled: case GestureRecognizerState.Ended: case GestureRecognizerState.Failed: var isShowing = _contentBounds.Y < 200; ToggleShowing(isShowing, true); break; default: break; } }