public void Reset() { if (_drawableEnabled) { _drawableEnabled = false; _drawable?.Reset(); _drawable = null; } }
public void UpdateDrawable() { if (Element == null) { return; } bool cornerRadiusIsDefault = Element.CornerRadius == (CornerRadius)PancakeView.CornerRadiusProperty.DefaultValue; bool backgroundColorIsDefault = !Element.BackgroundGradientStops.Any() && Element.BackgroundColor == (Color)VisualElement.BackgroundColorProperty.DefaultValue; if (backgroundColorIsDefault && cornerRadiusIsDefault) { if (!_drawableEnabled) { return; } if (_defaultDrawable != null) { this.SetBackground(_defaultDrawable); } _drawableEnabled = false; Reset(); } else { if (_drawable == null) { _drawable = new PancakeDrawable(Element, Context.ToPixels); } if (_drawableEnabled) { return; } if (_defaultDrawable == null) { _defaultDrawable = this.Background; } if (!backgroundColorIsDefault) { this.SetBackground(_drawable); } _drawableEnabled = true; } this.Invalidate(); }
protected override void Dispose(bool disposing) { if (!_disposed) { if (disposing) { _drawable?.Dispose(); _drawable = null; _defaultDrawable?.Dispose(); _defaultDrawable = null; } _disposed = true; } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { var pancake = Element as PancakeView; Validate(pancake); base.OnElementPropertyChanged(sender, e); if (e.PropertyName == PancakeView.BorderColorProperty.PropertyName || e.PropertyName == PancakeView.BorderThicknessProperty.PropertyName || e.PropertyName == PancakeView.BorderIsDashedProperty.PropertyName || e.PropertyName == PancakeView.BorderDashPatternProperty.PropertyName || e.PropertyName == PancakeView.BorderDrawingStyleProperty.PropertyName || e.PropertyName == PancakeView.BorderGradientAngleProperty.PropertyName || e.PropertyName == PancakeView.BorderGradientEndColorProperty.PropertyName || e.PropertyName == PancakeView.BorderGradientStartColorProperty.PropertyName || e.PropertyName == PancakeView.BorderGradientStopsProperty.PropertyName) { Invalidate(); } else if (e.PropertyName == PancakeView.SidesProperty.PropertyName || e.PropertyName == PancakeView.OffsetAngleProperty.PropertyName || e.PropertyName == PancakeView.ShadowProperty.PropertyName || e.PropertyName == PancakeView.HasShadowProperty.PropertyName || e.PropertyName == PancakeView.ElevationProperty.PropertyName) { SetupShadow(pancake); } else if (e.PropertyName == PancakeView.CornerRadiusProperty.PropertyName) { Invalidate(); SetupShadow(pancake); } else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) { _drawable.Dispose(); this.SetBackground(_drawable = new PancakeDrawable(pancake, Context.ToPixels)); } }
protected override void OnElementChanged(ElementChangedEventArgs <ContentView> e) { base.OnElementChanged(e); if (e.NewElement != null && e.OldElement == null) { var pancake = (Element as PancakeView); // HACK: When there are no children we add a Grid element to trigger DrawChild. // This should be improved upon, but I haven't found out a nice way to be able to clip // the children and add the border on top without using DrawChild. if (pancake.Content == null) { pancake.Content = new Grid(); } Validate(pancake); this.SetBackground(_drawable = new PancakeDrawable(pancake, Context.ToPixels)); SetupShadow(pancake); } }