/// <summary> /// Layout all children /// </summary> protected override void LayoutChildren(double x, double y, double width, double height) { MeasureHeaders(width, height); LayoutChild(_headerElement, new Rectangle(x, y, width, _headerSize.Request.Height)); LayoutChild(_stickyHeaderElement, new Rectangle(x, y, width, _stickyHeaderSize.Request.Height)); if (_relatedViews == null) { _relatedViews = new RelatedViews(this); } ScrollSource.TryGetNavigationBarProperties(_relatedViews.ContentPage, _relatedViews.NavigationPage, out double navigationBarHeight, out double navigationBarY, out bool isNavigationBarFloating, out bool isNavigationBarScrollable); // Update headers translationY based on previous scroll UpdateHeadersTranslationY(_scrollY, navigationBarHeight, navigationBarY, isNavigationBarFloating, isNavigationBarScrollable); bool isHeaderLayoutInScrollViewer = VisualTreeHelper.GetParent <ScrollView>(this, typeof(NavigationPage)) != null; if (isHeaderLayoutInScrollViewer) { double heightToAdd = 0; if (_relatedViews.ContentPage != null && _relatedViews.NavigationPage != null && isNavigationBarFloating == false && isNavigationBarScrollable == true) { heightToAdd = navigationBarHeight; } LayoutChild(_contentElement, new Rectangle(x, y + _headerSize.Request.Height + _stickyHeaderSize.Request.Height + heightToAdd, width, height)); } else { LayoutChild(_contentElement, new Rectangle(x, RootPage.Instance.SafeAreaInsest.Top, width, height)); } }
/// <summary> /// Add page content root element attached property list which contains all scroll hosts /// </summary> private static void OnIsEnabledChanged(BindableObject bindable, object oldValue, object newValue) { if ((bool)newValue == true) { View source = bindable as View; RelatedViews relatedViews = new RelatedViews(source); double oldScrollY = 0; // Size changed EventHandler sizeChangedEventHandler = null; sizeChangedEventHandler = (object sender, EventArgs e) => { UpdateScrollSourcePadding(relatedViews.HeaderLayout, relatedViews.ContentPage, relatedViews.NavigationPage, source); }; source.SizeChanged += sizeChangedEventHandler; if (bindable is ScrollView scrollView) { if (Device.RuntimePlatform == Device.UWP) { scrollView.Effects.Add(new ScrollEffect()); } // Scrolled EventHandler <ScrolledEventArgs> scrollEventHandler = null; scrollEventHandler = (object sender, ScrolledEventArgs e) => { HandleScrolling(relatedViews.HeaderLayout, relatedViews.ContentPage, relatedViews.NavigationPage, oldScrollY, e.ScrollY); oldScrollY = e.ScrollY; }; scrollView.Scrolled += scrollEventHandler; } else if (bindable is CollectionView collectionView) { // Scrolled EventHandler <ItemsViewScrolledEventArgs> scrollEventHandler = null; scrollEventHandler = (object sender, ItemsViewScrolledEventArgs e) => { HandleScrolling(relatedViews.HeaderLayout, relatedViews.ContentPage, relatedViews.NavigationPage, oldScrollY, e.VerticalOffset); oldScrollY = e.VerticalOffset; }; collectionView.Scrolled += scrollEventHandler; } } else { // TODO } }
private void OnTabViewPanChanged(object sender, PanChangedArgs args) { if (sender is CarouselView carouselView && carouselView.ItemsLayout is CarouselLayout carouselLayout) { if (_relatedViews == null) { _relatedViews = new RelatedViews(this); } foreach (View child in carouselLayout.Children) { ScrollView scrollView = VisualTreeHelper.FindVisualChildren <ScrollView>(child).FirstOrDefault(); if (scrollView != null && scrollView.ScrollY != _scrollY) { ScrollSource.UpdateScrollViewStart(this, _relatedViews.ContentPage, _relatedViews.NavigationPage, scrollView, _scrollY); } } } }