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: AvatarView clipping on Android isn't applied correctly #668

Merged
merged 4 commits into from
Oct 12, 2022
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 @@ -10,7 +10,7 @@
x:DataType="vm:GravatarImageSourceViewModel"
x:TypeArguments="vm:GravatarImageSourceViewModel">
<ScrollView>
<VerticalStackLayout Spacing="12">
<VerticalStackLayout Spacing="12" Padding="0,12,0,0" >
<VerticalStackLayout.Resources>
<ResourceDictionary>
<Style x:Key="Description" TargetType="Label">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public GravatarImageSourcePage(GravatarImageSourceViewModel viewModel) : base(vi
{
InitializeComponent();

Padding = new Thickness(Padding.Left, Padding.Top, Padding.Right, 0);
Padding = new Thickness(Padding.Left, 0, Padding.Right, 0);
}
}
10 changes: 9 additions & 1 deletion src/CommunityToolkit.Maui/Views/AvatarView.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,19 @@ void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e)
&& Height >= 0 // The default value of Height (before the view is drawn onto the page) is -1
&& Width >= 0 // The default value of Y (before the view is drawn onto the page) is -1
&& avatarImage.Source is not null)

{
#if WINDOWS
double offsetX = 0;
double offsetY = 0;
#else
double offsetX = StrokeThickness + Padding.Left;
double offsetY = StrokeThickness + Padding.Top;
#endif
double imageWidth = Width - (StrokeThickness * 2) - Padding.Left - Padding.Right;
double imageHeight = Height - (StrokeThickness * 2) - Padding.Top - Padding.Bottom;

Rect rect = new(0, 0, imageWidth, imageHeight);
Rect rect = new(offsetX, offsetY, imageWidth, imageHeight);

avatarImage.Clip = StrokeShape switch
{
Expand Down