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
60847a1d
Commit
60847a1d
authored
Jan 17, 2017
by
Hans Muller
Committed by
GitHub
Jan 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore velocity tracker sample window duration (#7510)
parent
9ece6daf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
2 deletions
+93
-2
velocity_tracker.dart
packages/flutter/lib/src/gestures/velocity_tracker.dart
+12
-2
velocity_tracker_data.dart
packages/flutter/test/gestures/velocity_tracker_data.dart
+69
-0
velocity_tracker_test.dart
packages/flutter/test/gestures/velocity_tracker_test.dart
+12
-0
No files found.
packages/flutter/lib/src/gestures/velocity_tracker.dart
View file @
60847a1d
...
...
@@ -34,6 +34,9 @@ class _Movement {
String
toString
()
=>
'Movement(
$position
at
$eventTime
)'
;
}
// TODO: On iOS we're not necccessarily seeing all of the motion events. See:
// https://github.com/flutter/flutter/issues/4737#issuecomment-241076994
class
_LeastSquaresVelocityTrackerStrategy
extends
_VelocityTrackerStrategy
{
_LeastSquaresVelocityTrackerStrategy
(
this
.
degree
);
...
...
@@ -43,7 +46,11 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
int
_index
=
0
;
static
const
int
kHistorySize
=
20
;
static
const
int
kHorizonMilliseconds
=
40
;
static
const
int
kHorizonMilliseconds
=
100
;
// The maximum length of time between two move events to allow before
// assuming the pointer stopped.
static
const
int
kAssumePointerMoveStoppedMilliseconds
=
40
;
@override
void
addMovement
(
Duration
timeStamp
,
Point
position
)
{
...
...
@@ -64,6 +71,7 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
int
index
=
_index
;
_Movement
newestMovement
=
_movements
[
index
];
_Movement
previousMovement
=
newestMovement
;
if
(
newestMovement
==
null
)
return
null
;
...
...
@@ -73,7 +81,9 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
break
;
double
age
=
(
newestMovement
.
eventTime
-
movement
.
eventTime
).
inMilliseconds
.
toDouble
();
if
(
age
>
kHorizonMilliseconds
)
double
delta
=
(
movement
.
eventTime
-
previousMovement
.
eventTime
).
inMilliseconds
.
abs
().
toDouble
();
previousMovement
=
movement
;
if
(
age
>
kHorizonMilliseconds
||
delta
>
kAssumePointerMoveStoppedMilliseconds
)
break
;
Point
position
=
movement
.
position
;
...
...
packages/flutter/test/gestures/velocity_tracker_data.dart
View file @
60847a1d
...
...
@@ -1536,3 +1536,72 @@ const List<PointerEvent> velocityEventData = const <PointerEvent>[
position:
const
Point
(
241.14285278320312
,
451.4285583496094
)
),
];
const
List
<
PointerEvent
>
interruptedVelocityEventData
=
const
<
PointerEvent
>[
const
PointerDownEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698321
),
pointer:
13
,
position:
const
Point
(
250.0
,
306.0
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698328
),
pointer:
13
,
position:
const
Point
(
250.0
,
306.0
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698344
),
pointer:
13
,
position:
const
Point
(
249.14285278320312
,
314.0
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698351
),
pointer:
13
,
position:
const
Point
(
247.42857360839844
,
319.4285583496094
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698359
),
pointer:
13
,
position:
const
Point
(
245.14285278320312
,
326.8571472167969
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698366
),
pointer:
13
,
position:
const
Point
(
241.7142791748047
,
339.4285583496094
)
),
// The pointer "stops" here because we've introduced a 40+ms gap
// in the move event stream. See kAssumePointerMoveStoppedMilliseconds
// in velocity_tracker.dart.
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698374
+
40
),
pointer:
13
,
position:
const
Point
(
238.57142639160156
,
355.71429443359375
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698382
+
40
),
pointer:
13
,
position:
const
Point
(
236.2857208251953
,
374.28570556640625
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698390
+
40
),
pointer:
13
,
position:
const
Point
(
235.14285278320312
,
396.5714416503906
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698398
+
40
),
pointer:
13
,
position:
const
Point
(
236.57142639160156
,
421.4285583496094
)
),
const
PointerMoveEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698406
+
40
),
pointer:
13
,
position:
const
Point
(
241.14285278320312
,
451.4285583496094
)
),
const
PointerUpEvent
(
timeStamp:
const
Duration
(
milliseconds:
216698421
+
40
),
pointer:
13
,
position:
const
Point
(
241.14285278320312
,
451.4285583496094
)
),
];
packages/flutter/test/gestures/velocity_tracker_test.dart
View file @
60847a1d
...
...
@@ -59,4 +59,16 @@ void main() {
expect
(
velocity1
.
hashCode
,
isNot
(
equals
(
velocity2
.
hashCode
)));
expect
(
velocity1
,
hasOneLineDescription
);
});
test
(
'Interrupted velocity estimation'
,
()
{
// Regression test for https://github.com/flutter/flutter/pull/7510
VelocityTracker
tracker
=
new
VelocityTracker
();
for
(
PointerEvent
event
in
interruptedVelocityEventData
)
{
if
(
event
is
PointerDownEvent
||
event
is
PointerMoveEvent
)
tracker
.
addPosition
(
event
.
timeStamp
,
event
.
position
);
if
(
event
is
PointerUpEvent
)
{
_checkVelocity
(
tracker
.
getVelocity
(),
const
Offset
(
649.5
,
3890.3
));
}
}
});
}
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