summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
authorRui Marinho <me@ruimarinho.net>2016-04-05 08:46:22 +0100
committerJason Smith <jason.smith@xamarin.com>2016-04-05 00:46:22 -0700
commit244ee01cfa3405c01746d9419e9955e07ae9df2e (patch)
tree0dd59f00c19090437a962fc31c58bc40dd2fe8d9 /Xamarin.Forms.Core
parenta6964ab96f139aa8c6c1eea9b62dfebb6962c11c (diff)
downloadxamarin-forms-244ee01cfa3405c01746d9419e9955e07ae9df2e.tar.gz
xamarin-forms-244ee01cfa3405c01746d9419e9955e07ae9df2e.tar.bz2
xamarin-forms-244ee01cfa3405c01746d9419e9955e07ae9df2e.zip
[iOS] Fix WeakNotifyCollectionChanged on CarouselView
Make some changes on WeakNotifyCollectionChanged to make it work ok in IOS, following the ListProxy approach.
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r--Xamarin.Forms.Core/ItemsViewSimple.cs31
1 files changed, 17 insertions, 14 deletions
diff --git a/Xamarin.Forms.Core/ItemsViewSimple.cs b/Xamarin.Forms.Core/ItemsViewSimple.cs
index fd631838..34b77264 100644
--- a/Xamarin.Forms.Core/ItemsViewSimple.cs
+++ b/Xamarin.Forms.Core/ItemsViewSimple.cs
@@ -73,7 +73,7 @@ namespace Xamarin.Forms
var dynamicItemSource = _itemSource as INotifyCollectionChanged;
if (dynamicItemSource != null)
{
- new WeakNotifyCollectionChanged(dynamicItemSource, OnCollectionChange);
+ new WeakNotifyCollectionChanged(this, dynamicItemSource);
}
}
@@ -82,34 +82,37 @@ namespace Xamarin.Forms
internal event NotifyCollectionChangedEventHandler CollectionChanged;
- void OnCollectionChange(object sender, NotifyCollectionChangedEventArgs e)
+ internal void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
CollectionChanged?.Invoke(sender, e);
}
sealed class WeakNotifyCollectionChanged
{
- readonly INotifyCollectionChanged _source;
- // prevent the itemSource from keeping the itemsView alive
- readonly WeakReference<NotifyCollectionChangedEventHandler> _weakTarget;
+ readonly WeakReference<INotifyCollectionChanged> _weakCollection;
+ readonly WeakReference<ItemsView> _weakSource;
- public WeakNotifyCollectionChanged(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler target)
+ public WeakNotifyCollectionChanged(ItemsView source, INotifyCollectionChanged incc)
{
- _weakTarget = new WeakReference<NotifyCollectionChangedEventHandler>(target);
- _source = source;
- _source.CollectionChanged += OnCollectionChanged;
+ incc.CollectionChanged += OnCollectionChanged;
+
+ _weakSource = new WeakReference<ItemsView>(source);
+ _weakCollection = new WeakReference<INotifyCollectionChanged>(incc);
}
- public void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
+ void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
- NotifyCollectionChangedEventHandler weakTarget;
- if (!_weakTarget.TryGetTarget(out weakTarget))
+ ItemsView source;
+ if (!_weakSource.TryGetTarget(out source))
{
- _source.CollectionChanged -= OnCollectionChanged;
+ INotifyCollectionChanged collection;
+ if (_weakCollection.TryGetTarget(out collection))
+ collection.CollectionChanged -= OnCollectionChanged;
+
return;
}
- weakTarget(sender, e);
+ source.OnCollectionChanged(sender, e);
}
}