From: Samantha Houts Date: Thu, 11 Apr 2019 00:25:45 +0000 (-0700) Subject: [Android] Null check on Switch TrackDrawable (#5851) X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~378^2^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=618ed187d75ed5b0794ae9933183f10be75b2f14;p=platform%2Fcore%2Fcsapi%2Fxsf.git [Android] Null check on Switch TrackDrawable (#5851) * [Android] Null check on Switch TrackDrawable fixes #5553 * Add a few more checks, dispose Drawable, fix copy/paste error * Couple more for safety's sake --- diff --git a/Xamarin.Forms.Core/Switch.cs b/Xamarin.Forms.Core/Switch.cs index cd1371b..9f31d47 100644 --- a/Xamarin.Forms.Core/Switch.cs +++ b/Xamarin.Forms.Core/Switch.cs @@ -13,7 +13,7 @@ namespace Xamarin.Forms eh(bindable, new ToggledEventArgs((bool)newValue)); }, defaultBindingMode: BindingMode.TwoWay); - public static readonly BindableProperty OnColorProperty = BindableProperty.Create(nameof(OnColor), typeof(Color), typeof(Slider), Color.Default); + public static readonly BindableProperty OnColorProperty = BindableProperty.Create(nameof(OnColor), typeof(Color), typeof(Switch), Color.Default); public Color OnColor { diff --git a/Xamarin.Forms.Platform.Android/AppCompat/SwitchRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/SwitchRenderer.cs index 0b6846d..1d8d64b 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/SwitchRenderer.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/SwitchRenderer.cs @@ -66,7 +66,10 @@ namespace Xamarin.Forms.Platform.Android.AppCompat if (Element != null) Element.Toggled -= HandleToggled; - Control.SetOnCheckedChangeListener(null); + Control?.SetOnCheckedChangeListener(null); + + _defaultTrackDrawable?.Dispose(); + _defaultTrackDrawable = null; } base.Dispose(disposing); @@ -118,12 +121,12 @@ namespace Xamarin.Forms.Platform.Android.AppCompat } else { - Control.TrackDrawable.SetColorFilter(Element.OnColor.ToAndroid(), PorterDuff.Mode.Multiply); + Control.TrackDrawable?.SetColorFilter(Element.OnColor.ToAndroid(), PorterDuff.Mode.Multiply); } } else { - Control.TrackDrawable.ClearColorFilter(); + Control.TrackDrawable?.ClearColorFilter(); } } diff --git a/Xamarin.Forms.Platform.Android/Renderers/SwitchRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SwitchRenderer.cs index fe3cc47..1d5a537 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SwitchRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SwitchRenderer.cs @@ -55,6 +55,9 @@ namespace Xamarin.Forms.Platform.Android Element.Toggled -= HandleToggled; Control.SetOnCheckedChangeListener(null); + + _defaultTrackDrawable.Dispose(); + _defaultTrackDrawable = null; } base.Dispose(disposing); @@ -114,13 +117,13 @@ namespace Xamarin.Forms.Platform.Android { if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) { - Control.TrackDrawable.SetColorFilter(Element.OnColor.ToAndroid(), PorterDuff.Mode.Multiply); + Control.TrackDrawable?.SetColorFilter(Element.OnColor.ToAndroid(), PorterDuff.Mode.Multiply); } } } else { - Control.TrackDrawable.ClearColorFilter(); + Control.TrackDrawable?.ClearColorFilter(); } } }