xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.88k forks source link

[Bug] ScrollView and Grid with Star row height cut off invisible part #14220

Open RenaudAvenas opened 3 years ago

RenaudAvenas commented 3 years ago

Description

When a grid is resized because a child in a row (star height) changed it size (IsVisible becomes true by example) then the parent ScrollView can scroll to this child but it is cut off.

Steps to Reproduce

  1. Create a page with a ScrollView
  2. Insert a grid
  3. Put a child with IsVisible property to false and heightRequest to more than your screen height
  4. Use a button to make child become visible
  5. Scroll to bottom

Expected Behavior

The child must be drawn

Actual Behavior

The child is cut off

Basic Information

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Enterprise 2019 (2) Version 16.8.4 VisualStudio.16.Release/16.8.4+30907.101 Microsoft .NET Framework Version 4.8.03752 Version installée : Enterprise Visual C++ 2019 00435-60000-00000-AA190 Microsoft Visual C++ 2019 ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 2019 16.8.557.25636 ASP.NET and Web Tools 2019 ASP.NET Core Razor Language Services 16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c Provides languages services for ASP.NET Core Razor. ASP.NET Web Frameworks and Tools 2019 16.8.557.25636 Pour plus d'informations, visitez https://www.asp.net/ Assistants Microsoft Visual C++ 1.0 Assistants Microsoft Visual C++ Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer. Azure Data Lake Tools for Visual Studio 2.6.1000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 16.8.557.25636 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.1000.0 Microsoft Azure Stream Analytics Tools for Visual Studio Common Azure Tools 1.10 Fournit des services courants utilisables par Microsoft Azure Mobile Services et Microsoft Azure Tools. Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Extension de débogage d'instantané 1.0 Informations détaillées sur l'extension Visual Studio de débogage d'instantané Extension IntelliCode 1.0 Informations détaillées sur l'extension Visual Studio IntelliCode Fabric.DiagnosticEvents 1.0 Événements de diagnostic Fabric Gestionnaire de package NuGet 5.8.1 Gestionnaire de package NuGet dans Visual Studio. Pour plus d'informations sur NuGet, visitez https://docs.nuget.org/ Markdown Editor 1.12.253 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown. Microsoft Azure HDInsight Azure Node 2.6.1000.0 HDInsight Node under Azure Node Microsoft Azure Hive Query Language Service 2.6.1000.0 Language service for Hive query Microsoft Azure Service Fabric Tools pour Visual Studio 16.0 Microsoft Azure Service Fabric Tools pour Visual Studio Microsoft Azure Stream Analytics Language Service 2.6.1000.0 Language service for Azure Stream Analytics Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node Microsoft Azure Tools 2.9 Microsoft Azure Tools pour Microsoft Visual Studio 2019 - v2.9.30924.1 Microsoft Continuous Delivery Tools pour Visual Studio 0.4 Simplification de la configuration des pipelines Azure DevOps à partir de l'IDE Visual Studio. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Mono Debugging for Visual Studio 16.8.43 (00471f8) Support for debugging Mono processes with Visual Studio. Outils Azure App Service v3.0.0 16.8.557.25636 Outils Azure App Service v3.0.0 Outils C# 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd Composants C# utilisés dans l'IDE. Selon votre type de projet et vos paramètres, une version différente du compilateur peut être utilisée. Outils TypeScript 16.0.21016.2001 Outils TypeScript pour Microsoft Visual Studio Outils Visual Basic 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd Composants Visual Basic utilisés dans l'IDE. Selon votre type de projet et vos paramètres, une version différente du compilateur peut être utilisée. Package hôte de l'adaptateur de débogage de Visual Studio Code 1.0 Couche d'interopérabilité pour l'hébergement d'adaptateurs de débogage Visual Studio Code dans Visual Studio Package Microsoft Visual Studio VC 1.0 Package Microsoft Visual Studio VC ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info SQL Server Data Tools 16.0.62012.31170 Microsoft SQL Server Data Tools ToolWindowHostedEditor 1.0 Hosting json editor into a tool window UnoPlatformPackage Extension 1.0 UnoPlatformPackage Visual Studio Extension Detailed Info Visual F# Tools 16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd Microsoft Visual F# Tools Visual Studio Container Tools Extensions 1.0 Affichez, gérez et diagnostiquez les conteneurs dans Visual Studio. Visual Studio Tools pour Conteneurs 1.0 Visual Studio Tools pour Conteneurs Visual Studio Tools pour Docker 1.1 Développez, exécutez et validez vos applications ASP.NET Core dans l'environnement cible. Appuyez sur F5 pour exécuter votre application directement dans un conteneur avec débogage ou sur CTRL+F5 pour modifier et actualiser votre application sans avoir à recréer le conteneur. Visual Studio Tools pour Kubernetes 1.0 Visual Studio Tools pour Kubernetes VisualStudio.DeviceLog 1.0 Informations sur mon paquet VisualStudio.Foo 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio Xamarin 16.8.000.261 (d16-8@bb99248) Extension Visual Studio permettant de développer pour Xamarin.iOS et Xamarin.Android. Xamarin Designer 16.8.0.507 (remotes/origin/d16-8@e87b24884) Extension Visual Studio pour activer les outils Xamarin Designer dans Visual Studio. Xamarin Templates 16.8.112 (86385a3) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.1.0.26 (d16-8/a36ce73) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-8@79d9533 ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc Xamarin.iOS and Xamarin.Mac SDK 14.8.0.3 (c51fabee8) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Screenshots

