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 and VerticalStackLayout do not resize themselves on iOS #8820

Closed
ammar-madni opened this issue Jul 18, 2022 · 17 comments
Closed

ScrollView and VerticalStackLayout do not resize themselves on iOS #8820

ammar-madni opened this issue Jul 18, 2022 · 17 comments
Labels

Comments

@ammar-madni
Copy link

Description

ScrollView and VerticalStackLayout do not resize themselves on iOS as they do on Android.

On toggling a control that is initially visible to be hidden. There is a blank space left where the control used to be.

If the control is set to be hidden initially and then toggled to be visible. The VerticalStackLayout and ScrollView do not resize to take into account the size of the now visible control.

Screenshot 2022-07-18 at 18 06 17

Steps to Reproduce

Clone repo https://github.com/ammar-madni/MauiResizeIssueIOS

Run on android to see intended result.

Run on iOS to see the issue on iOS.

Version with bug

6.0.408 (current)

Last version that worked well

6.0.312

Affected platforms

iOS

Affected platform versions

iOS 15.5

Did you find any workaround?

I have added a margin to the bottom of the last element in VStack. This margin gets used up when the Hidden Control is toggled to be visible.

Relevant log output

No response

@ammar-madni ammar-madni added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jul 18, 2022
@Eilon Eilon added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Jul 18, 2022
@rmarinho
Copy link
Member

rmarinho commented Jul 20, 2022

I just tested on Sr3 (6.0.409) and it's almost working , it seems the VerticalSttackLayout resizes fine, but the Scrollview doesn't.
Simulator Screen Shot - iPhone 13 - 2022-07-20 at 12 34 36

@rmarinho
Copy link
Member

@hartez any idea what is missing here?

@rmarinho rmarinho added platform/iOS 🍎 and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jul 20, 2022
@hartez hartez self-assigned this Jul 20, 2022
@hartez hartez removed their assignment Aug 2, 2022
@svaldetero-envoc
Copy link

svaldetero-envoc commented Aug 10, 2022

I also have this issue. My use case is I have a screen full of content with buttons at the bottom. In the middle of the screen, there is a label with LineBreakMode="WordWrap" inside of a Grid with the RowHeight set to Star. When the text of that label wraps beyond one line, the content of the scrollview increases that many pixels past the height of the scrollview. Essentially two line wraps and the bottom button is pushed off the screen. You can pull the scrollview to see the button but when you let go, it snaps back below the screen.

Basic structure (attributes removed for brevity):

    <ScrollView >
        <VerticalStackLayout >
            <Frame>
                <Grid
                    ColumnDefinitions="2*,3*"
                    RowDefinitions="*,*,*,*,*,*,*,*,*,*,*,*">

                    <!-- lots of content -->

                    <Label Grid.Column="1" Grid.Row="12" Text="{Binding LotsOfText}" LineBreakMode="WordWrap" />
                </Grid>
            </Frame>

            <!-- lots of content -->
            
            <Button />
            <Button  />
        </VerticalStackLayout>
    </ScrollView>

This is really frustrating because now I have to change how the information is laid out on the screen so that the users can tap the button at the bottom. I will most likely have to do a fixed height on the label/GridRow that should account for the most amount of text we should have but that leaves a ton of whitespace if there isn't any text.

@hartez hartez added the area-controls-scrollview ScrollView label Oct 9, 2022
@EPS-Lac
Copy link

EPS-Lac commented Oct 12, 2022

I also had this issue and I could resolve it by manually calling the layout update on the scrollview.
In my case I have a VerticalStackLayout using BindableLayout.ItemsSource where items are added and removed dynamically. So I think this should work similar to switching between hidden and visible items.

<ScrollView x:Name="ScrollView"><VerticalStackLayout>...</VerticalStackLayout></ScrollView>

In the code behind I added this:
private void OnItemsChanged(object sender, EventArgs e) { (ScrollView as IView).InvalidateMeasure(); }

Hope this works for you, too!

@jcsnider
Copy link

jcsnider commented Oct 12, 2022

