Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ public void ImageSourceParentSize()
{
avatarImage.WidthRequest.Should().Be(73);
avatarImage.HeightRequest.Should().Be(37);
avatarImage.Clip.Should().BeOfType<RoundRectangleGeometry>();
if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsMacOS())
{
avatarImage.Clip.Should().BeNull();
}
else
{
avatarImage.Clip.Should().BeOfType<RoundRectangleGeometry>();
}
}
}
}
23 changes: 14 additions & 9 deletions src/CommunityToolkit.Maui/Views/AvatarView.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ static void OnCornerRadiusPropertyChanged(BindableObject bindable, object oldVal
AvatarView avatarView = (AvatarView)bindable;
CornerRadius corderRadius = (CornerRadius)newValue;

avatarView.StrokeShape = new RoundRectangle { CornerRadius = corderRadius };
avatarView.StrokeShape = new RoundRectangle
{
CornerRadius = corderRadius
};
}

static void OnImageSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
Expand All @@ -328,12 +331,6 @@ void HandleImageChanged(ImageSource? newValue)
avatarImage.Source = newValue;
if (newValue is not null)
{
// Work-around for iOS / MacOS bug that paints `Border.BackgroundColor` over top of `Border.Content` when an Image is used for `Border.Content`
if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsMacOS())
{
BackgroundColor = Colors.Transparent;
}

Content = avatarImage;
}
else
Expand All @@ -357,6 +354,7 @@ void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e)
&& avatarImage.Source is not null)

{
Geometry? avatarImageClipGeometry = null;
#if WINDOWS
double offsetX = 0;
double offsetY = 0;
Expand All @@ -367,7 +365,14 @@ void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e)
double imageWidth = Width - (StrokeThickness * 2) - Padding.Left - Padding.Right;
double imageHeight = Height - (StrokeThickness * 2) - Padding.Top - Padding.Bottom;

Rect rect = new(offsetX, offsetY, imageWidth, imageHeight);
if (!OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacOS())
{
avatarImageClipGeometry = new RoundRectangleGeometry
{
CornerRadius = CornerRadius,
Rect = new(offsetX, offsetY, imageWidth, imageHeight)
};
}

avatarImage.Clip = StrokeShape switch
{
Expand All @@ -376,7 +381,7 @@ void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e)
Microsoft.Maui.Controls.Shapes.Path path => path.Clip,
Polygon polygon => polygon.Clip,
Rectangle rectangle => rectangle.Clip,
_ => new RoundRectangleGeometry { CornerRadius = CornerRadius, Rect = rect },
_ => avatarImageClipGeometry
};
}
}
Expand Down