Reproduction Link

Type this code in MainPage of Empty Xamarin.Forms application (5.0.0.2012) and implement Button_Clicked to invert IsVisible value of the BlueRectangle : ` <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ScrollBug.MainPage">

<ScrollView>
    <Grid
        RowDefinitions="400,Auto,*">

        <Rectangle
            Background="Red"
            HeightRequest="400" />
        <Button
            Grid.Row="1"
            Text="Hide/Show blue rectangle"
            Clicked="Button_Clicked" />
        <Rectangle
            Grid.Row="2"
            x:Name="BlueRectangle"
            IsVisible="False"
            HeightRequest="500"
            Background="Blue" />
    </Grid>
</ScrollView>

`

Workaround

Call InvalidateMesure on child

azrinsani commented 3 years ago

I think this is expected. That's why grid is the recommended layout vs stacklayout. Stack layout initiates the invalidatemeasure call on each state change.

Conclusions

A child of a stacklayout will always cause a full layout cycle, there’s no way a StackLayout can short circuit this cycle. A child of a Grid with that’s inside rows and columns with static or star widths AND the LayoutOptions are set to Fill, are fully constrained which means that the invalidation cycle will be stopped at that child view. In order to have children of a Grid change layout dynamically they need to be a child of another View which is fully constrained. (As per the Grid sample).

Read more here:

https://michaelridland.com/xamarin/hacking-the-xamarin-forms-layout-system-for-fun-and-profit/

RenaudAvenas commented 3 years ago

Images are better than words ^^ : Screen1 After the button clicked : Screen2 After scrolling down : Screen3

Expected : Screen4

RenaudAvenas commented 3 years ago

The code to reproduce : ScrollBug.zip

RenaudAvenas commented 3 years ago

I think this is expected. That's why grid is the recommended layout vs stacklayout. Stack layout initiates the invalidatemeasure call on each state change.

Conclusions

A child of a stacklayout will always cause a full layout cycle, there’s no way a StackLayout can short circuit this cycle. A child of a Grid with that’s inside rows and columns with static or star widths AND the LayoutOptions are set to Fill, are fully constrained which means that the invalidation cycle will be stopped at that child view. In order to have children of a Grid change layout dynamically they need to be a child of another View which is fully constrained. (As per the Grid sample).

Read more here:

https://michaelridland.com/xamarin/hacking-the-xamarin-forms-layout-system-for-fun-and-profit/

The StackLayout has no incidence, I change the code to have only a grid, same bug