Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[Tizen] Fix several CollectionView issue on Tizen (#13661)
Browse files Browse the repository at this point in the history
* Fix CollectionView.Scrolled event

* Fire Scolled event on first items layouting

* Fix CollectionView layouting issue with MeasureFirstItem

* Create Label for CollectionView string Header

* Reset ScrollCanvas size when Item measure was updated

Co-authored-by: sung-su.kim <sung-su.kim@samsung.com>
  • Loading branch information
myroot and sung-su committed Feb 8, 2021
1 parent 3b750d4 commit 7e8d112
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class CollectionView : EBox, ICollectionViewController, IRotaryInteractio
EvasObject _headerView;
EvasObject _footerView;
SmartEvent _scrollAnimationStop;
SmartEvent _scrollAnimationStart;
bool _isScrollAnimationStarted;

public event EventHandler<ItemsViewScrolledEventArgs> Scrolled;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -594,6 +605,7 @@ void OnLayout()
Scroller.HorizontalStepSize = _layoutManager.GetScrollBlockSize();
Scroller.VerticalStepSize = _layoutManager.GetScrollBlockSize();
UpdateSnapPointsType(SnapPointsType);
Device.BeginInvokeOnMainThread(SendScrolledEvent);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public void LayoutItems(ERect bound, bool force)
{
return;
}

_isLayouting = true;
_last = bound;

Expand Down Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 7e8d112

Please sign in to comment.