Skip to content

fix mouse wheel scroll miscontrol of ScrollPosition.#66039

Merged
fluttergithubbot merged 40 commits intoflutter:masterfrom
YeungKC:Fix_Mouse_Scroll_miscontrol_of_ScrollPosition
Nov 2, 2020
Merged

fix mouse wheel scroll miscontrol of ScrollPosition.#66039
fluttergithubbot merged 40 commits intoflutter:masterfrom
YeungKC:Fix_Mouse_Scroll_miscontrol_of_ScrollPosition

Conversation

@YeungKC
Copy link
Member

@YeungKC YeungKC commented Sep 17, 2020

Description

Trying to solve #55362 and #64266.

The handling of PointerSignalEvent in Scrollable is directly derived from the current ScrollPosition.pixels + delta, while NestedScrollView contains multiple ScrollPositions, and NestedScrollView contains multiple ScrollPosition. It doesn't make sense to calculate the target value alone.
So I've changed it to pass the delta directly to ScrollPosition and let ScrollPosition handle it internally.

About #64266, The original PointerSignalEvent was handled by call ScrollPosition.jumpTo which did not update ScrollDirection.forward or ScrollDirection.reverse, now it is handled by call ScrollPosition.jumpTo which does not update ScrollDirection.forward or ScrollDirection.reverse. call beginActivity, now it will update ScrollDirection.forward normally.

Related Discord: https://discordapp.com/channels/608014603317936148/608018585025118217/755515518294687844

Related Issues

Fixes #55362
#64266

Replace this paragraph with a list of issues related to this PR from our issue database. Indicate, which of these issues are resolved or fixed by this PR. There should be at least one issue listed here.

Tests

I added the following tests:

  • scrollable_test.dart
    • Holding scroll and Scroll pointer signal will update ScrollDirection.forward / ScrollDirection.reverse
  • nested_scroll_view_test.dart
    • Holding scroll and Scroll pointer signal will update ScrollDirection.forward / ScrollDirection.reverse
    • Scroll Pointer signals should not cause overscroll

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@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.

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

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 17, 2020
@Piinks Piinks added a: mouse Issues related to using a mouse or mouse support f: scrolling Viewports, list views, slivers, etc. a: desktop Running on desktop labels Sep 22, 2020
@Piinks
Copy link
Contributor

Piinks commented Sep 22, 2020

It looks like @dkwingsmt may be more familiar with the failing pointer tests here.

Regarding writing a test for this, this test checks the pointer scroll event, we can modify this test to use a NestedScrollView and validate the behavior:

testWidgets('Scroll pointer signals are handled on Fuchsia', (WidgetTester tester) async {

@Piinks
Copy link
Contributor

Piinks commented Sep 22, 2020

It doesn't make sense to calculate the target value alone.

Can you clarify? I am wondering if what we may need here is to deploy some of the unnesting methods in the NestedScrollView to calculate the 'true' position. I am not sure if that would work, but it may be a simpler approach that isn't breaking.

@YeungKC
Copy link
Member Author

YeungKC commented Sep 22, 2020

@Piinks

Do you mean to leave Scrollable unchanged and have _NestedScrollPosition return 'true' pixels?

I think this may be difficult.

  1. because ScrollPosition.pixels involves more code.
  2. if we go to Scrollable and additionally determine Position as _NestedScrollPosition, this may not be very elegant.
  3. Originally Scrollable used Position.jumpTo, which caused [web][desktop] Scrolling with 2 fingers (not press&hold style) categorized as ScrollDirection.idle (instead of ScrollDirection.forward or ScrollDirection.reverse) #64266 to occur.

@Piinks
Copy link
Contributor

Piinks commented Sep 22, 2020

Ah ok. Do you think it is possible to separate this out into two pull requests? This appears to be trying to solve two different issues.

@YeungKC
Copy link
Member Author

YeungKC commented Sep 22, 2020

I don't think so, as pointerScroll instead of jumpTo is now the core code for the solution to both issues.

@Piinks
Copy link
Contributor

Piinks commented Sep 22, 2020

I don't think so, as pointerScroll instead of jumpTo is now the core code for the solution to both issues.

Is it possible you could add pointerScroll in one change, and then implement it additional changes to solve each issue? This will be much easier to review if it is only trying to solve one problem.

@YeungKC
Copy link
Member Author

YeungKC commented Sep 22, 2020

I don't think so, I don't think there's any other way, after adding pointerScroll, it actually solves two problems...

@YeungKC
Copy link
Member Author

YeungKC commented Sep 22, 2020

I may not have described it clearly before, but now I'll explain why not.

  1. added pointerScroll to fix Unexpected behaviour of SliverAppBar in NestedScrollView on Mouse Scroll #55362 calculation error pixels, and now it's handled internally by position.
  2. having also given it to internal handling, it also solves [web][desktop] Scrolling with 2 fingers (not press&hold style) categorized as ScrollDirection.idle (instead of ScrollDirection.forward or ScrollDirection.reverse) #64266, otherwise I would need to change the jumpTo code to add updateUserScrollDirection, as changing the jumpTo code would affect the expected effect of calling jumpTo properly.

So it can't be split into two PR. I hope I've made it clear to you this time.

cc @Piinks

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Sep 22, 2020

I'm pretty sure the test failure is because of the design that relies on scheduleMicrotask in the constructor. The test does not clear microtasks, therefore the jump is not executed.

I'm not an expert in scrollables but I don't think it's a good design. I suppose ScrollActivity is designed to be passive, only triggers side effects when certain events come, instead of during constructor and starts its own microtask.

@YeungKC
Copy link
Member Author

YeungKC commented Sep 23, 2020

Thanks for the review, but regarding the scheduleMicrotask not executing, I debug 'Scroll pointer signals are handled on Fuchsia' test and adding the scheduleMicrotask.callback breakpoint, which I'm pretty sure has already been executed.

I may have a different opinion about ScrollActivity, because there is BallisticScrollActivity, DrivenScrollActivity, and also the callback to init async in the constructor, which shows that ScrollActivity It's not necessary or recommended to do it passively.

But I agree that scheduleMicrotask is probably not the best way to go.

@YeungKC
Copy link
Member Author

YeungKC commented Sep 29, 2020

Now it' s been updated and improved for testing.
I apologize for the delay of a few days.

@YeungKC YeungKC requested a review from Piinks October 21, 2020 14:37
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Flutter_LGTM
This LGTM! Thank you for your contribution! This is a really great change.

There are some merge conflicts that will need to be resolved before we can merge it in.

…miscontrol_of_ScrollPosition

# Conflicts:
#	packages/flutter/test/widgets/nested_scroll_view_test.dart
@Piinks
Copy link
Contributor

Piinks commented Oct 30, 2020

Hey @YeungKC can you check your branch? It looks like there was an issue when you rebased.

@Piinks
Copy link
Contributor

Piinks commented Oct 30, 2020

Hey @YeungKC I'm sorry to ask again, but can you update once more? It looks like your last update picked up a broken build that was fixed in #69426

@YeungKC
Copy link
Member Author

YeungKC commented Oct 30, 2020

It seems like I had already noticed it at the time, but at the time I wasn't sure if I was the only one experiencing the problem.

https://discord.com/channels/608014603317936148/613398423093116959/771433253529059438

It's updated now. I'm watching ci work.

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux web_long_running_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite framework_tests-widgets-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite framework_tests-libraries-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite framework_tests-misc-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

@YeungKC
Copy link
Member Author

YeungKC commented Nov 1, 2020

There were still some problems before, but now it can be merged.

cc @Piinks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop a: mouse Issues related to using a mouse or mouse support f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected behaviour of SliverAppBar in NestedScrollView on Mouse Scroll

6 participants