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

Size in OnSizeAllocated of SKCanvasView in .NET 9.0 / SkiaSharp 3.0 Preview 2.1 does not match value returned in MeasureOverride #2811

Open
1 task done
janne-hmp opened this issue Mar 27, 2024 · 1 comment
Labels

Comments

@janne-hmp
Copy link

Description

I'm not sure if this is a .NET MAUI or SkiaSharp 3.0 problem, so I post this in both repositories: I have created a custom control called CustomLabel inheriting from SKCanvasView (SkiaSharp 3.0 Preview 2.1), which works great in Xamarin.Forms. It is an auto-sizing special label (like normal label) with some extra features compared to normal label. It uses overriding OnMeasure in Xamarin and MeasureOverride in .NET MAUI (.NET 9.0 Preview 2) to set itself to the right size, based on its contents. In .NET MAUI, however, the Size value result from MeasureOverride (which is correctly calculated) does not match what MAUI allocates as size in OnSizeAllocated (which is how the control in fact looks like), making the control way smaller in height than requested, sometimes even 0 (on iOS). The error may depend on the layout, or the fact that there is new MeasureOverride function in MAUI, but I haven't figured out the root cause for the bug. In Xamarin, everything works exactly as intended. Tested on Android 14 and iOS 17.3.1.

Code

https://github.com/hyvanmielenpelit/GnollHack

Expected Behavior

I expected the CustomLabel used in GnollHackM (MAUI) menu titles to draw in full height like it does in GnollHackX (Xamarin).

Actual Behavior

The CustomLabel in GnollHackM (.NET MAUI) is drawn in partial height, making it too small and parts of the text being cut off. MeasureOverride calculates the right value, but OnSizeAllocated gets called with the wrong height (and that's how the label in fact looks in practice). On iOS, the height is even sometimes 0.

Version of SkiaSharp

3.x (Alpha)

Last Known Good Version of SkiaSharp

2.80.x (Deprecated)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Android, iOS

Platform / Operating System Version

Android 14, iOS 17.3.1

Devices

Google Pixel 6a, iPad 11,7

Relevant Screenshots

Screenshot_20240327-234854
Screenshot_20240327-234739

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@janne-hmp
Copy link
Author

There's a workaround to this in the following Maui issue: dotnet/maui#4019 (comment) . @mattleibow Perhaps this can give a clue how to fix the behavior for SKCanvasView when overriding OnMeasure or using MeasureOverride.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant