refactor: Centralize copying of drag events when handling scrollbar scrolling#186677
refactor: Centralize copying of drag events when handling scrollbar scrolling#186677luanpotter wants to merge 1 commit into
Conversation
|
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. |
There was a problem hiding this comment.
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.
| 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, | ||
| ); |
There was a problem hiding this comment.
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.
|
I've marked this PR as not ready to port to flutter/packages yet. The changes not in the material or cupertino libraries will remain here. |
|
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).
|
[this is a rethread of https://github.com//pull/181110]
addressing the comments:
buttons, so I am happy with it.[original description]
This PR changes the signatures of
handleThumbPressStart,handleThumbPressUpdate, andhandleThumbPressEnd, related to scrollbar handling, to take in a copy of the original event with thelocalPositionadded 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
kindwhen it exists,buttonswhen 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
buttonsproperty 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 wasglobal --(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
///).