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
22f51c34
Unverified
Commit
22f51c34
authored
Jul 21, 2022
by
Callum Moffat
Committed by
GitHub
Jul 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scroll inertia cancel [framework] (#106891)
parent
bf22b7ae
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
2 deletions
+129
-2
converter.dart
packages/flutter/lib/src/gestures/converter.dart
+8
-2
events.dart
packages/flutter/lib/src/gestures/events.dart
+85
-0
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+3
-0
scrollable_test.dart
packages/flutter/test/widgets/scrollable_test.dart
+16
-0
test_pointer.dart
packages/flutter_test/lib/src/test_pointer.dart
+17
-0
No files found.
packages/flutter/lib/src/gestures/converter.dart
View file @
22f51c34
...
@@ -259,9 +259,15 @@ class PointerEventConverter {
...
@@ -259,9 +259,15 @@ class PointerEventConverter {
scrollDelta:
scrollDelta
,
scrollDelta:
scrollDelta
,
embedderId:
datum
.
embedderId
,
embedderId:
datum
.
embedderId
,
);
);
case
ui
.
PointerSignalKind
.
scrollInertiaCancel
:
return
PointerScrollInertiaCancelEvent
(
timeStamp:
timeStamp
,
kind:
kind
,
device:
datum
.
device
,
position:
position
,
embedderId:
datum
.
embedderId
,
);
case
ui
.
PointerSignalKind
.
unknown
:
case
ui
.
PointerSignalKind
.
unknown
:
default
:
// ignore: no_default_cases, to allow adding a new [PointerSignalKind]
// TODO(moffatman): Remove after landing https://github.com/flutter/engine/pull/34402
// This branch should already have 'unknown' filtered out, but
// This branch should already have 'unknown' filtered out, but
// we don't want to return anything or miss if someone adds a new
// we don't want to return anything or miss if someone adds a new
// enumeration to PointerSignalKind.
// enumeration to PointerSignalKind.
...
...
packages/flutter/lib/src/gestures/events.dart
View file @
22f51c34
...
@@ -1830,6 +1830,91 @@ class _TransformedPointerScrollEvent extends _TransformedPointerEvent with _Copy
...
@@ -1830,6 +1830,91 @@ class _TransformedPointerScrollEvent extends _TransformedPointerEvent with _Copy
}
}
}
}
mixin
_CopyPointerScrollInertiaCancelEvent
on
PointerEvent
{
@override
PointerScrollInertiaCancelEvent
copyWith
({
Duration
?
timeStamp
,
int
?
pointer
,
PointerDeviceKind
?
kind
,
int
?
device
,
Offset
?
position
,
Offset
?
delta
,
int
?
buttons
,
bool
?
obscured
,
double
?
pressure
,
double
?
pressureMin
,
double
?
pressureMax
,
double
?
distance
,
double
?
distanceMax
,
double
?
size
,
double
?
radiusMajor
,
double
?
radiusMinor
,
double
?
radiusMin
,
double
?
radiusMax
,
double
?
orientation
,
double
?
tilt
,
bool
?
synthesized
,
int
?
embedderId
,
})
{
return
PointerScrollInertiaCancelEvent
(
timeStamp:
timeStamp
??
this
.
timeStamp
,
kind:
kind
??
this
.
kind
,
device:
device
??
this
.
device
,
position:
position
??
this
.
position
,
embedderId:
embedderId
??
this
.
embedderId
,
).
transformed
(
transform
);
}
}
/// The pointer issued a scroll-inertia cancel event.
///
/// Touching the trackpad immediately after a scroll is an example of an event
/// that would create a [PointerScrollInertiaCancelEvent].
///
/// See also:
///
/// * [Listener.onPointerSignal], which allows callers to be notified of these
/// events in a widget tree.
/// * [PointerSignalResolver], which provides an opt-in mechanism whereby
/// participating agents may disambiguate an event's target.
class
PointerScrollInertiaCancelEvent
extends
PointerSignalEvent
with
_PointerEventDescription
,
_CopyPointerScrollInertiaCancelEvent
{
/// Creates a pointer scroll-inertia cancel event.
///
/// All of the arguments must be non-null.
const
PointerScrollInertiaCancelEvent
({
super
.
timeStamp
,
super
.
kind
,
super
.
device
,
super
.
position
,
super
.
embedderId
,
})
:
assert
(
timeStamp
!=
null
),
assert
(
kind
!=
null
),
assert
(
device
!=
null
),
assert
(
position
!=
null
);
@override
PointerScrollInertiaCancelEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
}
return
_TransformedPointerScrollInertiaCancelEvent
(
original
as
PointerScrollInertiaCancelEvent
?
??
this
,
transform
);
}
}
class
_TransformedPointerScrollInertiaCancelEvent
extends
_TransformedPointerEvent
with
_CopyPointerScrollInertiaCancelEvent
implements
PointerScrollInertiaCancelEvent
{
_TransformedPointerScrollInertiaCancelEvent
(
this
.
original
,
this
.
transform
)
:
assert
(
original
!=
null
),
assert
(
transform
!=
null
);
@override
final
PointerScrollInertiaCancelEvent
original
;
@override
final
Matrix4
transform
;
@override
PointerScrollInertiaCancelEvent
transformed
(
Matrix4
?
transform
)
=>
original
.
transformed
(
transform
);
}
mixin
_CopyPointerPanZoomStartEvent
on
PointerEvent
{
mixin
_CopyPointerPanZoomStartEvent
on
PointerEvent
{
@override
@override
PointerPanZoomStartEvent
copyWith
({
PointerPanZoomStartEvent
copyWith
({
...
...
packages/flutter/lib/src/widgets/scrollable.dart
View file @
22f51c34
...
@@ -731,6 +731,9 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
...
@@ -731,6 +731,9 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
if
(
delta
!=
0.0
&&
targetScrollOffset
!=
position
.
pixels
)
{
if
(
delta
!=
0.0
&&
targetScrollOffset
!=
position
.
pixels
)
{
GestureBinding
.
instance
.
pointerSignalResolver
.
register
(
event
,
_handlePointerScroll
);
GestureBinding
.
instance
.
pointerSignalResolver
.
register
(
event
,
_handlePointerScroll
);
}
}
}
else
if
(
event
is
PointerScrollInertiaCancelEvent
)
{
position
.
jumpTo
(
position
.
pixels
);
// Don't use the pointer signal resolver, all hit-tested scrollables should stop.
}
}
}
}
...
...
packages/flutter/test/widgets/scrollable_test.dart
View file @
22f51c34
...
@@ -1427,6 +1427,22 @@ void main() {
...
@@ -1427,6 +1427,22 @@ void main() {
expect
(
syntheticScrollableNode
!.
hasFlag
(
ui
.
SemanticsFlag
.
hasImplicitScrolling
),
isTrue
);
expect
(
syntheticScrollableNode
!.
hasFlag
(
ui
.
SemanticsFlag
.
hasImplicitScrolling
),
isTrue
);
handle
.
dispose
();
handle
.
dispose
();
});
});
testWidgets
(
'Scroll inertia cancel event'
,
(
WidgetTester
tester
)
async
{
await
pumpTest
(
tester
,
null
);
await
tester
.
fling
(
find
.
byType
(
Scrollable
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
expect
(
getScrollOffset
(
tester
),
dragOffset
);
await
tester
.
pump
();
// trigger fling
expect
(
getScrollOffset
(
tester
),
dragOffset
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
final
TestPointer
testPointer
=
TestPointer
(
1
,
ui
.
PointerDeviceKind
.
mouse
);
await
tester
.
sendEventToBinding
(
testPointer
.
hover
(
tester
.
getCenter
(
find
.
byType
(
Scrollable
))));
await
tester
.
sendEventToBinding
(
testPointer
.
scrollInertiaCancel
());
// Cancel partway through.
await
tester
.
pump
();
expect
(
getScrollOffset
(
tester
),
closeTo
(
333.2944
,
0.0001
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
4800
));
expect
(
getScrollOffset
(
tester
),
closeTo
(
333.2944
,
0.0001
));
});
}
}
// ignore: must_be_immutable
// ignore: must_be_immutable
...
...
packages/flutter_test/lib/src/test_pointer.dart
View file @
22f51c34
...
@@ -304,6 +304,23 @@ class TestPointer {
...
@@ -304,6 +304,23 @@ class TestPointer {
);
);
}
}
/// Create a [PointerScrollInertiaCancelEvent] (e.g., user resting their finger on the trackpad).
///
/// By default, the time stamp on the event is [Duration.zero]. You can give a
/// specific time stamp by passing the `timeStamp` argument.
PointerScrollInertiaCancelEvent
scrollInertiaCancel
({
Duration
timeStamp
=
Duration
.
zero
,
})
{
assert
(
kind
!=
PointerDeviceKind
.
touch
,
"Touch pointers can't generate pointer signal events"
);
assert
(
location
!=
null
);
return
PointerScrollInertiaCancelEvent
(
timeStamp:
timeStamp
,
kind:
kind
,
device:
_device
,
position:
location
!
);
}
/// Create a [PointerPanZoomStartEvent] (e.g., trackpad scroll; not scroll wheel
/// Create a [PointerPanZoomStartEvent] (e.g., trackpad scroll; not scroll wheel
/// or finger-drag scroll) with the given delta.
/// or finger-drag scroll) with the given delta.
///
///
...
...
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