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

Fix iOS/macOS Images not cropped inside of a Frame #6580 #11352

Merged
merged 9 commits into from
Nov 21, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ void UpdateClippedToBounds()
if (Element == null)
return;

var shouldClip = Element.IsSet(Microsoft.Maui.Controls.Compatibility.Layout.IsClippedToBoundsProperty)
? Element.IsClippedToBounds : Element.CornerRadius > 0f;
var shouldClip = Element.IsClippedToBoundsSet(Element.CornerRadius > 0f);

this.SetClipToOutline(shouldClip);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public virtual void SetupLayer()

_actualView.Layer.RasterizationScale = UIScreen.MainScreen.Scale;
_actualView.Layer.ShouldRasterize = true;
_actualView.Layer.MasksToBounds = Element.IsClippedToBounds;
_actualView.Layer.MasksToBounds = Element.IsClippedToBoundsSet(true);
}

void UpdateShadow()
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/src/Core/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ void IBorderElement.OnBorderColorPropertyChanged(Color oldValue, Color newValue)

bool IBorderElement.IsBorderWidthSet() => false;
}

internal static class FrameExtensions
{
internal static bool IsClippedToBoundsSet(this Frame frame, bool defaultValue) =>
frame.IsSet(Compatibility.Layout.IsClippedToBoundsProperty) ? frame.IsClippedToBounds : defaultValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,40 @@ await InvokeOnMainThreadAsync(() =>
}
}));
}

[Theory(DisplayName = "Frame's Content Clips to Bounds Properly")]
[InlineData(true)]
[InlineData(false)]
[InlineData(null)]
public async Task FrameClipsCorrectly(bool? isClipped)
{
SetupBuilder();

var frame = new Frame()
{
HeightRequest = 300,
WidthRequest = 300,
CornerRadius = 80,
Content = new Frame
{
HeightRequest = 400,
WidthRequest = 400,
BackgroundColor = Colors.Blue,
}
};

if (isClipped is bool clipped)
frame.IsClippedToBounds = clipped!;

await InvokeOnMainThreadAsync(() =>
frame.ToPlatform(MauiContext).AttachAndRun(() =>
{
var handler = frame.ToHandler(MauiContext);
if (isClipped == false)
Assert.False(handler.PlatformView.ClipsToBounds);
else
Assert.True(handler.PlatformView.ClipsToBounds);
}));
}
}
}
}