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
19 changes: 18 additions & 1 deletion src/Controls/src/Core/BindableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,24 @@ BindablePropertyContext CreateAndAddContext(BindableProperty property)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal BindablePropertyContext GetContext(BindableProperty property) => _properties.TryGetValue(property, out var result) ? result : null;
internal BindablePropertyContext GetContext(BindableProperty property)
{
var isValueFound = _properties.TryGetValue(property, out var result);

if (isValueFound)
return result;

// Some properties may not be found due to the dictionary's BindableProperty class key
tj-devel709 marked this conversation as resolved.
Show resolved Hide resolved
foreach (var key in _properties.Keys)
{
if (key.PropertyName == property.PropertyName)
{
return _properties[key];
}
}

return null;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
BindablePropertyContext GetOrCreateContext(BindableProperty property) => GetContext(property) ?? CreateAndAddContext(property);
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.IsSet(Layout.IsClippedToBoundsProperty) ? Element.IsClippedToBounds : true;
}

void UpdateShadow()
Expand Down
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)
Assert.False(handler.PlatformView.ClipsToBounds);
else
Assert.True(handler.PlatformView.ClipsToBounds);
}));
}
}
}
}