From 9494ed5006040355edd41a5fa392fbc397f94d95 Mon Sep 17 00:00:00 2001 From: Matthew Richardson Date: Tue, 15 Jan 2019 09:57:51 +0000 Subject: [PATCH] Null/disposed check for spannableString to fix ObjectDisposedException. (#4878) Fixes #4864 --- .../Extensions/TextViewExtensions.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Xamarin.Forms.Platform.Android/Extensions/TextViewExtensions.cs b/Xamarin.Forms.Platform.Android/Extensions/TextViewExtensions.cs index a22d3cb..e3a7096 100644 --- a/Xamarin.Forms.Platform.Android/Extensions/TextViewExtensions.cs +++ b/Xamarin.Forms.Platform.Android/Extensions/TextViewExtensions.cs @@ -74,18 +74,18 @@ namespace Xamarin.Forms.Platform.Android public static void RecalculateSpanPositions(this TextView textView, Label element, SpannableString spannableString, SizeRequest finalSize) { - if (element?.FormattedText?.Spans == null - || element.FormattedText.Spans.Count == 0) + var layout = textView.Layout; + if (layout == null) return; - var labelWidth = finalSize.Request.Width; - - if (labelWidth <= 0 || finalSize.Request.Height <= 0) + if (element?.FormattedText?.Spans == null || element.FormattedText.Spans.Count == 0) return; - var layout = textView.Layout; + if (spannableString == null || spannableString.IsDisposed()) + return; - if (layout == null) + var labelWidth = finalSize.Request.Width; + if (labelWidth <= 0 || finalSize.Request.Height <= 0) return; var text = spannableString.ToString(); -- 2.7.4