Skip to content

Commit

Permalink
[NUI] Fix Linear Layouter crash and update issue
Browse files Browse the repository at this point in the history
1. Linear Layouter get crashed when group has no children.
2. Linear, Grid Layouter update is not working well because delayed
update timer is not started.
3. remmove spaces.
  • Loading branch information
everLEEst committed Oct 14, 2022
1 parent e69bcd2 commit e78a0fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public override void Initialize(RecyclerView view)
width + itemMargin.Start + itemMargin.End:
height + itemMargin.Top + itemMargin.Bottom;
groupFooterMargin = new Extents(itemMargin);

colView.UnrealizeItem(groupFooter);
}
}
Expand Down Expand Up @@ -378,7 +378,7 @@ public override void RequestLayout(float scrollPosition, bool force = false)

//Console.WriteLine("[NUI] itemsView [{0},{1}] [{2},{3}]", colView.Size.Width, colView.Size.Height, colView.ContentContainer.Size.Width, colView.ContentContainer.Size.Height);

// 1. Set First/Last Visible Item Index.
// 1. Set First/Last Visible Item Index.
(int start, int end) = FindVisibleItems(visibleArea);
FirstVisible = start;
LastVisible = end;
Expand Down Expand Up @@ -889,7 +889,7 @@ public override void NotifyItemRemoved(IItemSource source, int startIndex)
{
currentSize = StepCandidate;
}

}

ScrollContentSize -= currentSize;
Expand Down Expand Up @@ -1053,7 +1053,7 @@ public override void NotifyItemMoved(IItemSource source, int fromPosition, int t
float offset = 0F;
(topInScreenIndex, offset) = FindTopItemInScreen();
*/

// Move can only happen in it's own groups.
// so there will be no changes in position, startIndex in ohter groups.
// check visible item and update indexs.
Expand Down Expand Up @@ -1155,7 +1155,7 @@ public override void NotifyItemRangeMoved(IItemSource source, int fromPosition,

int startGroup = (diff > 0? fromParentIndex: toParentIndex);
int endGroup = (diff > 0? toParentIndex: fromParentIndex);

for (int i = startGroup; i <= endGroup; i++)
{
if (i == toParentIndex) continue;
Expand Down Expand Up @@ -1501,7 +1501,7 @@ internal override (float X, float Y) GetItemPosition(int index)
}

internal override (float Width, float Height) GetItemSize(int index)
{
{
return (sizeCandidate.Width - CandidateMargin.Start - CandidateMargin.End,
sizeCandidate.Height - CandidateMargin.Top - CandidateMargin.Bottom);
}
Expand All @@ -1519,6 +1519,7 @@ private void DelayedRequestLayout(float scrollPosition , bool force = true)
RequestLayout(scrollPosition, force);
return false;
});
requestLayoutTimer.Start();
}

private RecyclerViewItem GetVisibleItem(int index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public override void Initialize(RecyclerView view)
groupFooterSize = IsHorizontal?
width + itemMargin.Start + itemMargin.End:
height + itemMargin.Top + itemMargin.Bottom;
groupFooterMargin = new Extents(itemMargin);
groupFooterMargin = new Extents(itemMargin);
colView.UnrealizeItem(groupFooter);
}
}
Expand All @@ -202,12 +202,14 @@ public override void Initialize(RecyclerView view)
else isGrouped = false;

bool failed = false;

//Final Check of FirstIndex
while (colView.InternalItemSource.IsHeader(firstIndex) ||
colView.InternalItemSource.IsGroupHeader(firstIndex) ||
colView.InternalItemSource.IsGroupFooter(firstIndex))
{
if (colView.InternalItemSource.IsFooter(firstIndex))
if (colView.InternalItemSource.IsFooter(firstIndex)
|| ((colView.InternalItemSource.Count - 1) <= firstIndex))
{
StepCandidate = 0F;
failed = true;
Expand Down Expand Up @@ -245,7 +247,7 @@ public override void Initialize(RecyclerView view)
StepCandidate = IsHorizontal?
width + itemMargin.Start + itemMargin.End:
height + itemMargin.Top + itemMargin.Bottom;
CandidateMargin = new Extents(itemMargin);
CandidateMargin = new Extents(itemMargin);
if (StepCandidate == 0) StepCandidate = 1; //????

colView.UnrealizeItem(sizeDeligate);
Expand Down Expand Up @@ -388,7 +390,7 @@ public override void RequestLayout(float scrollPosition, bool force = false)
PrevScrollPosition + (IsHorizontal? colView.Size.Width : colView.Size.Height)
);

// 1. Set First/Last Visible Item Index.
// 1. Set First/Last Visible Item Index.
(int start, int end) = FindVisibleItems(visibleArea);
FirstVisible = start;
LastVisible = end;
Expand Down Expand Up @@ -571,7 +573,7 @@ public override void NotifyItemInserted(IItemSource source, int startIndex)
float offset = 0F;
(topInScreenIndex, offset) = FindTopItemInScreen();
*/

// 1. Handle MeasureAll
/*
if (colView.SizingStrategy == ItemSizingStrategy.MeasureAll)
Expand Down Expand Up @@ -1133,7 +1135,7 @@ public override void NotifyItemMoved(IItemSource source, int fromPosition, int t
//Need To Implement
}
*/

// Move can only happen in it's own groups.
// so there will be no changes in position, startIndex in ohter groups.
// check visible item and update indexs.
Expand Down Expand Up @@ -1235,7 +1237,7 @@ public override void NotifyItemRangeMoved(IItemSource source, int fromPosition,

int startGroup = (diff > 0? fromParentIndex: toParentIndex);
int endGroup = (diff > 0? toParentIndex: fromParentIndex);

for (int i = startGroup; i <= endGroup; i++)
{
if (i == toParentIndex) continue;
Expand Down Expand Up @@ -1594,7 +1596,7 @@ internal override (float Width, float Height) GetItemSize(int index)
- CandidateMargin.Start - CandidateMargin.End,
(IsHorizontal? (int)colView.Size.Height - Padding.Top - Padding.Bottom: (int)StepCandidate)
- CandidateMargin.Top - CandidateMargin.Bottom);
}
}
}

private void DelayedRequestLayout(float scrollPosition , bool force = true)
Expand All @@ -1611,6 +1613,7 @@ private void DelayedRequestLayout(float scrollPosition , bool force = true)
RequestLayout(scrollPosition, force);
return false;
});
requestLayoutTimer.Start();
}

/*
Expand Down Expand Up @@ -1653,7 +1656,7 @@ private float GetItemStepSize(int index)
return groupFooterSize;
else
return StepCandidate;
}
}
}

private void UpdatePosition(int index)
Expand Down

0 comments on commit e78a0fd

Please sign in to comment.