Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Render Border without set a Stroke #7247

Merged
merged 2 commits into from May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/Core/src/Graphics/MauiDrawable.Android.cs
Expand Up @@ -164,17 +164,20 @@ public void SetBorderBrush(GPaint? paint)
if (paint is SolidPaint solidPaint)
SetBorderBrush(solidPaint);

if (paint is LinearGradientPaint linearGradientPaint)
else if (paint is LinearGradientPaint linearGradientPaint)
SetBorderBrush(linearGradientPaint);

if (paint is RadialGradientPaint radialGradientPaint)
else if (paint is RadialGradientPaint radialGradientPaint)
SetBorderBrush(radialGradientPaint);

if (paint is ImagePaint imagePaint)
else if (paint is ImagePaint imagePaint)
SetBorderBrush(imagePaint);

if (paint is PatternPaint patternPaint)
else if (paint is PatternPaint patternPaint)
SetBorderBrush(patternPaint);

else
SetEmptyBorderBrush();
}

public void SetBorderBrush(SolidPaint solidPaint)
Expand Down Expand Up @@ -218,6 +221,27 @@ public void SetBorderBrush(RadialGradientPaint radialGradientPaint)
InvalidateSelf();
}

public void SetEmptyBorderBrush()
{
_invalidatePath = true;

if (_backgroundColor != null)
{
_borderColor = _backgroundColor.Value;
_stroke = null;
}
else
{
_borderColor = null;

if (_background != null)
SetBorderBrush(_background);
}

InitializeBorderIfNeeded();
InvalidateSelf();
}

public void SetBorderBrush(ImagePaint imagePaint)
{
throw new NotImplementedException();
Expand Down Expand Up @@ -473,7 +497,7 @@ bool HasBorder()
{
InitializeBorderIfNeeded();

return _shape != null && (_stroke != null || _borderColor != null);
return _shape != null;
}

void InitializeBorderIfNeeded()
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Platform/Android/StrokeExtensions.cs
Expand Up @@ -129,7 +129,7 @@ public static void InvalidateBorderStrokeBounds(this AView platformView)

internal static void UpdateMauiDrawable(this AView platformView, IBorderStroke border)
{
bool hasBorder = border.Shape != null && border.Stroke != null;
bool hasBorder = border.Shape != null;

if (!hasBorder)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Platform/Android/ViewExtensions.cs
Expand Up @@ -160,7 +160,7 @@ public static void SetWindowBackground(this AView view)

public static void UpdateBackground(this ContentViewGroup platformView, IBorderStroke border)
{
bool hasBorder = border.Shape != null && border.Stroke != null;
bool hasBorder = border.Shape != null;

if (hasBorder)
platformView.UpdateBorderStroke(border);
Expand Down
@@ -1,12 +1,34 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.DeviceTests.Stubs;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
public partial class BorderHandlerTests
{
[Theory(DisplayName = "Border render without Stroke")]
[InlineData(0xFF0000)]
[InlineData(0x00FF00)]
[InlineData(0x0000FF)]
public async Task BorderRenderWithoutStroke(uint color)
{
var expected = Color.FromUint(color);

var border = new BorderStub()
{
Content = new LabelStub { Text = "Without Stroke", TextColor = Colors.White },
Shape = new RoundRectangleShapeStub { CornerRadius = new CornerRadius(12) },
Background = new SolidPaintStub(expected),
Stroke = null,
StrokeThickness = 2,
Height = 100,
Width = 300
};

await ValidateHasColor(border, expected);
}

ContentViewGroup GetNativeBorder(BorderHandler borderHandler) =>
borderHandler.PlatformView;

Expand All @@ -20,4 +42,4 @@ Task ValidateHasColor(IBorderView border, Color color, Action action = null)
});
}
}
}
}