Skip to content

MauiScrollView resets ContentOffset on first layout pass - fix #30453

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Jul 6, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

@mjo151 could you please verify if this PR fixes your issue, since you did not provide your repro so that I can test it
https://github.com/dotnet/maui/wiki/Testing-PR-Builds

Issues Fixed

Fixes #30147

@Copilot Copilot AI review requested due to automatic review settings July 6, 2025 23:12
@kubaflo kubaflo requested a review from a team as a code owner July 6, 2025 23:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR prevents MauiScrollView on iOS from inadvertently resetting its scroll position on the very first layout pass by adding an explicit check against _previousEffectiveUserInterfaceLayoutDirection.

  • Introduces a guard so that on the initial layout pass (when _previousEffectiveUserInterfaceLayoutDirection is null), ContentOffset isn’t reset.
  • Ensures that on subsequent layout passes (when the layout direction is known), the old scroll offset logic still applies.
Comments suppressed due to low confidence (1)

src/Core/src/Platform/iOS/MauiScrollView.cs:67

  • Consider adding a unit test to verify that on the initial layout pass (when _previousEffectiveUserInterfaceLayoutDirection is null) the ContentOffset remains unchanged, and that on subsequent passes it resets correctly.
					else if (_previousEffectiveUserInterfaceLayoutDirection is not null)

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jul 6, 2025
Copy link
Contributor

Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@PureWeen
Copy link
Member

PureWeen commented Jul 6, 2025

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@@ -64,7 +64,7 @@ public override void LayoutSubviews()
crossPlatformLayout.CrossPlatformArrange(new Rect(new Point(-horizontalOffset, 0), crossPlatformBounds));
ContentOffset = new CGPoint(horizontalOffset, 0);
}
else
else if (_previousEffectiveUserInterfaceLayoutDirection is not null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjo151 If you try this, could you share a repro sample? Would like to include a related test.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the build from this PR and it appears to fix the issue. I will see if I can create a simple repo sample.

@PureWeen
Copy link
Member

PureWeen commented Jul 7, 2025

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen added this to the .NET 9 SR9 milestone Jul 7, 2025
@PureWeen PureWeen moved this from Todo to In Progress in MAUI SDK Ongoing Jul 7, 2025
@PureWeen PureWeen moved this from In Progress to Ready To Review in MAUI SDK Ongoing Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-scrollview ScrollView community ✨ Community Contribution
Projects
Status: Ready To Review
Development

Successfully merging this pull request may close these issues.

MauiScrollView resets ContentOffset on first layout pass in 9.0.80
4 participants