Skip to content

Fixed a problem with the first drag update on a reorderable list. - #82296

Merged
fluttergithubbot merged 2 commits into
flutter:masterfrom
darrenaustin:reorderable_list_first_drag
May 14, 2021
Merged

fluttergithubbot merged 2 commits into
flutter:masterfrom
darrenaustin:reorderable_list_first_drag

Conversation

@darrenaustin

@darrenaustin darrenaustin commented May 11, 2021 •

Copy link
Copy Markdown
Contributor

During the development of #81396 it was noticed the the drag calculations in the first frame of a reorderable list drag were off by the size of the dragged item. This is due to the implementation of the gap. During the drag the dragged item in the list is replaced by a zero sized item and all later items are just translated down by the gap size. This allows us to keep the order in the list while still being able to move the gap around based on the drag location. However, for the first frame of the drag the replacement of the zero sized box has not yet happened and any initial calculation of where the dragged item is will be off. During normal usage this isn't a problem because it is rare that you won't immediately have another drag event that will sort itself out. However in unit tests we only have a single drag event and it will be wrong.

This PR compensates for this issue and updates the tests so they are testing correct values.

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 feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard Bot added the framework flutter/packages/flutter repository. See also f: labels. label May 11, 2021
@google-cla google-cla Bot added the cla: yes label May 11, 2021
Comment thread packages/flutter/lib/src/widgets/reorderable_list.dart Outdated
Comment thread packages/flutter/lib/src/widgets/reorderable_list.dart Outdated

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.

Just set _dragStartTransitionComplete to true here, instead of using a post-frame callback?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, but the issue is that we don't know when this first update will occur. It could happen after the first frame, in which case we don't want to recompute the offset as it is already correct. Using this flag is just a way of making sure this is only recomputed if we are still before the first frame of the drag which is when we need to compensate for the dragged item that is still in the list.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Another alternative I played with was to reset the flag from the build method of the dragged widget (when it was actually being replaced with the zero sized box). That seemed messier because it meant the child item widget was directly manipulating the state in the list (or I would need to expose a method). The post-frame callback seemed the most self contained.

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.

I see, thanks for the detailed explanation!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review.

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

LGTM

@fluttergithubbot
fluttergithubbot merged commit 7903370 into flutter:master May 14, 2021
@darrenaustin
darrenaustin deleted the reorderable_list_first_drag branch May 15, 2021 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants