Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ee921e63
Unverified
Commit
ee921e63
authored
Apr 02, 2021
by
Trym Nilsen
Committed by
GitHub
Apr 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply carriedVelocity unless substantially different (#79382)
parent
d0513364
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
3 deletions
+36
-3
scroll_activity.dart
packages/flutter/lib/src/widgets/scroll_activity.dart
+19
-3
scrollable_test.dart
packages/flutter/test/widgets/scrollable_test.dart
+17
-0
No files found.
packages/flutter/lib/src/widgets/scroll_activity.dart
View file @
ee921e63
...
...
@@ -274,6 +274,14 @@ class ScrollDragController implements Drag {
static
const
Duration
momentumRetainStationaryDurationThreshold
=
Duration
(
milliseconds:
20
);
/// The minimum amount of velocity needed to apply the [carriedVelocity] at
/// the end of a drag. Expressed as a factor. For example with a
/// [carriedVelocity] of 2000, we will need a velocity of at least 1000 to
/// apply the [carriedVelocity] as well. If the velocity does not meet the
/// threshold the the [carriedVelocity] is lost. Decided by fair eyeballing
/// with the scroll_overlay platform test.
static
const
double
momentumRetainVelocityThresholdFactor
=
0.5
;
/// Maximum amount of time interval the drag can have consecutive stationary
/// pointer update events before needing to break the
/// [motionStartDistanceThreshold] to start motion again.
...
...
@@ -390,9 +398,17 @@ class ScrollDragController implements Drag {
velocity
=
-
velocity
;
_lastDetails
=
details
;
if
(
_retainMomentum
)
{
// Build momentum only if dragging in the same direction.
if
(
_retainMomentum
&&
velocity
.
sign
==
carriedVelocity
!.
sign
)
final
bool
isFlingingInSameDirection
=
velocity
.
sign
==
carriedVelocity
!.
sign
;
// Build momentum only if the velocity of the last drag was not
// substantially lower than the carried momentum.
final
bool
isVelocityNotSubstantiallyLessThanCarriedMomentum
=
velocity
.
abs
()
>
carriedVelocity
!.
abs
()
*
momentumRetainVelocityThresholdFactor
;
if
(
isFlingingInSameDirection
&&
isVelocityNotSubstantiallyLessThanCarriedMomentum
)
{
velocity
+=
carriedVelocity
!;
}
}
delegate
.
goBallistic
(
velocity
);
}
...
...
packages/flutter/test/widgets/scrollable_test.dart
View file @
ee921e63
...
...
@@ -178,6 +178,23 @@ void main() {
expect
(
getScrollVelocity
(
tester
),
moreOrLessEquals
(
1000.0
));
});
testWidgets
(
'A slower final fling does not apply carried momentum'
,
(
WidgetTester
tester
)
async
{
await
pumpTest
(
tester
,
debugDefaultTargetPlatformOverride
);
await
tester
.
fling
(
find
.
byType
(
Scrollable
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
await
tester
.
pump
();
// trigger fling
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// Repeat the exact same motion to build momentum.
await
tester
.
fling
(
find
.
byType
(
Scrollable
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
await
tester
.
pump
();
// trigger the second fling
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// Make a final fling that is much slower.
await
tester
.
fling
(
find
.
byType
(
Scrollable
),
const
Offset
(
0.0
,
-
dragOffset
),
200.0
);
await
tester
.
pump
();
// trigger the third fling
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// expect that there is no carried velocity
expect
(
getScrollVelocity
(
tester
),
lessThan
(
200.0
));
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
testWidgets
(
'No iOS/macOS momentum build with flings in opposite directions'
,
(
WidgetTester
tester
)
async
{
await
pumpTest
(
tester
,
debugDefaultTargetPlatformOverride
);
await
tester
.
fling
(
find
.
byType
(
Scrollable
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment