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] Fix issue updating Border size #5608

Merged
merged 2 commits into from
Mar 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Core/src/Graphics/MauiDrawable.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ public void SetBorderLineCap(LineCap lineCap)
InvalidateSelf();
}

public void InvalidateBorderBounds()
{
_bounds = null;

InvalidateSelf();
}

protected override void OnBoundsChange(ARect? bounds)
{
if (_bounds != bounds)
Expand Down
14 changes: 13 additions & 1 deletion src/Core/src/Handlers/Border/BorderHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ static void UpdateContent(IBorderHandler handler)
handler.PlatformView.AddView(view.ToPlatform(handler.MauiContext));
}

public static void MapHeight(IBorderHandler handler, IBorderView border)
{
handler.PlatformView?.UpdateHeight(border);
handler.PlatformView?.InvalidateBorderStrokeBounds();
}

public static void MapWidth(IBorderHandler handler, IBorderView border)
{
handler.PlatformView?.UpdateWidth(border);
handler.PlatformView?.InvalidateBorderStrokeBounds();
}

public static void MapContent(IBorderHandler handler, IBorderView border)
{
UpdateContent(handler);
Expand All @@ -59,4 +71,4 @@ protected override void DisconnectHandler(ContentViewGroup platformView)
base.DisconnectHandler(platformView);
}
}
}
}
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/Border/BorderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public partial class BorderHandler : IBorderHandler
{
public static IPropertyMapper<IBorderView, IBorderHandler> Mapper = new PropertyMapper<IBorderView, IBorderHandler>(ViewMapper)
{
#if __ANDROID__
[nameof(IContentView.Height)] = MapHeight,
[nameof(IContentView.Width)] = MapWidth,
#endif
[nameof(IContentView.Background)] = MapBackground,
[nameof(IContentView.Content)] = MapContent,
[nameof(IBorderStroke.Shape)] = MapStrokeShape,
Expand Down
11 changes: 10 additions & 1 deletion src/Core/src/Platform/Android/StrokeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class StrokeExtensions
{
public static void UpdateBorderStroke(this AView platformView, IBorderStroke border)
{
//Always set the drawable first
// Always set the drawable first
platformView.UpdateMauiDrawable(border);

var borderShape = border.Shape;
Expand Down Expand Up @@ -119,6 +119,14 @@ public static void UpdateStrokeLineJoin(this AView platformView, IBorderStroke b
mauiDrawable?.SetBorderLineJoin(border.StrokeLineJoin);
}

public static void InvalidateBorderStrokeBounds(this AView platformView)
{
if (platformView.Background is not MauiDrawable mauiDrawable)
return;

mauiDrawable.InvalidateBorderBounds();
}

internal static void UpdateMauiDrawable(this AView platformView, IBorderStroke border)
{
bool hasBorder = border.Shape != null && border.Stroke != null;
Expand All @@ -139,6 +147,7 @@ internal static void UpdateMauiDrawable(this AView platformView, IBorderStroke b
mauiDrawable.SetBackground(v.Background);
else
mauiDrawable.SetBackground(new SolidPaint(Colors.Transparent));

mauiDrawable.SetBorderShape(border.Shape);
}
}
Expand Down