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 with ScrollView VerticalOptions="Center" not growing to fit contents on iOS #23084

Open
krime81 opened this issue Jun 17, 2024 · 2 comments
Labels
area-controls-scrollview ScrollView platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@krime81
Copy link

krime81 commented Jun 17, 2024

Description

When a ScrollView has dynamic contents ( in this example, a view that is growing in size, or made visible )
it doesnt grow to fit its contents on iOS, but it does on Android

Steps to Reproduce

Create a xaml file with following contents
`

<ScrollView VerticalOptions="Center" Background="Red" Padding="10">
    <VerticalStackLayout BackgroundColor="Aqua"
        Padding="30,0"
        Spacing="25">
        <Frame x:Name="hiddenAtFirst" BackgroundColor="Green" HeightRequest="200" IsVisible="false"/>
        <Frame BackgroundColor="Blue" HeightRequest="200" IsVisible="true"/>

        <Button
            x:Name="MakeVisibleButton"
            Text="Click me to grow" 
            Clicked="OnMakeVisibleButtonClicked"
            HorizontalOptions="Fill" />
    </VerticalStackLayout>
</ScrollView>
`

with codebehind :
`namespace mauiscrollissue;

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

private void OnMakeVisibleButtonClicked(object sender, EventArgs e)
{
    hiddenAtFirst.IsVisible = true;
    hiddenAtFirst.HeightRequest += 100;
}

}
`

On tapping the button,
-on Android the scrollview grows until it reaches the max height, and then shows the scrolling behavior
-on iOS the scrollview doesnt grow and immediately shows scrolling behavior

Link to public reproduction project repository

https://github.com/krime81/mauiscrollissue

Version with bug

9.0.0-preview.1.9973

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

add this handler :
` Microsoft.Maui.Handlers.ScrollViewHandler.Mapper.AppendToMapping(nameof(IScrollView.ContentSize), (h, v) =>
{
var contentSize = h.VirtualView.ContentSize;

            if (contentSize.IsZero)
				return;

			UIKit.UIScrollView uiScrollView = h.PlatformView;
			var container = uiScrollView.Subviews.FirstOrDefault(x => x.Tag == 0x845fed);			

			if (container != null && container.Bounds.Height != contentSize.Height)
			{
				container.Bounds = new CoreGraphics.CGRect(
					container.Bounds.X,
					container.Bounds.Y, 
					contentSize.Width, 
					contentSize.Height);

				(h.VirtualView as IView).InvalidateMeasure();
			}
		});
			`

note that this might affect other instances of the scrollview in your projects

Relevant log output

No response

@krime81 krime81 added the t/bug Something isn't working label Jun 17, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@RoiChen001 RoiChen001 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jun 17, 2024
@RoiChen001
Copy link

Can repro this issue at iOS platform on the latest 17.10.2(9.0.0-preview.5.24307.10)
23084

@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-scrollview ScrollView platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants