Skip to content

Conversation

@Piinks
Copy link
Contributor

@Piinks Piinks commented May 26, 2023

(plus some more docs)

Fixes #76760
Fixes #82391
Fixes #45619
Fixes #117316
Fixes #110956
Fixes #127282
Fixes #32563
Fixes #46089
Fixes #79077
Part of fixing #62833

This fixes (a bunch of) issues that have been reported differently over the years, but all have the same root cause. Sometimes the NestedScrollView would incorrectly calculate whether or not there is enough content to allow scrolling. This would only apply to drag scrolling (not mouse wheel scrolling for example). This did not relate to how the extent of the NestedScrollView is computed, but just the logic that enabled the actual drag gestures. This fixes that. :)

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels May 26, 2023
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@github-actions github-actions bot removed f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels May 26, 2023
@Piinks
Copy link
Contributor Author

Piinks commented May 26, 2023

Still scanning issues to see if there are other test cases here, it looks like this has been reported a lot of different ways over the years. @nt4f04uNd and @xu-baolin might like to see this, no worries if you are unavailable to check it out, but if you can I'd be interested to see what you think. :)

@Piinks Piinks added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. a: quality A truly polished experience labels May 26, 2023
@xu-baolin xu-baolin self-requested a review May 29, 2023 12:37
|| totalInnerExtent > (viewportDimension - maxScrollExtent)
// There is no outer extent. The inner extent was computed based on the
// full viewport dimension and is accurate for the whole NestedScrollView.
|| (maxScrollExtent == 0 && totalInnerExtent > 0);
Copy link
Member

Choose a reason for hiding this comment

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

I think I need time to check if this change works for all the problem cases 😄

Will feedback in the next few days.

}
maxInnerExtent = math.max(
maxInnerExtent,
position.maxScrollExtent - position.minScrollExtent,
Copy link
Member

Choose a reason for hiding this comment

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

In fact, maxInnerExtent is not the total extension of the inner scrollable, but the maximum scrolling space inside, right?

final double maxScrollExtent = this.maxScrollExtent + overlapExtent;
final bool extentAllows =
// There is already room to scroll in the outer scroll view.
minScrollExtent != maxScrollExtent
Copy link
Member

Choose a reason for hiding this comment

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

This should be this.minScrollExtent != this.maxScrollExtent.
Thinking of this case, the overlapExtent > 0(just pinned the sliver bar) and the inner scrollable has a little extent that can not scrolling, we should not set this can drag, right?

minScrollExtent != maxScrollExtent
// The inner extent exceeds the bounds of the viewport, accounting for the
// outer extent.
|| totalInnerExtent > (viewportDimension - maxScrollExtent)
Copy link
Member

Choose a reason for hiding this comment

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

If this is right, we just should change extentAllows to

final bool extentAllows = this.minScrollExtent != this.maxScrollExtent || totalInnerExtent > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I realized this is not accounting for the physics at all! Which reminded me of #82391... so I changed it to what i think it should really be. Even if the extent is not enough to scroll, I don't want to completely ignore AlwaysScrollableScrollPhysics, which should always scroll even if it is not long enough.

// app bar should not have to consume scrolling before the inner body of the
// NestedScrollView scrolls. However, when calculating the drag here, 0
// could result in scrolling being disabled unexpectedly if the inner scroll
// view by itself were not long enough to allow scrolling on its own.
Copy link
Member

Choose a reason for hiding this comment

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

Great comment!
I have to admit that this was pretty tricky for me to wrap my head around this ;-)

I am not very familiar with the internals of NestedScrollView, so I'll leave this to @xu-baolin to review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually able to make it even simpler. :)

auto-submit bot pushed a commit that referenced this pull request Jun 1, 2023
Adds an error message where we previously would crash without any help.
Came across this while working on #127718
Fixes #128074
@Piinks Piinks changed the title WIP - Fix nested computation of drag in NestedScrollView Fix update drag error that made NestedScrollView un-scrollable Jun 2, 2023
@Piinks Piinks added the f: gestures flutter/packages/flutter/gestures repository. label Jun 2, 2023
@github-actions github-actions bot removed the f: gestures flutter/packages/flutter/gestures repository. label Jun 2, 2023
@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 2, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 3, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Jun 3, 2023

auto label is removed for flutter/flutter, pr: 127718, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 5, 2023
@auto-submit auto-submit bot merged commit 9a26346 into flutter:master Jun 5, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 7, 2023
Roll Flutter from 0b74153 to 8a5c22e (46 revisions)

flutter/flutter@0b74153...8a5c22e

