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
1 change: 1 addition & 0 deletions eng/BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to create the service instead
M:Android.Content.Res.ColorStateList.#ctor(System.Int32[][],System.Int32[]);Use Microsoft.Maui.PlatformInterop.Get*ColorStateList() Java methods instead
M:Android.Widget.ImageView.GetScaleType();Use PlatformInterop.IsImageViewCenterCrop instead (or add a new method)
P:Microsoft.Maui.MauiWinUIApplication.Services;Use the IPlatformApplication.Current.Services instead
P:Microsoft.Maui.MauiWinUIApplication.Application;Use the IPlatformApplication.Current.Application instead
P:Microsoft.UI.Xaml.Window.AppWindow;This API doesn't have null safety. Use GetAppWindow() and make sure to account for the possibility that GetAppWindow() might be null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void OnLayoutChange(object sender, global::Android.Views.View.LayoutChang
{
if (sender is IVisualElementRenderer renderer && renderer.View is ImageView imageView)
#pragma warning disable CS0618 // Obsolete
AViewCompat.SetClipBounds(imageView, imageView.GetScaleType() == AScaleType.CenterCrop ? new ARect(0, 0, e.Right - e.Left, e.Bottom - e.Top) : null);
AViewCompat.SetClipBounds(imageView, PlatformInterop.IsImageViewCenterCrop(imageView) ? new ARect(0, 0, e.Right - e.Left, e.Bottom - e.Top) : null);
#pragma warning restore CS0618 // Obsolete

}
Expand Down
1 change: 1 addition & 0 deletions src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<RootNamespace>Microsoft.Maui.DeviceTests</RootNamespace>
<AssemblyName>Microsoft.Maui.Controls.DeviceTests</AssemblyName>
<NoWarn>$(NoWarn),CA1416</NoWarn>
<IsTestProject>true</IsTestProject>
<!-- Disable multi-RID builds to workaround a parallel build issue -->
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst'))">maccatalyst-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst')) and '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'arm64'">maccatalyst-arm64</RuntimeIdentifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,19 @@ public static Animatable getAnimatable(Drawable drawable) {
}
return null;
}

/*
* Checks if the ScaleType of the ImageView is CENTER_CROP.
* Avoids returning an object to C#.
*/
public static boolean isImageViewCenterCrop(@NonNull ImageView imageView) {
return imageView.getScaleType() == ImageView.ScaleType.CENTER_CROP;
}

/*
* Sets View.ClipBounds without creating a Rect object in C#
*/
public static void setClipBounds(@NonNull View view, int left, int top, int right, int bottom) {
view.setClipBounds(new Rect(left, top, right, bottom));
}
}
7 changes: 3 additions & 4 deletions src/Core/src/Handlers/Image/ImageHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ await handler

public override void PlatformArrange(Graphics.Rect frame)
{
if (PlatformView.GetScaleType() == ImageView.ScaleType.CenterCrop)
if (PlatformInterop.IsImageViewCenterCrop(PlatformView))
{
// If the image is center cropped (AspectFill), then the size of the image likely exceeds
// the view size in some dimension. So we need to clip to the view's bounds.

var (left, top, right, bottom) = PlatformView.Context!.ToPixels(frame);
var clipRect = new Android.Graphics.Rect(0, 0, right - left, bottom - top);
PlatformView.ClipBounds = clipRect;
var (left, top, right, bottom) = PlatformView.ToPixels(frame);
PlatformInterop.SetClipBounds(PlatformView, 0, 0, right - left, bottom - top);
}
else
{
Expand Down
11 changes: 11 additions & 0 deletions src/Core/src/Platform/Android/ContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ static float ToPixelsUsingMetrics(double dp)
return (float)Math.Ceiling((dp * s_displayDensity) - GeometryUtil.Epsilon);
}

internal static (int left, int top, int right, int bottom) ToPixels(this View view, Graphics.Rect rectangle)
{
return
(
(int)view.ToPixels(rectangle.Left),
(int)view.ToPixels(rectangle.Top),
(int)view.ToPixels(rectangle.Right),
(int)view.ToPixels(rectangle.Bottom)
);
}

public static (int left, int top, int right, int bottom) ToPixels(this Context context, Graphics.Rect rectangle)
{
return
Expand Down
1 change: 1 addition & 0 deletions src/Core/tests/DeviceTests/Core.DeviceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<RootNamespace>Microsoft.Maui.DeviceTests</RootNamespace>
<AssemblyName>Microsoft.Maui.Core.DeviceTests</AssemblyName>
<NoWarn>$(NoWarn),CA1416</NoWarn>
<IsTestProject>true</IsTestProject>
<!-- Disable multi-RID builds to workaround a parallel build issue -->
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst'))">maccatalyst-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst')) and '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'arm64'">maccatalyst-arm64</RuntimeIdentifier>
Expand Down
Loading