Skip to content

Commit

Permalink
Fix issue updating Border size on Android (#5608)
Browse files Browse the repository at this point in the history
Co-authored-by: redth <jondick@gmail.com>
  • Loading branch information
jsuarezruiz and Redth authored Mar 28, 2022
1 parent f2cdd2d commit 5c0a286
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
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

0 comments on commit 5c0a286

Please sign in to comment.