summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorSamantha Houts <samhouts@users.noreply.github.com>2017-08-15 15:50:59 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-08-15 15:50:59 (GMT)
commit6b9730ee2b09c429c4b7dbc1b2c450938992268c (patch)
tree7c015de0e67977402b84deac23ef9dccf4941c54 /Xamarin.Forms.Platform.iOS
parent565973a42fc2b6a86dd50fbf2bf6d843b3c6f5e9 (diff)
downloadxamarin-forms-6b9730ee2b09c429c4b7dbc1b2c450938992268c.zip
xamarin-forms-6b9730ee2b09c429c4b7dbc1b2c450938992268c.tar.gz
xamarin-forms-6b9730ee2b09c429c4b7dbc1b2c450938992268c.tar.bz2
[iOS] Prevent ListView HasUnevenRows crash when template w/container Element is swapped (#1095)
* Add repro for 58645 * [iOS] Check for null before clearing element renderer * [iOS] Remove unnecessary code renderer.SetElement(null); == descendant.ClearValue(Platform.RendererProperty); * [iOS] Clarify comment, use preferred method of clearing renderer from Element * How about we make the test work? Sounds like a good idea to me.
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/RendererPool.cs4
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs10
-rw-r--r--Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs4
3 files changed, 7 insertions, 11 deletions
diff --git a/Xamarin.Forms.Platform.iOS/RendererPool.cs b/Xamarin.Forms.Platform.iOS/RendererPool.cs
index 7c7e445..563201f 100644
--- a/Xamarin.Forms.Platform.iOS/RendererPool.cs
+++ b/Xamarin.Forms.Platform.iOS/RendererPool.cs
@@ -91,7 +91,9 @@ namespace Xamarin.Forms.Platform.MacOS
{
PushRenderer(childRenderer);
- if (ReferenceEquals(childRenderer, Platform.GetRenderer(childRenderer.Element)))
+ // The ListView CalculateHeightForCell method can create renderers and dispose its child renderers before this is called.
+ // Thus, it is possible that this work is already completed.
+ if (childRenderer.Element != null && ReferenceEquals(childRenderer, Platform.GetRenderer(childRenderer.Element)))
childRenderer.Element.ClearValue(Platform.RendererProperty);
}
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
index 6f10cf1..7fd68cc 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
@@ -739,14 +739,8 @@ namespace Xamarin.Forms.Platform.iOS
// Clear renderer from descendent; this will not happen in Dispose as normal because we need to
// unhook the Element from the renderer before disposing it.
descendant.ClearValue(Platform.RendererProperty);
-
- if (renderer != null)
- {
- // Unhook Element (descendant) from renderer before Disposing so we don't set the Element to null
- renderer.SetElement(null);
- renderer.Dispose();
- renderer = null;
- }
+ renderer?.Dispose();
+ renderer = null;
}
// Let the EstimatedHeight method know to use this value.
diff --git a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
index ee16328..5eb29d0 100644
--- a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
@@ -251,11 +251,11 @@ namespace Xamarin.Forms.Platform.MacOS
_packager = null;
}
- // The ListView can create renderers and unhook them from the Element before Dispose is called.
+ // The ListView can create renderers and unhook them from the Element before Dispose is called in CalculateHeightForCell.
// Thus, it is possible that this work is already completed.
if (Element != null)
{
- Platform.SetRenderer(Element, null);
+ Element.ClearValue(Platform.RendererProperty);
SetElement(null);
}
}