Skip to content

Commit fa2e92e

Browse files
committed
Fix unbind issue.
1 parent e5129a1 commit fa2e92e

File tree

1 file changed

+15
-2
lines changed
  • src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/UITK/BindableUIElements

1 file changed

+15
-2
lines changed

src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/UITK/BindableUIElements/BindableListView.T.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public virtual void Dispose()
4040

4141
public virtual void SetBindingContext(IBindingContext context, IObjectProvider objectProvider)
4242
{
43+
if (string.IsNullOrWhiteSpace(BindingItemsSourcePath))
44+
{
45+
return;
46+
}
47+
4348
_itemsSourceBindingData ??= BindingItemsSourcePath.ToPropertyBindingData();
4449
_itemTemplate ??= objectProvider.GetCollectionItemTemplate<TItemBindingContext, VisualTreeAsset>();
4550

@@ -95,14 +100,22 @@ protected virtual void UnbindItem(VisualElement item, int index, [CanBeNull] TIt
95100
item.ResetChildsBindingContext(objectProvider);
96101
}
97102

98-
private void OnItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
103+
protected virtual void OnItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
99104
{
100-
RefreshItems(); // TODO: Do not refresh all items.
105+
if (e.Action == NotifyCollectionChangedAction.Remove)
106+
{
107+
Rebuild();
108+
}
109+
else
110+
{
111+
RefreshItems();
112+
}
101113
}
102114

103115
private VisualElement OnMakeItem()
104116
{
105117
var item = MakeItem(_itemTemplate);
118+
106119
_itemAssets.Add(item);
107120

108121
return item;

0 commit comments

Comments
 (0)