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

ScrollView doesn't work properly on Android. #7590

Closed
Dan-Banfield opened this issue May 29, 2022 · 20 comments
Closed

ScrollView doesn't work properly on Android. #7590

Dan-Banfield opened this issue May 29, 2022 · 20 comments
Assignees
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/android 🤖 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@Dan-Banfield
Copy link

Dan-Banfield commented May 29, 2022

Description

When I wrap a ScrollView around a VerticalStackLayout in Android specifically, or any other control really, if the controls exceed the viewing area, it's not possible to scroll, and everything is simply truncated. https://i.imgur.com/fwfnTfi.png This same project works completely fine on Windows, though, and scrolling works perfectly. Here is the xaml:

<ScrollView>
        <VerticalStackLayout 
            Spacing="16" 
            Padding="30,30" 
            VerticalOptions="Start">

            <Label
                x:Name="titleLabel"
                FontSize="32"
                FontFamily=""
                FontAttributes="Bold"
                Text="Loading..." />

            <Label
                x:Name="descriptionLabel"
                FontSize="18"
                FontFamily=""
                FontAttributes="None"
                Text="Loading..." />

            <Image
                x:Name="apodImage"
                Margin="0, 30"
                Source="loading.png"
                HeightRequest="200"
                Aspect="AspectFit" />

            <Button
                x:Name="refreshButton"
                IsEnabled="False"
                Text="Refresh" 
                Clicked="refreshButton_Clicked" />

            <Button
                x:Name="shareButton"
                IsEnabled="False"
                Text="Share" 
                Clicked="shareButton_Clicked" />

        </VerticalStackLayout>
    </ScrollView>

Thanks for your time!

(Top part of the code which keeps getting cut off): image

Steps to Reproduce

  1. Create a new .NET MAUI project.
  2. In the default VerticalStackLayout, add some controls and then change their initial size at runtime.
  3. Run the project on Android.

Version with bug

6.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

All Android versions

Did you find any workaround?

edit see: #7590 (comment)

Relevant log output

No response

@Dan-Banfield Dan-Banfield added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 29, 2022
@leoderja
Copy link

the code you posted, is incomplete and do not produces the image that you shared...

@Dan-Banfield
Copy link
Author

Dan-Banfield commented May 29, 2022

the code you posted, is incomplete and do not produces the image that you shared...

Hi, sorry, the top part of the code is as follows (it keeps getting cut off when posted): image
And as for the title label and description label, I'm simply setting their text to that of the APOD feature from the NASA API. In doing so, the ScrollView cuts off, not enabling scrolling, and the buttons and other controls get hidden. In other words, when the second label has lots of text, it cuts off the ScrollView. The ScrollView also can't scroll.

@fsdsabel
Copy link

I think it's a problem with updating the size of controls inside of a ScrollView after initial layout. I just wanted to open an issue myself. I can easily reproduce it like so:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage  xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:html="http://schemas.microsoft.com/dotnet/2021/mauilitehtml"   
              xmlns:local="clr-namespace:LiteHtmlMaui.TestApp"
             x:Class="Maui.TestApp.DynamicPage">
    <ContentPage.Content>
        <ScrollView VerticalScrollBarVisibility="Always">
            <StackLayout>
                <BoxView HeightRequest="100" x:Name="bd"></BoxView>
                <Button Text="Click" Clicked="Button_Clicked"></Button>
            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

code behind:

public partial class DynamicPage : ContentPage
{
	public DynamicPage()
	{
		InitializeComponent();    
	}

    private void Button_Clicked(object sender, EventArgs e)
    {
        bd.HeightRequest = 10000;
    }
}

After clicking the button the button is gone and no scrolling is possible. This happens on Android and iOS but is fine on Windows.

@Dan-Banfield
Copy link
Author

I think it's a problem with updating the size of controls inside of a ScrollView after initial layout. I just wanted to open an issue myself. I can easily reproduce it like so:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage  xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:html="http://schemas.microsoft.com/dotnet/2021/mauilitehtml"   
              xmlns:local="clr-namespace:LiteHtmlMaui.TestApp"
             x:Class="Maui.TestApp.DynamicPage">
    <ContentPage.Content>
        <ScrollView VerticalScrollBarVisibility="Always">
            <StackLayout>
                <BoxView HeightRequest="100" x:Name="bd"></BoxView>
                <Button Text="Click" Clicked="Button_Clicked"></Button>
            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

