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

Commit 7e8d112

Browse files
myrootsung-su
andauthored
[Tizen] Fix several CollectionView issue on Tizen (#13661)
* 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 <[email protected]>
1 parent 3b750d4 commit 7e8d112

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class CollectionView : EBox, ICollectionViewController, IRotaryInteractio
3232
EvasObject _headerView;
3333
EvasObject _footerView;
3434
SmartEvent _scrollAnimationStop;
35+
SmartEvent _scrollAnimationStart;
36+
bool _isScrollAnimationStarted;
3537

3638
public event EventHandler<ItemsViewScrolledEventArgs> Scrolled;
3739

@@ -43,6 +45,10 @@ public CollectionView(EvasObject parent) : base(parent)
4345
Scroller.Show();
4446
PackEnd(Scroller);
4547
Scroller.Scrolled += OnScrolled;
48+
49+
_scrollAnimationStart = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StartScrollAnimation);
50+
_scrollAnimationStart.On += OnScrollStarted;
51+
4652
_scrollAnimationStop = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StopScrollAnimation);
4753
_scrollAnimationStop.On += OnScrollStopped;
4854

@@ -227,6 +233,11 @@ public void ScrollTo(object item, ScrollToPosition position = ScrollToPosition.M
227233

228234
public void ItemMeasureInvalidated(int index)
229235
{
236+
// If a first item size was updated, need to reset _itemSize
237+
if (index == 0)
238+
{
239+
_itemSize = new ESize(-1, -1);
240+
}
230241
LayoutManager?.ItemMeasureInvalidated(index);
231242
}
232243

@@ -594,6 +605,7 @@ void OnLayout()
594605
Scroller.HorizontalStepSize = _layoutManager.GetScrollBlockSize();
595606
Scroller.VerticalStepSize = _layoutManager.GetScrollBlockSize();
596607
UpdateSnapPointsType(SnapPointsType);
608+
Device.BeginInvokeOnMainThread(SendScrolledEvent);
597609
}
598610
}
599611

@@ -629,7 +641,27 @@ void OnInnerLayout()
629641
int _previousHorizontalOffset = 0;
630642
int _previousVerticalOffset = 0;
631643

644+
void OnScrollStarted(object sender, EventArgs e)
645+
{
646+
_isScrollAnimationStarted = true;
647+
}
648+
632649
void OnScrollStopped(object sender, EventArgs e)
650+
{
651+
SendScrolledEvent();
652+
_isScrollAnimationStarted = false;
653+
}
654+
655+
void OnScrolled(object sender, EventArgs e)
656+
{
657+
_layoutManager.LayoutItems(ViewPort);
658+
if (!_isScrollAnimationStarted)
659+
{
660+
SendScrolledEvent();
661+
}
662+
}
663+
664+
void SendScrolledEvent()
633665
{
634666
var args = new ItemsViewScrolledEventArgs();
635667
args.FirstVisibleItemIndex = _layoutManager.GetVisibleItemIndex(ViewPort.X, ViewPort.Y);
@@ -646,11 +678,6 @@ void OnScrollStopped(object sender, EventArgs e)
646678
_previousVerticalOffset = ViewPort.Y;
647679
}
648680

649-
void OnScrolled(object sender, EventArgs e)
650-
{
651-
_layoutManager.LayoutItems(ViewPort);
652-
}
653-
654681
void UpdateSnapPointsType(SnapPointsType snapPoints)
655682
{
656683
if (LayoutManager == null)

Xamarin.Forms.Platform.Tizen/Native/CollectionView/GridLayoutManager.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public void LayoutItems(ERect bound, bool force)
178178
{
179179
return;
180180
}
181+
181182
_isLayouting = true;
182183
_last = bound;
183184

@@ -382,14 +383,21 @@ public void ItemSourceUpdated()
382383

383384
public void ItemMeasureInvalidated(int index)
384385
{
385-
if (_realizedItem.ContainsKey(index))
386-
{
387-
CollectionView.RequestLayoutItems();
388-
}
389386
if (_hasUnevenRows)
390387
{
391388
if (_cached.Count > index)
392389
_cached[index] = false;
390+
391+
if (_realizedItem.ContainsKey(index))
392+
{
393+
CollectionView.RequestLayoutItems();
394+
}
395+
}
396+
else if (index == 0) // MeasureFirstItem
397+
{
398+
// Reset item size to measure updated size
399+
InitializeMeasureCache();
400+
CollectionView.RequestLayoutItems();
393401
}
394402
}
395403

Xamarin.Forms.Platform.Tizen/Native/CollectionView/ItemTemplateAdaptor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ protected virtual View CreateHeaderView()
252252
header = structuredItemsView.HeaderTemplate.CreateContent() as View;
253253
header.BindingContext = structuredItemsView.Header;
254254
}
255+
else if (structuredItemsView.Header is String str)
256+
{
257+
header = new XLabel { Text = str, };
258+
}
255259
return header;
256260
}
257261
}
@@ -274,6 +278,10 @@ protected virtual View CreateFooterView()
274278
footer = structuredItemsView.FooterTemplate.CreateContent() as View;
275279
footer.BindingContext = structuredItemsView.Footer;
276280
}
281+
else if (structuredItemsView.Footer is String str)
282+
{
283+
footer = new XLabel { Text = str, };
284+
}
277285
return footer;
278286
}
279287
}

Xamarin.Forms.Platform.Tizen/Native/CollectionView/LinearLayoutManager.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,21 @@ public void ItemSourceUpdated()
322322

323323
public void ItemMeasureInvalidated(int index)
324324
{
325-
if (_realizedItem.ContainsKey(index))
326-
{
327-
CollectionView.RequestLayoutItems();
328-
}
329325
if (_hasUnevenRows)
330326
{
331327
if (_cached.Count > index)
332328
_cached[index] = false;
329+
330+
if (_realizedItem.ContainsKey(index))
331+
{
332+
CollectionView.RequestLayoutItems();
333+
}
334+
}
335+
else if (index == 0)
336+
{
337+
// Reset item size to measure updated size
338+
InitializeMeasureCache();
339+
CollectionView.RequestLayoutItems();
333340
}
334341
}
335342

0 commit comments

Comments
 (0)