Skip to content

Add a snapAnimationDuration param in DraggableScrollableSheet #107396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2022

Conversation

hannah-hyj
Copy link
Member

@hannah-hyj hannah-hyj commented Jul 11, 2022

Add a new param so user can define the duration of the snap animation of a DraggableScrollableSheet.

video attached with snap animations duration = 0.5S

Fixed: #107033

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 Jul 11, 2022
@hannah-hyj hannah-hyj requested a review from HansMuller July 11, 2022 11:21
@hannah-hyj
Copy link
Member Author

slow_snap_animation.mp4

@hannah-hyj hannah-hyj requested a review from darrenaustin July 11, 2022 11:32
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

This look good, just a few trivialities to deal with.

///
/// If it's not set, then the animation duration is the distance to the snap
/// target divided by the velocity of the widget.
final Duration? snapAnimationDuration;
Copy link
Contributor

Choose a reason for hiding this comment

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

What if this value is zero? Do we want to support that to indicate "no animation"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's unlikely to be a use case to snap the bottom sheet with no animation. So The negative/zero/less than 1 milliseconds durations can be considered as unset.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can support the no animation snap use case when there are new feature requests.

Copy link
Contributor

Choose a reason for hiding this comment

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

< 1 seems a bit arbitrary. Since 1 frame is typically 16ms, it might make more sense to use that, since a duration of less than a frame is effectively 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about this again; I think it would be best to just assert that if a duration was specified it must be > 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Assertion added


// The duration of the snap animation is defined.
if(snapAnimationDuration != null) {
velocity = (_pixelSnapSize - position) * 1000 / snapAnimationDuration.inMilliseconds;
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the duration is zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ditto, added a check.

@hannah-hyj hannah-hyj requested a review from HansMuller July 12, 2022 09:44
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

@hannah-hyj hannah-hyj merged commit b753476 into flutter:master Jul 12, 2022
@hannah-hyj hannah-hyj deleted the branch1 branch July 12, 2022 15:06
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
…r#107396)

* Add a snapAnimationDuration param in DraggableScrollableSheet

* snapAnimationDuration.inMilliseconds > 0

* Update draggable_scrollable_sheet.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Add way to change DraggableScrollableSheet snap animation curve and duration
2 participants