code behind:

public partial class DynamicPage : ContentPage
{
	public DynamicPage()
	{
		InitializeComponent();    
	}

    private void Button_Clicked(object sender, EventArgs e)
    {
        bd.HeightRequest = 10000;
    }
}

After clicking the button the button is gone and no scrolling is possible. This happens on Android and iOS but is fine on Windows.

Thanks for also bringing this up!

@paulvarache
Copy link

This might be related to this issue I flagged a few days ago #7322
This issue specifically mentions using IsVisible, but if related to the content sizing not updating it might be the same bug

@Dan-Banfield
Copy link
Author

This might be related to this issue I flagged a few days ago #7322 This issue specifically mentions using IsVisible, but if related to the content sizing not updating it might be the same bug

Yeah, I think it's anything related to resizing which causes the ScrollView to break because it works fine initially but I update the data with some fetched from an API, and it overflows and breaks.

@angelru
Copy link

angelru commented May 31, 2022

if you use a Grid does the same thing happen?

@Dan-Banfield
Copy link
Author

if you use a Grid does the same thing happen?

Haven't tried a Grid yet, but from what I understand, it's any control inside of a ScrollView that's size gets changed from its initial value.

@fsdsabel
Copy link

Tried it with Grid:

<Grid RowDefinitions="Auto,Auto" VerticalOptions="FillAndExpand">         
                <Frame x:Name="html"  HeightRequest="1000" BackgroundColor="Red"/>
                <Button Grid.Row="1" Clicked="Button_Clicked"></Button>
            </Grid>

Makes no difference on Android but is even more broken on Windows. On Windows it doesn't even render correctly initially.

@XamerDev
Copy link

same here, scrolling doesnt work when we have verticalstacklayout inside scrollView. On android doesnt work at all, on Windows works ok. One thing when I populate data during initialization in constructor scrolling works properly so it seems that the problems is in "resizing" layout after initialization

@Dan-Banfield
Copy link
Author

same here, scrolling doesnt work when we have verticalstacklayout inside scrollView. On android doesnt work at all, on Windows works ok. One thing when I populate data during initialization in constructor scrolling works properly so it seems that the problems is in "resizing" layout after initialization

Yup. Exactly the same here. A really big problem actually; I don't even know how this went unnoticed?

@Eilon Eilon added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label May 31, 2022
@CobaltGoldCS
Copy link

There are a ton of issues relating to the resizing of scrollView that I have been able to find, and all of them seem to have something to do with resizes.
#6959 #7322

@VincentBu
Copy link

repro with vs main build 32601.361.main on Android emulator & IOS emulator

@VincentBu VincentBu added s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 2, 2022
@Quietscheente
Copy link

Also massive scrolling problems on Android. What always worked for me as a workaround to not get stuck in project development is hold phone landscape and back again.

@jameskolts
Copy link

Have this issue as well

@philipag
Copy link

same issue here

@hartez hartez added this to the 6.0-sr3 milestone Jun 22, 2022
@fyndor
Copy link

fyndor commented Jun 23, 2022

This is my workaround for now. Every time I do something in my ViewModel that I know should affect the vertical height of the page, I call an Action that I assign to this method. By setting the Content property to null, and then back to it's value as defined in XAML, it recalculates it's size and works properly.

private void NotifyScrollChanged()
{
    var content = ScrollViewCtrl.Content;
    ScrollViewCtrl.Content = null;
    ScrollViewCtrl.Content = content;
}

@Dreamescaper
Copy link

It's probably the same issue which was fixed in XF some time ago
xamarin/Xamarin.Forms#14569

@leoderja
Copy link

This is my workaround for now. Every time I do something in my ViewModel that I know should affect the vertical height of the page, I call an Action that I assign to this method. By setting the Content property to null, and then back to it's value as defined in XAML, it recalculates it's size and works properly.

private void NotifyScrollChanged()
{
    var content = ScrollViewCtrl.Content;
    ScrollViewCtrl.Content = null;
    ScrollViewCtrl.Content = content;
}

Thank you, Greg!... your solution magically came to me at the right time...

@jfversluis jfversluis self-assigned this Jul 6, 2022
@jfversluis
Copy link
Member

Checked on the latest code, this seems to work there. The fix should be included in the next service release!

@ghost ghost locked as resolved and limited conversation to collaborators Aug 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/android 🤖 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests