Skip to content

refactor: Centralize copying of drag events when handling scrollbar scrolling#186677

Open
luanpotter wants to merge 1 commit into
flutter:masterfrom
luanpotter:luan.scrolls2
Open

refactor: Centralize copying of drag events when handling scrollbar scrolling#186677
luanpotter wants to merge 1 commit into
flutter:masterfrom
luanpotter:luan.scrolls2

Conversation

@luanpotter

Copy link
Copy Markdown
Contributor

[this is a rethread of https://github.com//pull/181110]

addressing the comments:

  • data driven fix - I looked into this, but unfortunately I don't think it fits - it seems to key off of method name changes; signature-only changes do not appear to be supported. As I mentioned this is a trivial change in the guts of scrollbars, so while technically breaking change (if someone is extending it directly), end users probably wouldn't notice this, and anyone creating their own custom scrollbars have a clear path forward.
  • keeping both versions of the methods: I also considered this but that unfortunately doesn't help with the ultimate buttons goal, because anyone calling the old signature just doesn't give enough information to fully reconstruct the event. the reason for this change is to force callers to provide the entire event thus guaranteeing we have the info needed to propagate button (and better future proofing against any other such changes).
  • copyWith and nullability - agreeing with the confusing semantics of copyWith exposed by @Renzo-Olivares , so I just removed it. this makes this PR much simpler, and the final state still a bit "brittle", in the sense that future event additions need to be aware of updating the ad-hoc copies, but it is still a much nicer state than before, and fully unblocks my ultimate goal of exposing buttons, so I am happy with it.

[original description]

This PR changes the signatures of handleThumbPressStart, handleThumbPressUpdate, and handleThumbPressEnd, related to scrollbar handling, to take in a copy of the original event with the localPosition added inside, instead of separate fields.

This centralizes the copying of these events by the generic platform code (while still allowing some of them to re-copy based on implementation details), ensures that additional fields are propagated (such as kind when it exists, buttons when it is eventually added, and others) and simplifies the method signature significantly, future proofing it to future additions.

This was extracted from #176968 in an attempt to simplify it, and it will make it possible to add the missing buttons property to these events more easily.

Note: this is a public signature change but only if people are creating their own custom scrollbar implementations (?) without using either the material or cupertino ones; and on top of that should be very trivial to fix. But please advise if there are concerns.

Note: this has no test changes because it is a refactor which should have zero change in behaviour; the existing tests passing is proof of it working.

Note: this PR assumes that the renderBox.localToGlobal(localPosition) computation that was previously done was essentially the reverse of the global -> local computation, so essentially the flow was global --(global to local)--> local --(local to global)--> global (the second step being there just because we didn't provide the original global to the method). So this is saving a computation step and should not change the behaviour. I will let the tests be the judge of this assumption but please let me know if there are concerns.

Pre-launch Checklist

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

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. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. f: cupertino flutter/packages/flutter/cupertino repository labels May 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the scrollbar thumb press handlers in RawScrollbarState and its subclasses to use DragStartDetails, DragUpdateDetails, and DragEndDetails instead of raw Offset and Velocity values, centralizing the calculation of local coordinates. Feedback suggests implementing a helper method for recreating these detail objects to reduce duplication and the risk of missing fields in future framework updates.

Comment on lines 1786 to 1793
final scrollDetails = DragUpdateDetails(
delta: delta,
primaryDelta: primaryDelta,
globalPosition: renderBox.localToGlobal(localPosition),
localPosition: localPosition,
globalPosition: details.globalPosition,
localPosition: details.localPosition,
sourceTimeStamp: details.sourceTimeStamp,
kind: details.kind,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this refactor aims to centralize copying, manually creating a new DragUpdateDetails instance here (and in _handleThumbDragUpdate) means that any future fields added to DragUpdateDetails (like buttons) will need to be manually added in multiple places. Since DragUpdateDetails does not have a copyWith method, this is currently necessary, but it highlights the brittleness mentioned in the PR description.

Consider if a helper method for copying DragUpdateDetails with specific overrides would be beneficial to reduce duplication and the risk of missing fields in the future.

@Piinks Piinks added the Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. label Jun 24, 2026
@Piinks

Piinks commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I've marked this PR as not ready to port to flutter/packages yet.
We'll provide instructions to move this change over to material_ui/cupertino_ui once ready to receive PRs. Thank you!

The changes not in the material or cupertino libraries will remain here.

@Piinks Piinks added the Decoupling: Split PR The PR will need to be split to separate Material & Cupertino changes label Jun 25, 2026
@Piinks

Piinks commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Advice for PR splitting: Since this touches material/cupertino along with other parts of flutter/flutter, it will need to be split up.

If the material/cupertino changes are dependent on the other non-material/cupertino changes in this PR, then the material/cupertino changes will need to wait for them to roll to stable before they can be ported over to material_ui/cupertino_ui in flutter/packages (which uses the stable branch).

  • If that is the case here, consider opening a new PR with the non-material/cupertino changes to move forward with so that waiting period can be reduced. Up to you!

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

Labels

Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. Decoupling: Split PR The PR will need to be split to separate Material & Cupertino changes f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. 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.

3 participants