Skip to content

Commit

Permalink
Null ref, keep radius synced
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sadegh-sh committed Sep 2, 2024
1 parent c132d1a commit ddc2202
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
26 changes: 10 additions & 16 deletions Zebble/Android/Image/AndroidRenderer.Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,25 @@
using layout = Android.Views.ViewGroup.LayoutParams;
using Olive;
using Zebble.Device;
using System.Linq;

partial class Renderer
{
Android.Views.View BackgroundImage;

class CustomViewOutlineProvider : Android.Views.ViewOutlineProvider
{
readonly View View;
float BorderRadius;

public CustomViewOutlineProvider(View view) => View = view;
public CustomViewOutlineProvider(float borderRadius) => BorderRadius = borderRadius;

public override void GetOutline(Android.Views.View view, Android.Graphics.Outline outline)
{
if (View is null) return;
if (view is null) return;
if (outline is null) return;

var left = 0;
var top = 0;
var right = Scale.ToDevice(View.ActualWidth);
var bottom = Scale.ToDevice(View.ActualHeight);

var borderRadius = View.Effective.BorderRadius;
var corners = borderRadius.GetEffectiveRadiusCorners(View);
var radius = Scale.ToDevice(corners[0]);

view.ClipToOutline = true;
outline.Alpha = 0;
outline.SetRoundRect(left, top, right, bottom, radius);
outline.SetRoundRect(0, 0, view.Width, view.Height, BorderRadius);
view.ClipToOutline = true;
}
}

Expand All @@ -63,7 +52,12 @@ void SetBackgroundAndBorder()
Result.Background = colorLayer;

if (hasBorderRadius && View is Canvas canvas && canvas.ClipChildren)
Result.OutlineProvider = new CustomViewOutlineProvider(view);
{
var borderRadius = View.Effective.BorderRadius;
var corners = borderRadius.GetEffectiveRadiusCorners(View);
var radius = Scale.ToDevice(corners[0]);
Result.OutlineProvider = new CustomViewOutlineProvider(radius);
}
}

void SetBackgroundImage()
Expand Down
1 change: 1 addition & 0 deletions Zebble/Android/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void HandleEvents()
if (IsDead(out var view)) return;

view.BorderChanged.HandleOnUI(SetBackgroundAndBorder);
view.BorderRadiusChanged.HandleOnUI(SetBackgroundAndBorder);
view.BackgroundImageChanged.HandleOnUI(SetBackgroundImage);

if (Result is IPaddableControl)
Expand Down
2 changes: 1 addition & 1 deletion Zebble/Zebble.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RootNamespace>Zebble</RootNamespace>
<PackageId>Zebble</PackageId>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<Version>5.0.58.0</Version>
<Version>5.0.59.0</Version>
<PackOnBuild>true</PackOnBuild>
<NeutralLanguage>en</NeutralLanguage>
<NoWarn>0618;0162</NoWarn>
Expand Down

0 comments on commit ddc2202

Please sign in to comment.