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
22.28k stars 1.76k forks source link

VisualElement.HeightRequest defaults to 0 instead of -1 when using OnIdiom default value #9978

Open ZackAllen opened 2 years ago

ZackAllen commented 2 years ago

Description

VisualElement.WidthRequest and VisualElement.HeightRequest have a default value of 0 if an OnIdiom condition is not set. This results in an element not being visible instead of being -1 which doesn't change behavior.

Steps to Reproduce

  1. Set a height request to "{OnIdiom Phone=200}".
  2. Run on desktop.
  3. Observe that the visual element has 0 height, instead of the default height it would have with no height request set.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="MauiWidthBugApp.MainPage"
             xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <ScrollView>
        <VerticalStackLayout Padding="30,0"
                             Spacing="25"
                             VerticalOptions="Center"
                             WidthRequest="300">

            <Label FontSize="32"
                   HorizontalOptions="Center"
                   SemanticProperties.HeadingLevel="Level1"
                   Text="Working image:" />
            <!--  No height request, image stretches to fit  -->
            <Image HorizontalOptions="Center"
                   SemanticProperties.Description="Working image"
                   Source="dotnet_bot.png" />

            <Label FontSize="32"
                   HorizontalOptions="Center"
                   SemanticProperties.HeadingLevel="Level1"
                   Text="Image with bug:" />
            <!--  With no default set, platforms that aren't Phone have this value set to 0, making the visual element disappear instead of stretching to fit the parent like it should  -->
            <Image HeightRequest="{OnIdiom Phone=200}"
                   HorizontalOptions="Center"
                   SemanticProperties.Description="Defaults to height request 0 on desktop"
                   Source="dotnet_bot.png" />

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

Link to public reproduction project repository

https://github.com/ZackAllen/mauiHeightRequestBug

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows

Affected platform versions

All

Did you find any workaround?

Manually setting a default of -1.

Relevant log output

No response

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

PureWeen commented 2 years ago

@StephaneDelcroix

DancesWithDingo commented 1 year ago

I just ran into this when running my app on Android for the first time. Setting width with {OnIdiom Desktop=600, Tablet=600} required Default=-1 to be added to work on Android mobile screens.

Zhanglirong-Winnie commented 1 year ago

Verified this issue with Visual Studio 17.7.0 Preview 1.0. Can repro on windows and iOS platform with above project. Android works fine. mauiHeightRequestBug-main.zip Windows: Windows iOS: iOS Android: Android