dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.72k forks source link

[BUG] In .NET 9.0 Preview 2, the last control of a layout is in some cases of incorrect size #21534

Open janne-hmp opened 5 months ago

janne-hmp commented 5 months ago

Description

On various occasions (mostly on Android and in different places on iOS), the last item of a layout in some cases is given too narrow a width. On Android, this happened with a custom control in a scroll view where the (normal, autosizing, HorizontalOptions Center) label inside the custom control became one character wide. The other labels were just fine, and the label worked on iOS, so it seems to be mostly an Android issue, and it seems to affect always only the last item in a list / layout.

However, on iOS, I was trying to make another layout to work with the new MaximumWidthRequest functionality, and ran into a similar issue where a grid become unnecessarily narrow despite HorizontalOptions set to FillAndExpand, which did not make any sense. Also this grid was the last element in a StackLayout; when I changed the StackLayout to a Grid, the problem persisted exactly in the same way (the resulting layout seemed to be exactly the same, too). EDIT: iOS issue was not connected, it is this one https://github.com/dotnet/maui/issues/21917 dealing with incorrect margin behavior.

Steps to Reproduce

Unfortunately, not sure how to reproduce this in an easy way (it used to appear sometimes on Android in my game GnollHack before I used the workaround below), but perhaps you could double-check that the last item of the layout is always correctly treated (all indices run correctly all the way to the last item, and all the layout logic holds correctly even for the last layout item).

Link to public reproduction project repository

https://github.com/hyvanmielenpelit/GnollHack

Version with bug

9.0.0-preview.1.9973

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

Android 14, iOS 17.3.1

Did you find any workaround?

I changed HorizontalOptions of the label to FillAndExpand, the last label in the layout started to resize itself correctly on Android (obviously because it had more space). However, it was bugged when the HorizontalOptions were set to Center.

Relevant log output

No response

janne-hmp commented 4 months ago

I think this may be because when porting from Xamarin to MAUI I forgot to remove ContentView.Content and ContentPage.Content tags in XAML. EDIT: This did not seem to be a problem after all, at least regarding the iOS topic mentioned above. This is an Android-only problem with lists. iOS issue was a separate thing influencing both platforms (https://github.com/dotnet/maui/issues/21917), and it appeared only iOS because I was using an iPad (wide screen; leading to big margins in the code) rather than a narrow phone.

Zhanglirong-Winnie commented 4 months ago

Verified this issue with Visual Studio 17.10.0 Preview 3(8.0.20&8.0.0-rc.2.9530&9.0.0-preview.2.10293). Can repro on iOS and android platforms.

janne-hmp commented 4 months ago

I would note here that this seems to be just an Android problem with lists and custom controls; iOS thing mentioned was a different thing. I updated the description and the comments to reflect the latest understanding.