Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exceptions with live update of multiple FormGroups #77

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Buform/Buform.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
<PackageReference Include="Fedandburk.iOS.Extensions" Version="1.0.8" />
<PackageReference Include="Fedandburk.iOS.Extensions" Version="1.0.9" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
Expand Down
5 changes: 5 additions & 0 deletions Buform/FormGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ protected virtual void ShiftHiddenItems(int index, int shift)
}
}

protected void AddItem(TFormItem item)
{
InsertItem(Count, item);
}

protected override void InsertItem(int index, TFormItem item)
{
ShiftHiddenItems(index, 1);
Expand Down
40 changes: 37 additions & 3 deletions Buform/Groups/List/ListFormGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,43 @@ public ListFormGroup(

protected virtual void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
Reset();
switch (e.Action)
{
case NotifyCollectionChangedAction.Remove:
{
for (var i = 0; i < e.OldItems!.Count; i++)
{
RemoveItem(e.OldStartingIndex);
}

break;
}
case NotifyCollectionChangedAction.Add:
{
var items = e.NewItems!.Cast<TValue>()
.Select((item, index) => (_itemFactory!(item), e.NewStartingIndex + index))
.ToList();

foreach (var (item, index) in items)
{
InsertItem(index, item);
}

break;
}
case NotifyCollectionChangedAction.Reset:
{
Reset();

NotifyPropertyChanged(nameof(Source));
break;
}
case NotifyCollectionChangedAction.Move:
{
MoveItem(e.OldStartingIndex, e.NewStartingIndex);

break;
}
}
}

protected virtual void Reset()
Expand All @@ -106,7 +140,7 @@ protected virtual void Reset()
{
var item = _itemFactory(value);

Add(item);
AddItem(item);
}
}

Expand Down
Loading