Skip to content

Commit

Permalink
fix(reg): Fix CornerRadius support on Border
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Oct 21, 2021
1 parent 9b88a52 commit 9f0b463
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 49 deletions.
89 changes: 41 additions & 48 deletions src/Uno.UI/UI/Xaml/Controls/Border/BorderLayerRenderer.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,58 +47,51 @@ public void UpdateLayer(
Brush borderBrush,
CornerRadius cornerRadius,
Thickness padding,
bool willUpdateMeasures = false
)
bool willUpdateMeasures = false)
{
// This is required because android Height and Width are hidden by Control.
var baseView = view as View;

var logicalDrawArea = view.LayoutSlot;
// Set origin to 0, because drawArea should be in the coordinates of the view itself
logicalDrawArea.X = 0;
logicalDrawArea.Y = 0;
var drawArea = logicalDrawArea.LogicalToPhysicalPixels();
var drawArea = new Rect(default, view.LayoutSlotWithMarginsAndAlignments.Size.LogicalToPhysicalPixels());
var newState = new LayoutState(drawArea, background, borderThickness, borderBrush, cornerRadius, padding);
var previousLayoutState = _currentState;

if (!newState.Equals(previousLayoutState))
if (newState.Equals(previousLayoutState))
{
bool imageHasChanged = newState.BackgroundImageSource != previousLayoutState?.BackgroundImageSource;
bool shouldDisposeEagerly = imageHasChanged || newState.BackgroundImageSource == null;
if (shouldDisposeEagerly)
{
return;
}

// Clear previous value anyway in order to make sure the previous values are unset before the new ones.
// This prevents the case where a second update would set a new background and then set the background to null when disposing the previous.
_layerDisposable.Disposable = null;
}
var imageHasChanged = newState.BackgroundImageSource != previousLayoutState?.BackgroundImageSource;
var shouldDisposeEagerly = imageHasChanged || newState.BackgroundImageSource == null;
if (shouldDisposeEagerly)
{
// Clear previous value anyway in order to make sure the previous values are unset before the new ones.
// This prevents the case where a second update would set a new background and then set the background to null when disposing the previous.
_layerDisposable.Disposable = null;
}

Action onImageSet = null;
var disposable = InnerCreateLayers(view, drawArea, background, backgroundSizing, borderThickness, borderBrush, cornerRadius, () => onImageSet?.Invoke());
Action onImageSet = null;
var disposable = InnerCreateLayers(view, drawArea, background, backgroundSizing, borderThickness, borderBrush, cornerRadius, () => onImageSet?.Invoke());

// Most of the time we immediately dispose the previous layer. In the case where we're using an ImageBrush,
// and the backing image hasn't changed, we dispose the previous layer at the moment the new background is applied,
// to prevent a visible flicker.
if (shouldDisposeEagerly)
{
_layerDisposable.Disposable = disposable;
}
else
{
onImageSet = () => _layerDisposable.Disposable = disposable;
}

if (willUpdateMeasures)
{
view.RequestLayout();
}
else
{
view.Invalidate();
}
// Most of the time we immediately dispose the previous layer. In the case where we're using an ImageBrush,
// and the backing image hasn't changed, we dispose the previous layer at the moment the new background is applied,
// to prevent a visible flicker.
if (shouldDisposeEagerly)
{
_layerDisposable.Disposable = disposable;
}
else
{
onImageSet = () => _layerDisposable.Disposable = disposable;
}

_currentState = newState;
if (willUpdateMeasures)
{
view.RequestLayout();
}
else
{
view.Invalidate();
}

_currentState = newState;
}

/// <summary>
Expand All @@ -110,7 +103,8 @@ internal void Clear()
_currentState = null;
}

private static IDisposable InnerCreateLayers(BindableView view,
private static IDisposable InnerCreateLayers(
BindableView view,
Rect drawArea,
Brush background,
BackgroundSizing backgroundSizing,
Expand All @@ -123,14 +117,13 @@ private static IDisposable InnerCreateLayers(BindableView view,

var physicalBorderThickness = borderThickness.LogicalToPhysicalPixels();
var isInnerBorderSizing = backgroundSizing == BackgroundSizing.InnerBorderEdge;
var adjustedArea =
isInnerBorderSizing
? drawArea.DeflateBy(physicalBorderThickness)
: drawArea;
var adjustedArea = isInnerBorderSizing
? drawArea.DeflateBy(physicalBorderThickness)
: drawArea;

if (cornerRadius != 0)
{
if (view is UIElement uiElement && uiElement.FrameRoundingAdjustment is { } fra)
if ((view as UIElement)?.FrameRoundingAdjustment is { } fra)
{
drawArea.Height += fra.Height;
drawArea.Width += fra.Width;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ internal virtual void OnPropertyChanged2(DependencyPropertyChangedEventArgs args
/// <summary>
/// This is the <see cref="LayoutSlot"/> **after** margins and alignments has been applied.
/// It's somehow the region into which an element renders itself in its parent (before any RenderTransform).
/// The size of
/// This is the 'finalRect' of the last Arrange.
/// </summary>
/// <remarks>This is expressed in parent's coordinate space.</remarks>
internal Rect LayoutSlotWithMarginsAndAlignments { get; set; } = default;
Expand Down

0 comments on commit 9f0b463

Please sign in to comment.