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

Layout Error: Label height within VerticalStackLayout is truncated when width is set #15559

Open
DancesWithDingo opened this issue Jun 9, 2023 · 2 comments · May be fixed by #25748
Open

Layout Error: Label height within VerticalStackLayout is truncated when width is set #15559

DancesWithDingo opened this issue Jun 9, 2023 · 2 comments · May be fixed by #25748
Labels
area-controls-label Label, Span area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-stack platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@DancesWithDingo
Copy link

DancesWithDingo commented Jun 9, 2023

Description

In iOS and MacCatalyst, there is flaw in the VerticalStackLayout height calculation that impacts the height of content. Specifically, when a Label is placed within a VerticalStackLayout that has its width set, the Label height is miscalculated to be the height it would be if the width weren't set.

For an example, I've created a repro application that shows this in action. (https://github.com/DancesWithDingo/MAUI_LabelTextWrapSample.git)

Steps to Reproduce

Create a new .NET MAUI app. In MainPage.xaml, replace the content with the following:

<VerticalStackLayout Spacing="20" Margin="20">
    <VerticalStackLayout BackgroundColor="Yellow">
        <Label Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore."/>
    </VerticalStackLayout>

    <VerticalStackLayout WidthRequest="240" BackgroundColor="Yellow">
        <Label Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore."/>
    </VerticalStackLayout>
</VerticalStackLayout>

Run on iOS device with narrow screen. Note that the first label (without a width set) displays all of the text (two lines), and the second label (with with set to 240) only displays the first two lines.

Simulator Screenshot - iPhone 14 Pro Max - 2023-06-09 at 11 59 43

The sample repo provided shows the situation a bit more clearly. On MainPage, there are three VerticalStackLayout controls (and a fourth Grid). The first (yellow) instance has no width set. The second (green) example has the VerticalStackLayout width set to 300. The third (blue) example has no width set on the VerticalStackLayout, but instead the width is set on the label. The fourth example (orange) shows what happens when a Grid is used instead of the VerticalStackLayout.

Note when first run that the yellow label appears normally, taking up two lines of text. The green and yellow labels have the same height as the yellow label, but the text does not extend vertically as it should (and does on Android). And the orange example shows three lines and all of the text.

Press the Toggle button, which doubles the amount of text in the labels. Yellow and blue jump to four lines (truncated), and the orange grid displays normally.

Simulator.Screen.Recording.-.iPhone.14.Pro.Max.-.2023-06-09.at.11.07.57.mp4

The labels are colored with a lighter color to make it clear that it's the height of the label that is at issue, not the height of the containing VerticalStackLayout.

My takeaway is that the size calculation is returning the wrong height when width is restricted. I haven't tested it, but my assumption is this happens in the horizontal orientation as well.

Link to public reproduction project repository

https://github.com/DancesWithDingo/MAUI_LabelTextWrapSample.git

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

iOS 16.4

Did you find any workaround?

Wrapping with a grid instead of the VSL works, but is less ideal in many situations, not to mention potential performance issues implied by having nested grids.

@DancesWithDingo DancesWithDingo added the t/bug Something isn't working label Jun 9, 2023
@Eilon Eilon added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Jun 9, 2023
@PureWeen PureWeen added the area-controls-label Label, Span label Jun 13, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jun 13, 2023
@PureWeen PureWeen added this to the Backlog milestone Jun 13, 2023
@ghost
Copy link

ghost commented Jun 13, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Nov 24, 2023
@XamlTest
Copy link

Verified this on Visual Studio Enterprise 17.9.0 Preview 1(8.0.3). Repro on iOS 17.0 and MacCatalyst, not repro on Windows 11 and Android 14.0-API34 with below Project:
LabelTextWrapSample.zip

@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-label Label, Span area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-stack platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
6 participants