diff options
author | Samantha Houts <samhouts@users.noreply.github.com> | 2017-06-26 11:11:53 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-06-26 19:11:53 +0100 |
commit | 39dee7a01bf14fa70766e6521790612850a391e7 (patch) | |
tree | df7f717a487fc4a2c42f3d594960950270c144d7 | |
parent | 43b65f34e40170c5d1344513356fce2a5ff7b4af (diff) | |
download | xamarin-forms-39dee7a01bf14fa70766e6521790612850a391e7.tar.gz xamarin-forms-39dee7a01bf14fa70766e6521790612850a391e7.tar.bz2 xamarin-forms-39dee7a01bf14fa70766e6521790612850a391e7.zip |
[Android] Dispose check before setting properties on Button (#1013)
-rw-r--r-- | Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs index 11f669e9..888026f1 100644 --- a/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs @@ -21,9 +21,9 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers Typeface _defaultTypeface; int _imageHeight = -1; bool _isDisposed; - bool _inputTransparent; - readonly Lazy<TextColorSwitcher> _textColorSwitcher; - readonly AutomationPropertiesProvider _automationPropertiesProvider; + bool _inputTransparent; + readonly Lazy<TextColorSwitcher> _textColorSwitcher; + readonly AutomationPropertiesProvider _automationPropertiesProvider; readonly EffectControlProvider _effectControlProvider; VisualElementTracker _tracker; ButtonBackgroundTracker _backgroundTracker; @@ -33,9 +33,9 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers public ButtonRenderer() : base(Forms.Context) { - _automationPropertiesProvider = new AutomationPropertiesProvider(this); + _automationPropertiesProvider = new AutomationPropertiesProvider(this); _effectControlProvider = new EffectControlProvider(this); - _textColorSwitcher = new Lazy<TextColorSwitcher>(() => new TextColorSwitcher(TextColors)); + _textColorSwitcher = new Lazy<TextColorSwitcher>(() => new TextColorSwitcher(TextColors)); Initialize(); } @@ -145,7 +145,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers SendVisualElementInitialized(element, this); EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); - + Performance.Stop(); } @@ -185,7 +185,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers _tracker?.Dispose(); _backgroundTracker?.Dispose(); - + if (Element != null) { Element.PropertyChanged -= OnElementPropertyChanged; @@ -195,15 +195,15 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers base.Dispose(disposing); } - public override bool OnTouchEvent(MotionEvent e) - { - if (!Enabled || (_inputTransparent && Enabled)) - return false; + public override bool OnTouchEvent(MotionEvent e) + { + if (!Enabled || (_inputTransparent && Enabled)) + return false; - return base.OnTouchEvent(e); - } + return base.OnTouchEvent(e); + } - protected virtual Size MinimumSize() + protected virtual Size MinimumSize() { return new Size(); } @@ -267,7 +267,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers protected override void OnLayout(bool changed, int l, int t, int r, int b) { - if (Element == null) + if (Element == null || _isDisposed) { return; } @@ -315,12 +315,12 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers AddOnAttachStateChangeListener(this); OnFocusChangeListener = this; - Tag = this; - } + Tag = this; + } void UpdateBitmap() { - if (Element == null) + if (Element == null || _isDisposed) { return; } @@ -381,7 +381,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers void UpdateFont() { - if (Element == null) + if (Element == null || _isDisposed) { return; } @@ -413,17 +413,27 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers void UpdateIsEnabled() { + if (Element == null || _isDisposed) + { + return; + } + Enabled = Element.IsEnabled; } - void UpdateInputTransparent() - { - _inputTransparent = Element.InputTransparent; - } + void UpdateInputTransparent() + { + if (Element == null || _isDisposed) + { + return; + } + + _inputTransparent = Element.InputTransparent; + } - void UpdateText() + void UpdateText() { - if (Element == null) + if (Element == null || _isDisposed) { return; } @@ -440,7 +450,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers void UpdateTextColor() { - if (Element == null) + if (Element == null || _isDisposed) { return; } @@ -450,7 +460,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers void UpdateDrawable() { - _backgroundTracker.UpdateDrawable(); + _backgroundTracker?.UpdateDrawable(); } } |