Skip to content

Commit

Permalink
[NUI] Fix some SVACE issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhao02 authored and dongsug-song committed Nov 20, 2023
1 parent df9fbfc commit a0a293b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void HandleCollectionChange(NotifyCollectionChangedEventArgs args)

void Move(NotifyCollectionChangedEventArgs args)
{
var count = args.OldItems.Count;
int count = args.OldItems?.Count ?? 0;

for (int n = 0; n < count; n++)
{
Expand All @@ -124,7 +124,8 @@ void Move(NotifyCollectionChangedEventArgs args)

void Remove(NotifyCollectionChangedEventArgs args)
{
var startIndex = args.OldStartingIndex + args.OldItems.Count - 1;
int count=args.OldItems?.Count ?? 0;
int startIndex = args.OldStartingIndex + count - 1;
for (int n = startIndex; n >= args.OldStartingIndex; n--)
{
RemoveAt(n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void Remove(NotifyCollectionChangedEventArgs args)
}

// If we have a start index, we can be more clever about removing the group(s) (and get the nifty animations)
var groupCount = args.OldItems.Count;
int groupCount = args.OldItems?.Count ?? 0;

var absolutePosition = GetAbsolutePosition(groups[groupIndex], 0);

Expand All @@ -360,18 +360,24 @@ void Remove(NotifyCollectionChangedEventArgs args)

void Replace(NotifyCollectionChangedEventArgs args)
{
var groupCount = args.NewItems.Count;

if (groupCount != args.OldItems.Count)
var newItems = args.NewItems;
var oldItems = args.OldItems;
if(newItems == null || oldItems == null)
{
return;
}
int groupCount = newItems.Count;
int oldCount = oldItems.Count;
if (groupCount != oldCount)
{
// The original and replacement sets are of unequal size; this means that most everything currently in
// view will have to be updated. So just reload the whole thing.
Reload();
return;
}

var newStartIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : groupSource.IndexOf(args.NewItems[0]);
var oldStartIndex = args.OldStartingIndex > -1 ? args.OldStartingIndex : groupSource.IndexOf(args.OldItems[0]);
var newStartIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : groupSource.IndexOf(newItems[0]);
var oldStartIndex = args.OldStartingIndex > -1 ? args.OldStartingIndex : groupSource.IndexOf(oldItems[0]);

var newItemCount = CountItemsInGroups(newStartIndex, groupCount);
var oldItemCount = CountItemsInGroups(oldStartIndex, groupCount);
Expand Down Expand Up @@ -402,7 +408,7 @@ void Replace(NotifyCollectionChangedEventArgs args)

void Move(NotifyCollectionChangedEventArgs args)
{
var itemCount = CountItemsInGroups(args.OldStartingIndex, args.OldItems.Count);
var itemCount = CountItemsInGroups(args.OldStartingIndex, args.OldItems?.Count ?? 0);
var start = Math.Min(args.OldStartingIndex, args.NewStartingIndex);
var end = Math.Max(args.OldStartingIndex, args.NewStartingIndex) + itemCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void Remove(NotifyCollectionChangedEventArgs args)
startIndex = AdjustPositionForHeader(startIndex);

// If we have a start index, we can be more clever about removing the item(s) (and get the nifty animations)
var count = args.OldItems.Count;
int count = args.OldItems?.Count ?? 0;

if (count == 1)
{
Expand All @@ -200,11 +200,18 @@ void Remove(NotifyCollectionChangedEventArgs args)

void Replace(NotifyCollectionChangedEventArgs args)
{
var newItems = args.NewItems;
var oldItems = args.OldItems;
if (newItems == null || oldItems == null)
{
return;
}
var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : IndexOf(args.NewItems[0]);
startIndex = AdjustPositionForHeader(startIndex);
var newCount = args.NewItems.Count;

if (newCount == args.OldItems.Count)

int newCount = newItems.Count;
int oldCount = oldItems.Count;
if (newCount == oldCount)
{
// We are replacing one set of items with a set of equal size; we can do a simple item or range
// notification to the adapter
Expand Down

0 comments on commit a0a293b

Please sign in to comment.