2023-06-07 [email protected] Super tiny MediaQuery doc update (flutter/flutter#127904)
2023-06-07 [email protected] Revert "Make inspector weakly referencing the inspected objects." (flutter/flutter#128436)
2023-06-07 [email protected] Update menu API docs to help developers migrate to m3 (flutter/flutter#128351)
2023-06-07 [email protected] [tools] allow explicitly specifying the JDK to use via a new config setting (flutter/flutter#128264)
2023-06-07 [email protected] Roll Flutter Engine from 6f9df0f988c1 to 59d5444cf06c (3 revisions) (flutter/flutter#128376)
2023-06-07 [email protected] Do not try to load main/default asset image if only higher-res variants exist (flutter/flutter#128143)
2023-06-07 [email protected] Addressed Ambiguity in transform.scale constructor docs (flutter/flutter#128182)
2023-06-07 [email protected] Super tiny fix of dead link (flutter/flutter#128160)
2023-06-07 [email protected] Refactor tests (flutter/flutter#128371)
2023-06-07 [email protected] Make inspector weakly referencing the inspected objects. (flutter/flutter#128095)
2023-06-07 [email protected] Add viewId to PointerEvents (flutter/flutter#128287)
2023-06-07 [email protected] Show error message in release mode when box is not laid out without losing performance (flutter/flutter#126302)
2023-06-06 [email protected] Roll Flutter Engine from ca499463ec2e to 6f9df0f988c1 (1 revision) (flutter/flutter#128363)
2023-06-06 [email protected] Update Draggable YouTube video link (flutter/flutter#128078)
2023-06-06 [email protected] Remove more rounding hacks from TextPainter (flutter/flutter#127826)
2023-06-06 [email protected] Roll Flutter Engine from 4571695f9e76 to ca499463ec2e (1 revision) (flutter/flutter#128356)
2023-06-06 [email protected] [Android] Update plugin and module templates to use Flutter constant for `compileSdkVersion` (flutter/flutter#128073)
2023-06-06 [email protected] handleSelectWord in MultiSelectableSelectionContainerDelegate should handle rects inside of rects (flutter/flutter#127478)
2023-06-06 [email protected] [flutter_tools] never tree shake 0x20 (space) font codepoints on web (flutter/flutter#128302)
2023-06-06 [email protected] Remove `textScaleFactor` dependent logic from `AppBar` (flutter/flutter#128112)
2023-06-06 [email protected] Roll Flutter Engine from b6d37f8f74ad to 4571695f9e76 (6 revisions) (flutter/flutter#128350)
2023-06-06 [email protected] Fix `Null check operator used on a null value` on TextField with contextMenuBuilder (flutter/flutter#128114)
2023-06-06 [email protected] Roll Packages from db4e5c2 to da72219 (10 revisions) (flutter/flutter#128348)
2023-06-06 [email protected] Updating cirrus docker image to ubuntu focal. (flutter/flutter#128291)
2023-06-06 [email protected] Adding example for migrating to navigation drawer (flutter/flutter#128295)
2023-06-06 [email protected] Roll Flutter Engine from 722aad83e5fe to b6d37f8f74ad (2 revisions) (flutter/flutter#128341)
2023-06-06 [email protected] Clean-up viewId casts in flutter_test (flutter/flutter#128256)
2023-06-06 [email protected] Update cherry-pick issue template to more uniform labels. (flutter/flutter#128333)
2023-06-06 [email protected] Use Material3 in the 2D viewport tests (flutter/flutter#128155)
2023-06-06 [email protected] Use a `show` over a `hide` for `test_api` exports (flutter/flutter#128298)
2023-06-06 [email protected] Roll Flutter Engine from aaa7574375a6 to 722aad83e5fe (1 revision) (flutter/flutter#128307)
2023-06-06 [email protected] Migration guide for moving from BottomNavigationBar to NavigationBar (flutter/flutter#128263)
2023-06-06 [email protected] [web] Use 'Uri' instead of 'dart:html' to extract pathname (flutter/flutter#127983)
2023-06-06 [email protected] Roll Flutter Engine from 2b353ae90731 to aaa7574375a6 (4 revisions) (flutter/flutter#128301)
2023-06-05 [email protected] Roll Flutter Engine from 220ece4d9faa to 2b353ae90731 (1 revision) (flutter/flutter#128293)
2023-06-05 49699333+dependabot[bot]@users.noreply.github.com Bump actions/labeler from 4.0.4 to 4.1.0 (flutter/flutter#128290)
2023-06-05 [email protected] Roll Flutter Engine from 7f12e3497428 to 220ece4d9faa (6 revisions) (flutter/flutter#128282)
2023-06-05 [email protected] [framework] attempt non-key solution (flutter/flutter#128273)
2023-06-05 [email protected] [labeler] Fix adding labels when name is directory (flutter/flutter#128243)
2023-06-05 [email protected] Remove scrollbar deprecations isAlwaysShown and hoverThickness (flutter/flutter#127351)
2023-06-05 [email protected] Fix update drag error that made NestedScrollView un-scrollable (flutter/flutter#127718)
2023-06-05 [email protected] Roll Flutter Engine from f9f72388a4da to 7f12e3497428 (4 revisions) (flutter/flutter#128271)
2023-06-05 [email protected] Migrate SemanticsBinding to onSemanticsActionEvent (flutter/flutter#128254)
2023-06-05 [email protected] Roll Flutter Engine from c838a1b05924 to f9f72388a4da (19 revisions) (flutter/flutter#128252)
2023-06-05 [email protected] [framework] force flexible space background to rebuild. (flutter/flutter#128138)
2023-06-05 [email protected] Roll Packages from 75085ed to db4e5c2 (4 revisions) (flutter/flutter#128246)
...
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment