diff --git a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs index dbf3d2ccdff..21ef1531377 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs @@ -32,6 +32,8 @@ public class CollectionView : EBox, ICollectionViewController, IRotaryInteractio EvasObject _headerView; EvasObject _footerView; SmartEvent _scrollAnimationStop; + SmartEvent _scrollAnimationStart; + bool _isScrollAnimationStarted; public event EventHandler Scrolled; @@ -43,6 +45,10 @@ public CollectionView(EvasObject parent) : base(parent) Scroller.Show(); PackEnd(Scroller); Scroller.Scrolled += OnScrolled; + + _scrollAnimationStart = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StartScrollAnimation); + _scrollAnimationStart.On += OnScrollStarted; + _scrollAnimationStop = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StopScrollAnimation); _scrollAnimationStop.On += OnScrollStopped; @@ -227,6 +233,11 @@ public void ScrollTo(object item, ScrollToPosition position = ScrollToPosition.M public void ItemMeasureInvalidated(int index) { + // If a first item size was updated, need to reset _itemSize + if (index == 0) + { + _itemSize = new ESize(-1, -1); + } LayoutManager?.ItemMeasureInvalidated(index); } @@ -594,6 +605,7 @@ void OnLayout() Scroller.HorizontalStepSize = _layoutManager.GetScrollBlockSize(); Scroller.VerticalStepSize = _layoutManager.GetScrollBlockSize(); UpdateSnapPointsType(SnapPointsType); + Device.BeginInvokeOnMainThread(SendScrolledEvent); } } @@ -629,7 +641,27 @@ void OnInnerLayout() int _previousHorizontalOffset = 0; int _previousVerticalOffset = 0; + void OnScrollStarted(object sender, EventArgs e) + { + _isScrollAnimationStarted = true; + } + void OnScrollStopped(object sender, EventArgs e) + { + SendScrolledEvent(); + _isScrollAnimationStarted = false; + } + + void OnScrolled(object sender, EventArgs e) + { + _layoutManager.LayoutItems(ViewPort); + if (!_isScrollAnimationStarted) + { + SendScrolledEvent(); + } + } + + void SendScrolledEvent() { var args = new ItemsViewScrolledEventArgs(); args.FirstVisibleItemIndex = _layoutManager.GetVisibleItemIndex(ViewPort.X, ViewPort.Y); @@ -646,11 +678,6 @@ void OnScrollStopped(object sender, EventArgs e) _previousVerticalOffset = ViewPort.Y; } - void OnScrolled(object sender, EventArgs e) - { - _layoutManager.LayoutItems(ViewPort); - } - void UpdateSnapPointsType(SnapPointsType snapPoints) { if (LayoutManager == null) diff --git a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/GridLayoutManager.cs b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/GridLayoutManager.cs index 9e66c5cdfba..e707e2643bb 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/GridLayoutManager.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/GridLayoutManager.cs @@ -178,6 +178,7 @@ public void LayoutItems(ERect bound, bool force) { return; } + _isLayouting = true; _last = bound; @@ -382,14 +383,21 @@ public void ItemSourceUpdated() public void ItemMeasureInvalidated(int index) { - if (_realizedItem.ContainsKey(index)) - { - CollectionView.RequestLayoutItems(); - } if (_hasUnevenRows) { if (_cached.Count > index) _cached[index] = false; + + if (_realizedItem.ContainsKey(index)) + { + CollectionView.RequestLayoutItems(); + } + } + else if (index == 0) // MeasureFirstItem + { + // Reset item size to measure updated size + InitializeMeasureCache(); + CollectionView.RequestLayoutItems(); } } diff --git a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ItemTemplateAdaptor.cs b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ItemTemplateAdaptor.cs index cfbf12294b8..eb7e4ee6e5a 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ItemTemplateAdaptor.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ItemTemplateAdaptor.cs @@ -252,6 +252,10 @@ protected virtual View CreateHeaderView() header = structuredItemsView.HeaderTemplate.CreateContent() as View; header.BindingContext = structuredItemsView.Header; } + else if (structuredItemsView.Header is String str) + { + header = new XLabel { Text = str, }; + } return header; } } @@ -274,6 +278,10 @@ protected virtual View CreateFooterView() footer = structuredItemsView.FooterTemplate.CreateContent() as View; footer.BindingContext = structuredItemsView.Footer; } + else if (structuredItemsView.Footer is String str) + { + footer = new XLabel { Text = str, }; + } return footer; } } diff --git a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/LinearLayoutManager.cs b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/LinearLayoutManager.cs index 246f7847281..82981b0e3dc 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/LinearLayoutManager.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/LinearLayoutManager.cs @@ -322,14 +322,21 @@ public void ItemSourceUpdated() public void ItemMeasureInvalidated(int index) { - if (_realizedItem.ContainsKey(index)) - { - CollectionView.RequestLayoutItems(); - } if (_hasUnevenRows) { if (_cached.Count > index) _cached[index] = false; + + if (_realizedItem.ContainsKey(index)) + { + CollectionView.RequestLayoutItems(); + } + } + else if (index == 0) + { + // Reset item size to measure updated size + InitializeMeasureCache(); + CollectionView.RequestLayoutItems(); } }