From 81b8a9325dfda1d0967d6443e745152315d71769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez=20Ruiz?= Date: Fri, 22 May 2020 14:11:53 +0200 Subject: [PATCH] Fixed scroll animation issue Fixed issue resetting the TabViewItem BindingContext --- src/TabView.Sample/Views/CarouselViewGallery.xaml.cs | 8 ++++---- src/Xamarin.Forms.TabView/CarouselView.cs | 7 ++++--- src/Xamarin.Forms.TabView/TabView.cs | 8 +++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/TabView.Sample/Views/CarouselViewGallery.xaml.cs b/src/TabView.Sample/Views/CarouselViewGallery.xaml.cs index 0605597..4dc8880 100644 --- a/src/TabView.Sample/Views/CarouselViewGallery.xaml.cs +++ b/src/TabView.Sample/Views/CarouselViewGallery.xaml.cs @@ -10,16 +10,16 @@ namespace TabView.Sample.Views InitializeComponent(); } - void OnScrollToZeroClicked(object sender, EventArgs e) + async void OnScrollToZeroClicked(object sender, EventArgs e) { bool isAnimated = IsAnimatedScrollToCheckBox.IsChecked; - CarouselView.ScrollTo(0, isAnimated); + await CarouselView.ScrollToAsync(0, isAnimated); } - void OnScrollToFiveClicked(object sender, EventArgs e) + async void OnScrollToFiveClicked(object sender, EventArgs e) { bool isAnimated = IsAnimatedScrollToCheckBox.IsChecked; - CarouselView.ScrollTo(5, isAnimated); + await CarouselView.ScrollToAsync(5, isAnimated); } } } diff --git a/src/Xamarin.Forms.TabView/CarouselView.cs b/src/Xamarin.Forms.TabView/CarouselView.cs index 1510f92..8a01a6f 100644 --- a/src/Xamarin.Forms.TabView/CarouselView.cs +++ b/src/Xamarin.Forms.TabView/CarouselView.cs @@ -168,7 +168,7 @@ namespace Xamarin.Forms.TabView public event EventHandler PositionChanged; public event EventHandler Scrolled; - public async void ScrollTo(int position, bool animated = true) + public async Task ScrollToAsync(int position, bool animated = true) { if (Position == position) return; @@ -464,7 +464,7 @@ namespace Xamarin.Forms.TabView UpdateViewIndex(_previousView); } } - + void AddOrUpdateCache(int key, View value) { if (_existingViews == null) @@ -501,7 +501,8 @@ namespace Xamarin.Forms.TabView if (view == null) view = (View)ItemTemplate.CreateContent(); - view.BindingContext = context; + if (view.BindingContext == null) + view.BindingContext = context; return view; } diff --git a/src/Xamarin.Forms.TabView/TabView.cs b/src/Xamarin.Forms.TabView/TabView.cs index 2bde653..11eebb6 100644 --- a/src/Xamarin.Forms.TabView/TabView.cs +++ b/src/Xamarin.Forms.TabView/TabView.cs @@ -730,10 +730,12 @@ namespace Xamarin.Forms.TabView return; SelectedIndex = newPosition; - _contentContainer.ScrollTo(SelectedIndex); - Device.BeginInvokeOnMainThread( - async () => await _tabStripContainerScroll.ScrollToAsync(_tabStripContent.Children[position], ScrollToPosition.MakeVisible, false)); + Device.BeginInvokeOnMainThread(async () => + { + await _contentContainer.ScrollToAsync(SelectedIndex); + await _tabStripContainerScroll.ScrollToAsync(_tabStripContent.Children[position], ScrollToPosition.MakeVisible, false); + }); if (TabItems.Count > 0) {