From e6e7b5649be857a7e7d6ecf1e6faf587a0662ff2 Mon Sep 17 00:00:00 2001 From: SangHyeon Jade Lee Date: Wed, 16 Jun 2021 17:47:53 +0900 Subject: [PATCH] [NUI] enable groups regardless of groupHeader (#3199) --- .../Controls/RecyclerView/Layouter/GridLayouter.cs | 38 ++++++++++------------ .../RecyclerView/Layouter/LinearLayouter.cs | 34 +++++++++---------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs index b05488d..e72eb6c 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs @@ -271,6 +271,7 @@ namespace Tizen.NUI.Components float Current = 0.0F; IGroupableItemSource source = colView.InternalItemSource; GroupInfo currentGroup = null; + object currentParent = null; for (int i = 0; i < count; i++) { @@ -284,19 +285,21 @@ namespace Tizen.NUI.Components } else { - //GroupHeader must always exist in group usage. - if (source.IsGroupHeader(i)) + if (source.GetGroupParent(i) != currentParent) { + currentParent = source.GetGroupParent(i); + float currentSize = (source.IsGroupHeader(i)? groupHeaderSize : + (source.IsGroupFooter(i)? groupFooterSize: StepCandidate)); currentGroup = new GroupInfo() { GroupParent = source.GetGroupParent(i), StartIndex = i, Count = 1, - GroupSize = groupHeaderSize, + GroupSize = currentSize, GroupPosition = Current }; groups.Add(currentGroup); - Current += groupHeaderSize; + Current += currentSize; } //optional else if (source.IsGroupFooter(i)) @@ -309,7 +312,7 @@ namespace Tizen.NUI.Components else { currentGroup.Count++; - int index = i - currentGroup.StartIndex - 1; // groupHeader must always exist. + int index = i - currentGroup.StartIndex - ((colView.GroupHeaderTemplate != null)? 1: 0); if ((index % spanSize) == 0) { currentGroup.GroupSize += StepCandidate; @@ -650,7 +653,7 @@ namespace Tizen.NUI.Components Initialize(colView); } - float currentSize = 0; + float currentSize = StepCandidate; // Will be null if not a group. IGroupableItemSource gSource = source as IGroupableItemSource; @@ -669,16 +672,9 @@ namespace Tizen.NUI.Components object groupParent = gSource.GetGroupParent(startIndex); int parentIndex = gSource.GetPosition(groupParent); if (gSource.HasHeader) parentIndex--; - int groupStartIndex = 0; - if (gSource.IsGroupHeader(startIndex)) - { - groupStartIndex = startIndex; - } - else - { - //exception case! - throw new Exception("Inserted wrong groups!"); - } + + // We guess here that range inserted from GroupStartIndex. + int groupStartIndex = startIndex; for (int current = startIndex; current - startIndex < count; current++) { @@ -687,14 +683,16 @@ namespace Tizen.NUI.Components if (groupStartIndex == current) { //create new groupInfo! + currentSize = (gSource.IsGroupHeader(current)? groupHeaderSize : + (gSource.IsGroupFooter(current)? groupFooterSize: currentSize)); groupInfo = new GroupInfo() { GroupParent = groupParent, StartIndex = current, Count = 1, - GroupSize = groupHeaderSize, + GroupSize = StepCandidate, }; - currentSize += groupHeaderSize; + currentSize += StepCandidate; } else @@ -717,7 +715,7 @@ namespace Tizen.NUI.Components } else { - int index = current - groupInfo.StartIndex - 1; // groupHeader must always exist. + int index = current - groupStartIndex - ((colView.GroupHeaderTemplate != null)? 1: 0); if ((index % spanSize) == 0) { groupInfo.GroupSize += StepCandidate; @@ -1439,7 +1437,7 @@ namespace Tizen.NUI.Components } else { - int pureIndex = index - myGroup.StartIndex - 1; + int pureIndex = index - myGroup.StartIndex - ((colView.GroupHeaderTemplate != null)? 1: 0); int division = pureIndex / spanSize; int remainder = pureIndex % spanSize; if (division < 0) division = 0; diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs index 7b4344d..a6a6ffb 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs @@ -253,6 +253,7 @@ namespace Tizen.NUI.Components float Current = IsHorizontal? Padding.Start : Padding.Top; IGroupableItemSource source = colView.InternalItemSource; GroupInfo currentGroup = null; + object currentParent = null; for (int i = 0; i < count; i++) { if (colView.SizingStrategy == ItemSizingStrategy.MeasureAll) @@ -269,12 +270,12 @@ namespace Tizen.NUI.Components } if (isGrouped) { - if (i == 0 && hasHeader) + if (source.IsHeader(i)) { //ItemPosition.Add(Current); Current += headerSize; } - else if (i == count - 1 && hasFooter) + else if (source.IsFooter(i)) { //ItemPosition.Add(Current); Current += footerSize; @@ -282,22 +283,26 @@ namespace Tizen.NUI.Components else { //GroupHeader must always exist in group usage. - if (source.IsGroupHeader(i)) + //if (source.IsGroupHeader(i)) + if (source.GetGroupParent(i) != currentParent) { + currentParent = source.GetGroupParent(i); + float currentSize = (source.IsGroupHeader(i)? groupHeaderSize : + (source.IsGroupFooter(i)? groupFooterSize: StepCandidate)); currentGroup = new GroupInfo() { - GroupParent = source.GetGroupParent(i), + GroupParent = currentParent, //hasHeader = true, //hasFooter = false, StartIndex = i, Count = 1, - GroupSize = groupHeaderSize, + GroupSize = currentSize, GroupPosition = Current }; if (colView.SizingStrategy == ItemSizingStrategy.MeasureAll) currentGroup.ItemPosition.Add(0); groups.Add(currentGroup); - Current += groupHeaderSize; + if (source.IsGroupHeader(i)) Current += currentSize; } //optional else if (source.IsGroupFooter(i)) @@ -729,16 +734,9 @@ namespace Tizen.NUI.Components object groupParent = gSource.GetGroupParent(startIndex); int parentIndex = gSource.GetPosition(groupParent); if (gSource.HasHeader) parentIndex--; - int groupStartIndex = 0; - if (gSource.IsGroupHeader(startIndex)) - { - groupStartIndex = startIndex; - } - else - { - //exception case! - throw new Exception("Inserted wrong groups!"); - } + + // We guess here that range inserted from GroupStartIndex. + int groupStartIndex = startIndex; for (int current = startIndex; current - startIndex < count; current++) { @@ -746,13 +744,15 @@ namespace Tizen.NUI.Components // if group parent, add new gorupinfo if (groupStartIndex == current) { + currentSize = (gSource.IsGroupHeader(current)? groupHeaderSize : + (gSource.IsGroupFooter(current)? groupFooterSize: currentSize)); //create new groupInfo! groupInfo = new GroupInfo() { GroupParent = groupParent, StartIndex = current, Count = 1, - GroupSize = groupHeaderSize, + GroupSize = currentSize, }; } -- 2.7.4