summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-04-05 14:11:11 -0700
committerkingces95 <kingces95@users.noreply.github.com>2016-04-05 14:11:11 -0700
commit14e22d8f6c09d51c4ce5d2856d1e910f7d0ff7f2 (patch)
treeb77086ae50ec0988d1a76ac4602866bd46cfa50f /Xamarin.Forms.Platform.Android
parent22e4b3bd6d40ffc3d29a5a072ebb0ae7f8f7783a (diff)
downloadxamarin-forms-14e22d8f6c09d51c4ce5d2856d1e910f7d0ff7f2.tar.gz
xamarin-forms-14e22d8f6c09d51c4ce5d2856d1e910f7d0ff7f2.tar.bz2
xamarin-forms-14e22d8f6c09d51c4ce5d2856d1e910f7d0ff7f2.zip
[A] Make sure carouselView disposes correctly
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs50
1 files changed, 33 insertions, 17 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs
index a98126f9..b44ef3e6 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs
@@ -412,6 +412,7 @@ namespace Xamarin.Forms.Platform.Android
#region Fields
PhysicalLayoutManager _physicalLayout;
int _position;
+ bool _disposed;
#endregion
public CarouselViewRenderer()
@@ -419,11 +420,23 @@ namespace Xamarin.Forms.Platform.Android
AutoPackage = false;
}
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && !_disposed)
+ {
+ _disposed = true;
+ if (Element != null)
+ Element.CollectionChanged -= OnCollectionChanged;
+ }
+
+ base.Dispose(disposing);
+ }
+
#region Private Members
void Initialize()
{
// cache hit? Check if the view page is already created
- RecyclerView recyclerView = base.Control;
+ RecyclerView recyclerView = Control;
if (recyclerView != null)
return;
@@ -488,24 +501,10 @@ namespace Xamarin.Forms.Platform.Android
var adapter = new ItemViewAdapter(this);
adapter.RegisterAdapterDataObserver(new PositionUpdater(this));
recyclerView.SetAdapter(adapter);
-
- // initialize properties
- Element.Position = 0;
-
- // initialize events
- Element.CollectionChanged += OnCollectionChanged;
}
ItemViewAdapter Adapter => (ItemViewAdapter)Control.GetAdapter();
PhysicalLayoutManager LayoutManager => (PhysicalLayoutManager)Control.GetLayoutManager();
- new RecyclerView Control
- {
- get
- {
- Initialize();
- return base.Control;
- }
- }
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
@@ -552,6 +551,7 @@ namespace Xamarin.Forms.Platform.Android
}
}
ICarouselViewController Controller => Element;
+ IVisualElementController VisualElementController => Element;
void OnPositionChanged()
{
Element.Position = _position;
@@ -566,12 +566,28 @@ namespace Xamarin.Forms.Platform.Android
protected override void OnElementChanged(ElementChangedEventArgs<CarouselView> e)
{
+ base.OnElementChanged(e);
+
CarouselView oldElement = e.OldElement;
+ CarouselView newElement = e.NewElement;
if (oldElement != null)
+ {
e.OldElement.CollectionChanged -= OnCollectionChanged;
+ }
- base.OnElementChanged(e);
- Initialize();
+ if (newElement != null)
+ {
+ if (Control == null)
+ {
+ Initialize();
+ }
+
+ // initialize properties
+ VisualElementController.SetValueFromRenderer(CarouselView.PositionProperty, 0);
+
+ // initialize events
+ Element.CollectionChanged += OnCollectionChanged;
+ }
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{