Thank you @EPS-Lac for the share. I was facing a similar issue with dynamically expanding/resizing web views within scroll views described here.

Using your example I was able to work around this issue by manually notifying any parent ScrollViews to invalidate their measures.

@nicjay
Copy link

nicjay commented Oct 12, 2022

In the code behind I added this: private void OnItemsChanged(object sender, EventArgs e) { (ScrollView as IView).InvalidateMeasure(); }

Hope this works for you, too!

Very nice solution. I had an async data loading situation, invoking the InvalidateMeasure() via an Action from my ViewModel did the trick.

@EPS-Lac
Copy link

EPS-Lac commented Oct 17, 2022

I think it works well if you bind the OnItemsChanged to the SizeChanged event of the VerticalStackLayout.
Just noticed it in one case, but that's probably the same for all cases.

@borrmann
Copy link
Contributor

@EPS-Lac thank you for the workaround, it works really well!

However, in my solution, SizeChanged does not work, but if I use PropertyChanged instead, it does.
I also needed to add a null check in my event handler:

<ScrollView x:Name="scrollView">
      <VerticalStackLayout PropertyChanged="VerticalStackLayout_PropertyChanged">

private void VerticalStackLayout_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
      (scrollView as IView)?.InvalidateMeasure();
}

This gets called quite often, but still better than an unaccesible view.

@FM1973
Copy link

FM1973 commented Dec 20, 2022

@EPS-Lac
oh man, thanks a lot! I was looking for a workaround for this bug a long time!

durandt pushed a commit to durandt/maui-issue2-ios-stacklayout-scroll that referenced this issue Dec 22, 2022
@durandt
Copy link

durandt commented Dec 22, 2022

Wonder if this is a duplicate of #9209 ?

Another repro here: https://github.com/durandt/maui-issue2-ios-stacklayout-scroll

@AdamBebko
Copy link

AdamBebko commented Dec 30, 2022

A similar thing seems to occur for me in a BindableLayout. When I add items beyond the size of the screen the parent scrollview doesn't seem to expand. I was able to fix this using the above workaround. I added a few modifications. I have posted them below in case anyone is interested.

in xaml:

    <ScrollView x:Name="MainScrollView">
        <StackLayout x:Name="MainLayout">
            <StackLayout BindableLayout.ItemsSource="{Binding Items}">
                <!-- etc.. -->

in xaml.cs:

	protected override void OnAppearing()
	{
		base.OnAppearing();
		MainLayout.PropertyChanged += UpdateView;
	}

	protected override void OnDisappearing()
	{
		base.OnDisappearing();
		MainLayout.PropertyChanged -= UpdateView;
	}

	void UpdateView(object sender, PropertyChangedEventArgs e)
	{
		(MainScrollView as IView)?.InvalidateMeasure();
	}

@hartez
Copy link
Contributor

hartez commented Mar 13, 2023

With the latest stable version (17.5) iOS now works the same as Android.

@hartez hartez closed this as completed Mar 13, 2023
@FM1973
Copy link

FM1973 commented Mar 25, 2023

@hartez I´m not sure the bug has gone away.
When I have a ScrollView and a VerticalStackLayout inside and load content dynamically, i.e. some text (using an async function) and at the bottom of the VerticalStackLayout there is a button, the command never gets fired when the button is clicked. One can see the Button, but it´s handler doesn´t get called.
When I reapply @borrmann ´s workaround, the handler gets called.

@ghost
Copy link

ghost commented Mar 25, 2023

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

@borrmann
Copy link
Contributor

@FM1973 +1!!

@hartez
Copy link
Contributor

hartez commented Mar 28, 2023

@FM1973 @borrmann This sounds like it might be a slightly different issue (since you can see the button).

Can you open a new issue with a repro specific to this problem? Thanks!

@FM1973
Copy link

FM1973 commented Mar 29, 2023

@hartez
Ok, I opened a new issue. #14257
I still think it´s the same problem.
And please no "duplicate issue ping pong"!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 28, 2023
@Eilon Eilon removed the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label May 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests