protected override void Dispose(bool disposing) { if (_isDisposed) { return; } _isDisposed = true; if (disposing) { SetOnClickListener(null); SetOnTouchListener(null); RemoveOnAttachStateChangeListener(this); _automationPropertiesProvider?.Dispose(); _tracker?.Dispose(); _backgroundTracker?.Dispose(); _backgroundTracker = null; if (Element != null) { Element.PropertyChanged -= OnElementPropertyChanged; if (Platform.GetRenderer(Element) == this) { Element.ClearValue(Platform.RendererProperty); } } } base.Dispose(disposing); }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement != null) { } if (e.NewElement != null) { if (Control == null) { AppCompatButton button = CreateNativeControl(); button.SetOnClickListener(ButtonClickListener.Instance.Value); button.SetOnTouchListener(ButtonTouchListener.Instance.Value); button.Tag = this; _textColorSwitcher = new TextColorSwitcher(button.TextColors); SetNativeControl(button); button.AddOnAttachStateChangeListener(this); } if (_backgroundTracker == null) { _backgroundTracker = new ButtonBackgroundTracker(Element, Control); } else { _backgroundTracker.Button = e.NewElement; } UpdateAll(); } }
protected override void Dispose(bool disposing) { if (_isDisposed) { return; } _isDisposed = true; if (disposing) { if (Control != null) { Control.SetOnClickListener(null); Control.SetOnTouchListener(null); Control.RemoveOnAttachStateChangeListener(this); Control.Tag = null; _textColorSwitcher = null; } _backgroundTracker?.Dispose(); _backgroundTracker = null; } base.Dispose(disposing); }
void IVisualElementRenderer.SetElement(VisualElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (!(element is Button)) { throw new ArgumentException($"{nameof(element)} must be of type {nameof(Button)}"); } VisualElement oldElement = Button; Button = (Button)element; var reference = Guid.NewGuid().ToString(); Performance.Start(reference); if (oldElement != null) { oldElement.PropertyChanged -= OnElementPropertyChanged; } if (_backgroundTracker == null) { _backgroundTracker = new ButtonBackgroundTracker(Button, this); } else { _backgroundTracker.Button = Button; } Color currentColor = oldElement?.BackgroundColor ?? Color.Default; if (element.BackgroundColor != currentColor) { UpdateBackgroundColor(); } element.PropertyChanged += OnElementPropertyChanged; if (_tracker == null) { // Can't set up the tracker in the constructor because it access the Element (for now) SetTracker(new VisualElementTracker(this)); } OnElementChanged(new ElementChangedEventArgs <Button>(oldElement as Button, Button)); SendVisualElementInitialized(element, this); EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); Performance.Stop(reference); }