mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #2829 from HansMuller/super_fling_fast
Fix Fast Fling Failure
This commit is contained in:
commit
bcf08d2309
@ -78,9 +78,9 @@ const double kWindowTouchSlop = 16.0; // Logical pixels
|
||||
/// gesture.
|
||||
// TODO(ianh): Make sure nobody has their own version of this.
|
||||
const double kMinFlingVelocity = 50.0; // Logical pixels / second
|
||||
// const Velocity kMinFlingVelocity = const Velocity(pixelsPerSecond: 50.0);
|
||||
|
||||
/// The maximum velocity of a touch to consider that touch to trigger a fling
|
||||
/// gesture.
|
||||
/// Drag gesture fling velocities are clipped to this value.
|
||||
// TODO(ianh): Make sure nobody has their own version of this.
|
||||
const double kMaxFlingVelocity = 8000.0; // Logical pixels / second
|
||||
|
||||
|
||||
@ -31,8 +31,7 @@ typedef void _GesturePolymorphicUpdateCallback<T>(T delta);
|
||||
bool _isFlingGesture(Velocity velocity) {
|
||||
assert(velocity != null);
|
||||
final double speedSquared = velocity.pixelsPerSecond.distanceSquared;
|
||||
return speedSquared > kMinFlingVelocity * kMinFlingVelocity
|
||||
&& speedSquared < kMaxFlingVelocity * kMaxFlingVelocity;
|
||||
return speedSquared > kMinFlingVelocity * kMinFlingVelocity;
|
||||
}
|
||||
|
||||
abstract class _DragGestureRecognizer<T extends dynamic> extends OneSequenceGestureRecognizer {
|
||||
@ -119,10 +118,14 @@ abstract class _DragGestureRecognizer<T extends dynamic> extends OneSequenceGest
|
||||
assert(tracker != null);
|
||||
|
||||
Velocity velocity = tracker.getVelocity();
|
||||
if (velocity != null && _isFlingGesture(velocity))
|
||||
if (velocity != null && _isFlingGesture(velocity)) {
|
||||
final Offset pixelsPerSecond = velocity.pixelsPerSecond;
|
||||
if (pixelsPerSecond.distanceSquared > kMaxFlingVelocity * kMaxFlingVelocity)
|
||||
velocity = new Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * kMaxFlingVelocity);
|
||||
onEnd(velocity);
|
||||
else
|
||||
} else {
|
||||
onEnd(Velocity.zero);
|
||||
}
|
||||
}
|
||||
_velocityTrackers.clear();
|
||||
}
|
||||
|
||||
@ -499,8 +499,7 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
|
||||
|
||||
Future<Null> _handleDragEnd(Velocity velocity) {
|
||||
double scrollVelocity = pixelDeltaToScrollOffset(velocity.pixelsPerSecond) / Duration.MILLISECONDS_PER_SECOND;
|
||||
// The gesture velocity properties are pixels/second, config min,max limits are pixels/ms
|
||||
return fling(scrollVelocity.clamp(-kMaxFlingVelocity, kMaxFlingVelocity)).then(_endScroll);
|
||||
return fling(scrollVelocity).then(_endScroll);
|
||||
}
|
||||
|
||||
Null _endScroll([Null _]) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user