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
3fc40820
Unverified
Commit
3fc40820
authored
May 18, 2021
by
Todd Volkert
Committed by
GitHub
May 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Gesture recognizer cleanup (#81884)" (#82831)
This reverts commit
e88a387b
.
parent
b353f15e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
282 deletions
+33
-282
eager.dart
packages/flutter/lib/src/gestures/eager.dart
+2
-1
force_press.dart
packages/flutter/lib/src/gestures/force_press.dart
+3
-3
monodrag.dart
packages/flutter/lib/src/gestures/monodrag.dart
+2
-2
recognizer.dart
packages/flutter/lib/src/gestures/recognizer.dart
+11
-56
scale.dart
packages/flutter/lib/src/gestures/scale.dart
+2
-2
platform_view.dart
packages/flutter/lib/src/rendering/platform_view.dart
+2
-2
recognizer_test.dart
packages/flutter/test/gestures/recognizer_test.dart
+11
-216
No files found.
packages/flutter/lib/src/gestures/eager.dart
View file @
3fc40820
...
@@ -27,7 +27,8 @@ class EagerGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -27,7 +27,8 @@ class EagerGestureRecognizer extends OneSequenceGestureRecognizer {
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
super
.
addAllowedPointer
(
event
);
// We call startTrackingPointer as this is where OneSequenceGestureRecognizer joins the arena.
startTrackingPointer
(
event
.
pointer
,
event
.
transform
);
resolve
(
GestureDisposition
.
accepted
);
resolve
(
GestureDisposition
.
accepted
);
stopTrackingPointer
(
event
.
pointer
);
stopTrackingPointer
(
event
.
pointer
);
}
}
...
...
packages/flutter/lib/src/gestures/force_press.dart
View file @
3fc40820
...
@@ -216,14 +216,14 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -216,14 +216,14 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
_ForceState
_state
=
_ForceState
.
ready
;
_ForceState
_state
=
_ForceState
.
ready
;
@override
@override
void
addAllowedPointer
(
Pointer
Down
Event
event
)
{
void
addAllowedPointer
(
PointerEvent
event
)
{
// If the device has a maximum pressure of less than or equal to 1, it
// If the device has a maximum pressure of less than or equal to 1, it
// doesn't have touch pressure sensing capabilities. Do not participate
// doesn't have touch pressure sensing capabilities. Do not participate
// in the gesture arena.
// in the gesture arena.
if
(
event
.
pressureMax
<=
1.0
)
{
if
(
event
is
!
PointerUpEvent
&&
event
.
pressureMax
<=
1.0
)
{
resolve
(
GestureDisposition
.
rejected
);
resolve
(
GestureDisposition
.
rejected
);
}
else
{
}
else
{
s
uper
.
addAllowedPointer
(
event
);
s
tartTrackingPointer
(
event
.
pointer
,
event
.
transform
);
if
(
_state
==
_ForceState
.
ready
)
{
if
(
_state
==
_ForceState
.
ready
)
{
_state
=
_ForceState
.
possible
;
_state
=
_ForceState
.
possible
;
_lastPosition
=
OffsetPair
.
fromEventPosition
(
event
);
_lastPosition
=
OffsetPair
.
fromEventPosition
(
event
);
...
...
packages/flutter/lib/src/gestures/monodrag.dart
View file @
3fc40820
...
@@ -262,8 +262,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -262,8 +262,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
}
}
@override
@override
void
addAllowedPointer
(
Pointer
Down
Event
event
)
{
void
addAllowedPointer
(
PointerEvent
event
)
{
s
uper
.
addAllowedPointer
(
event
);
s
tartTrackingPointer
(
event
.
pointer
,
event
.
transform
);
_velocityTrackers
[
event
.
pointer
]
=
velocityTrackerBuilder
(
event
);
_velocityTrackers
[
event
.
pointer
]
=
velocityTrackerBuilder
(
event
);
if
(
_state
==
_DragState
.
ready
)
{
if
(
_state
==
_DragState
.
ready
)
{
_state
=
_DragState
.
possible
;
_state
=
_DragState
.
possible
;
...
...
packages/flutter/lib/src/gestures/recognizer.dart
View file @
3fc40820
...
@@ -248,32 +248,11 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -248,32 +248,11 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
final
Set
<
int
>
_trackedPointers
=
HashSet
<
int
>();
final
Set
<
int
>
_trackedPointers
=
HashSet
<
int
>();
@override
@override
@protected
void
addAllowedPointer
(
PointerDownEvent
event
)
{
startTrackingPointer
(
event
.
pointer
,
event
.
transform
);
}
@override
@protected
void
handleNonAllowedPointer
(
PointerDownEvent
event
)
{
void
handleNonAllowedPointer
(
PointerDownEvent
event
)
{
resolve
(
GestureDisposition
.
rejected
);
resolve
(
GestureDisposition
.
rejected
);
}
}
/// Called when a pointer event is routed to this recognizer.
/// Called when a pointer event is routed to this recognizer.
///
/// This will be called for every pointer event while the pointer is being
/// tracked. Typically, this recognizer will start tracking the pointer in
/// [addAllowedPointer], which means that [handleEvent] will be called
/// starting with the [PointerDownEvent] that was passed to [addAllowedPointer].
///
/// See also:
///
/// * [startTrackingPointer], which causes pointer events to be routed to
/// this recognizer.
/// * [stopTrackingPointer], which stops events from being routed to this
/// recognizer.
/// * [stopTrackingIfPointerNoLongerDown], which conditionally stops events
/// from being routed to this recognizer.
@protected
@protected
void
handleEvent
(
PointerEvent
event
);
void
handleEvent
(
PointerEvent
event
);
...
@@ -359,11 +338,6 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -359,11 +338,6 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
/// null if no transformation is necessary.
/// null if no transformation is necessary.
///
///
/// Use [stopTrackingPointer] to remove the route added by this function.
/// Use [stopTrackingPointer] to remove the route added by this function.
///
/// This method also adds this recognizer (or its [team] if it's non-null) to
/// the gesture arena for the specified pointer.
///
/// This is called by [OneSequenceGestureRecognizer.addAllowedPointer].
@protected
@protected
void
startTrackingPointer
(
int
pointer
,
[
Matrix4
?
transform
])
{
void
startTrackingPointer
(
int
pointer
,
[
Matrix4
?
transform
])
{
GestureBinding
.
instance
!.
pointerRouter
.
addRoute
(
pointer
,
handleEvent
,
transform
);
GestureBinding
.
instance
!.
pointerRouter
.
addRoute
(
pointer
,
handleEvent
,
transform
);
...
@@ -492,27 +466,13 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -492,27 +466,13 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
/// The current state of the recognizer.
/// The current state of the recognizer.
///
///
/// See [GestureRecognizerState] for a description of the states.
/// See [GestureRecognizerState] for a description of the states.
GestureRecognizerState
get
state
=>
_state
;
GestureRecognizerState
state
=
GestureRecognizerState
.
ready
;
GestureRecognizerState
_state
=
GestureRecognizerState
.
ready
;
/// The ID of the primary pointer this recognizer is tracking.
/// The ID of the primary pointer this recognizer is tracking.
///
int
?
primaryPointer
;
/// If this recognizer is no longer tracking any pointers, this field holds
/// the ID of the primary pointer this recognizer was most recently tracking.
/// This enables the recognizer to know which pointer it was most recently
/// tracking when [acceptGesture] or [rejectGesture] is called (which may be
/// called after the recognizer is no longer tracking a pointer if, e.g.
/// [GestureArenaManager.hold] has been called, or if there are other
/// recognizers keeping the arena open).
int
?
get
primaryPointer
=>
_primaryPointer
;
int
?
_primaryPointer
;
/// The location at which the primary pointer contacted the screen.
/// The location at which the primary pointer contacted the screen.
///
OffsetPair
?
initialPosition
;
/// This will only be non-null while this recognizer is tracking at least
/// one pointer.
OffsetPair
?
get
initialPosition
=>
_initialPosition
;
OffsetPair
?
_initialPosition
;
// Whether this pointer is accepted by winning the arena or as defined by
// Whether this pointer is accepted by winning the arena or as defined by
// a subclass calling acceptGesture.
// a subclass calling acceptGesture.
...
@@ -521,11 +481,11 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -521,11 +481,11 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
s
uper
.
addAllowedPointer
(
event
);
s
tartTrackingPointer
(
event
.
pointer
,
event
.
transform
);
if
(
state
==
GestureRecognizerState
.
ready
)
{
if
(
state
==
GestureRecognizerState
.
ready
)
{
_
state
=
GestureRecognizerState
.
possible
;
state
=
GestureRecognizerState
.
possible
;
_
primaryPointer
=
event
.
pointer
;
primaryPointer
=
event
.
pointer
;
_
initialPosition
=
OffsetPair
(
local:
event
.
localPosition
,
global:
event
.
position
);
initialPosition
=
OffsetPair
(
local:
event
.
localPosition
,
global:
event
.
position
);
if
(
deadline
!=
null
)
if
(
deadline
!=
null
)
_timer
=
Timer
(
deadline
!,
()
=>
didExceedDeadlineWithEvent
(
event
));
_timer
=
Timer
(
deadline
!,
()
=>
didExceedDeadlineWithEvent
(
event
));
}
}
...
@@ -568,8 +528,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -568,8 +528,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
/// Override to be notified when [deadline] is exceeded.
/// Override to be notified when [deadline] is exceeded.
///
///
/// You must override this method or [didExceedDeadlineWithEvent] if you
/// You must override this method or [didExceedDeadlineWithEvent] if you
/// supply a [deadline]. Subclasses that override this method must _not_
/// supply a [deadline].
/// call `super.didExceedDeadline()`.
@protected
@protected
void
didExceedDeadline
()
{
void
didExceedDeadline
()
{
assert
(
deadline
==
null
);
assert
(
deadline
==
null
);
...
@@ -579,8 +538,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -579,8 +538,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
/// gesture.
/// gesture.
///
///
/// You must override this method or [didExceedDeadline] if you supply a
/// You must override this method or [didExceedDeadline] if you supply a
/// [deadline]. Subclasses that override this method must _not_ call
/// [deadline].
/// `super.didExceedDeadlineWithEvent(event)`.
@protected
@protected
void
didExceedDeadlineWithEvent
(
PointerDownEvent
event
)
{
void
didExceedDeadlineWithEvent
(
PointerDownEvent
event
)
{
didExceedDeadline
();
didExceedDeadline
();
...
@@ -598,7 +556,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -598,7 +556,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
void
rejectGesture
(
int
pointer
)
{
void
rejectGesture
(
int
pointer
)
{
if
(
pointer
==
primaryPointer
&&
state
==
GestureRecognizerState
.
possible
)
{
if
(
pointer
==
primaryPointer
&&
state
==
GestureRecognizerState
.
possible
)
{
_stopTimer
();
_stopTimer
();
_
state
=
GestureRecognizerState
.
defunct
;
state
=
GestureRecognizerState
.
defunct
;
}
}
}
}
...
@@ -606,9 +564,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -606,9 +564,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
void
didStopTrackingLastPointer
(
int
pointer
)
{
void
didStopTrackingLastPointer
(
int
pointer
)
{
assert
(
state
!=
GestureRecognizerState
.
ready
);
assert
(
state
!=
GestureRecognizerState
.
ready
);
_stopTimer
();
_stopTimer
();
_state
=
GestureRecognizerState
.
ready
;
state
=
GestureRecognizerState
.
ready
;
_initialPosition
=
null
;
_gestureAccepted
=
false
;
}
}
@override
@override
...
@@ -641,7 +597,6 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -641,7 +597,6 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
/// Usually, the [global] [Offset] is in the coordinate space of the screen
/// Usually, the [global] [Offset] is in the coordinate space of the screen
/// after conversion to logical pixels and the [local] offset is the same
/// after conversion to logical pixels and the [local] offset is the same
/// [Offset], but transformed to a local coordinate space.
/// [Offset], but transformed to a local coordinate space.
@immutable
class
OffsetPair
{
class
OffsetPair
{
/// Creates a [OffsetPair] combining a [local] and [global] [Offset].
/// Creates a [OffsetPair] combining a [local] and [global] [Offset].
const
OffsetPair
({
const
OffsetPair
({
...
...
packages/flutter/lib/src/gestures/scale.dart
View file @
3fc40820
...
@@ -350,8 +350,8 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -350,8 +350,8 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
}
}
@override
@override
void
addAllowedPointer
(
Pointer
Down
Event
event
)
{
void
addAllowedPointer
(
PointerEvent
event
)
{
s
uper
.
addAllowedPointer
(
event
);
s
tartTrackingPointer
(
event
.
pointer
,
event
.
transform
);
_velocityTrackers
[
event
.
pointer
]
=
VelocityTracker
.
withKind
(
event
.
kind
);
_velocityTrackers
[
event
.
pointer
]
=
VelocityTracker
.
withKind
(
event
.
kind
);
if
(
_state
==
_ScaleState
.
ready
)
{
if
(
_state
==
_ScaleState
.
ready
)
{
_state
=
_ScaleState
.
possible
;
_state
=
_ScaleState
.
possible
;
...
...
packages/flutter/lib/src/rendering/platform_view.dart
View file @
3fc40820
...
@@ -456,7 +456,7 @@ class _UiKitViewGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -456,7 +456,7 @@ class _UiKitViewGestureRecognizer extends OneSequenceGestureRecognizer {
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
s
uper
.
addAllowedPointer
(
event
);
s
tartTrackingPointer
(
event
.
pointer
,
event
.
transform
);
for
(
final
OneSequenceGestureRecognizer
recognizer
in
_gestureRecognizers
)
{
for
(
final
OneSequenceGestureRecognizer
recognizer
in
_gestureRecognizers
)
{
recognizer
.
addPointer
(
event
);
recognizer
.
addPointer
(
event
);
}
}
...
@@ -544,7 +544,7 @@ class _PlatformViewGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -544,7 +544,7 @@ class _PlatformViewGestureRecognizer extends OneSequenceGestureRecognizer {
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
s
uper
.
addAllowedPointer
(
event
);
s
tartTrackingPointer
(
event
.
pointer
,
event
.
transform
);
for
(
final
OneSequenceGestureRecognizer
recognizer
in
_gestureRecognizers
)
{
for
(
final
OneSequenceGestureRecognizer
recognizer
in
_gestureRecognizers
)
{
recognizer
.
addPointer
(
event
);
recognizer
.
addPointer
(
event
);
}
}
...
...
packages/flutter/test/gestures/recognizer_test.dart
View file @
3fc40820
...
@@ -2,48 +2,26 @@
...
@@ -2,48 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:ui'
show
VoidCallback
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'gesture_tester.dart'
;
class
TestGestureRecognizer
extends
GestureRecognizer
{
TestGestureRecognizer
({
Object
?
debugOwner
})
:
super
(
debugOwner:
debugOwner
);
// Down/move/up pair 1: normal tap sequence
const
PointerDownEvent
down
=
PointerDownEvent
(
pointer:
5
,
position:
Offset
(
10
,
10
),
);
const
PointerMoveEvent
move
=
PointerMoveEvent
(
pointer:
5
,
position:
Offset
(
15
,
15
),
);
const
PointerUpEvent
up
=
PointerUpEvent
(
@override
pointer:
5
,
String
get
debugDescription
=>
'debugDescription content'
;
position:
Offset
(
15
,
15
),
);
// Down/move/up pair 2: tap sequence with a large move in the middle
@override
const
PointerDownEvent
down2
=
PointerDownEvent
(
void
addPointer
(
PointerDownEvent
event
)
{
}
pointer:
6
,
position:
Offset
(
10
,
10
),
);
const
PointerMoveEvent
move2
=
PointerMoveEvent
(
@override
pointer:
6
,
void
acceptGesture
(
int
pointer
)
{
}
position:
Offset
(
100
,
200
),
);
const
PointerUpEvent
up2
=
PointerUpEvent
(
@override
pointer:
6
,
void
rejectGesture
(
int
pointer
)
{
}
position:
Offset
(
100
,
200
),
}
);
void
main
(
)
{
void
main
(
)
{
setUp
(
ensureGestureBinding
);
test
(
'GestureRecognizer smoketest'
,
()
{
test
(
'GestureRecognizer smoketest'
,
()
{
final
TestGestureRecognizer
recognizer
=
TestGestureRecognizer
(
debugOwner:
0
);
final
TestGestureRecognizer
recognizer
=
TestGestureRecognizer
(
debugOwner:
0
);
expect
(
recognizer
,
hasAGoodToStringDeep
);
expect
(
recognizer
,
hasAGoodToStringDeep
);
...
@@ -86,187 +64,4 @@ void main() {
...
@@ -86,187 +64,4 @@ void main() {
),
),
);
);
});
});
group
(
'PrimaryPointerGestureRecognizer'
,
()
{
testGesture
(
'cleans up state after winning arena'
,
(
GestureTester
tester
)
{
final
List
<
String
>
resolutions
=
<
String
>[];
final
IndefiniteGestureRecognizer
indefinite
=
IndefiniteGestureRecognizer
();
final
TestPrimaryPointerGestureRecognizer
<
PointerUpEvent
>
accepting
=
TestPrimaryPointerGestureRecognizer
<
PointerUpEvent
>(
GestureDisposition
.
accepted
,
onAcceptGesture:
()
=>
resolutions
.
add
(
'accepted'
),
onRejectGesture:
()
=>
resolutions
.
add
(
'rejected'
),
);
expect
(
accepting
.
state
,
GestureRecognizerState
.
ready
);
expect
(
accepting
.
primaryPointer
,
isNull
);
expect
(
accepting
.
initialPosition
,
isNull
);
expect
(
resolutions
,
<
String
>[]);
indefinite
.
addPointer
(
down
);
accepting
.
addPointer
(
down
);
expect
(
accepting
.
state
,
GestureRecognizerState
.
possible
);
expect
(
accepting
.
primaryPointer
,
5
);
expect
(
accepting
.
initialPosition
!.
global
,
down
.
position
);
expect
(
accepting
.
initialPosition
!.
local
,
down
.
localPosition
);
expect
(
resolutions
,
<
String
>[]);
tester
.
closeArena
(
5
);
tester
.
async
.
flushMicrotasks
();
tester
.
route
(
down
);
tester
.
route
(
up
);
expect
(
accepting
.
state
,
GestureRecognizerState
.
ready
);
expect
(
accepting
.
primaryPointer
,
5
);
expect
(
accepting
.
initialPosition
,
isNull
);
expect
(
resolutions
,
<
String
>[
'accepted'
]);
});
testGesture
(
'cleans up state after losing arena'
,
(
GestureTester
tester
)
{
final
List
<
String
>
resolutions
=
<
String
>[];
final
IndefiniteGestureRecognizer
indefinite
=
IndefiniteGestureRecognizer
();
final
TestPrimaryPointerGestureRecognizer
<
PointerMoveEvent
>
rejecting
=
TestPrimaryPointerGestureRecognizer
<
PointerMoveEvent
>(
GestureDisposition
.
rejected
,
onAcceptGesture:
()
=>
resolutions
.
add
(
'accepted'
),
onRejectGesture:
()
=>
resolutions
.
add
(
'rejected'
),
);
expect
(
rejecting
.
state
,
GestureRecognizerState
.
ready
);
expect
(
rejecting
.
primaryPointer
,
isNull
);
expect
(
rejecting
.
initialPosition
,
isNull
);
expect
(
resolutions
,
<
String
>[]);
indefinite
.
addPointer
(
down
);
rejecting
.
addPointer
(
down
);
expect
(
rejecting
.
state
,
GestureRecognizerState
.
possible
);
expect
(
rejecting
.
primaryPointer
,
5
);
expect
(
rejecting
.
initialPosition
!.
global
,
down
.
position
);
expect
(
rejecting
.
initialPosition
!.
local
,
down
.
localPosition
);
expect
(
resolutions
,
<
String
>[]);
tester
.
closeArena
(
5
);
tester
.
async
.
flushMicrotasks
();
tester
.
route
(
down
);
tester
.
route
(
move
);
expect
(
rejecting
.
state
,
GestureRecognizerState
.
defunct
);
expect
(
rejecting
.
primaryPointer
,
5
);
expect
(
rejecting
.
initialPosition
!.
global
,
down
.
position
);
expect
(
rejecting
.
initialPosition
!.
local
,
down
.
localPosition
);
expect
(
resolutions
,
<
String
>[
'rejected'
]);
tester
.
route
(
up
);
expect
(
rejecting
.
state
,
GestureRecognizerState
.
ready
);
expect
(
rejecting
.
primaryPointer
,
5
);
expect
(
rejecting
.
initialPosition
,
isNull
);
expect
(
resolutions
,
<
String
>[
'rejected'
]);
});
testGesture
(
'works properly when recycled'
,
(
GestureTester
tester
)
{
final
List
<
String
>
resolutions
=
<
String
>[];
final
IndefiniteGestureRecognizer
indefinite
=
IndefiniteGestureRecognizer
();
final
TestPrimaryPointerGestureRecognizer
<
PointerUpEvent
>
accepting
=
TestPrimaryPointerGestureRecognizer
<
PointerUpEvent
>(
GestureDisposition
.
accepted
,
preAcceptSlopTolerance:
15
,
postAcceptSlopTolerance:
1000
,
onAcceptGesture:
()
=>
resolutions
.
add
(
'accepted'
),
onRejectGesture:
()
=>
resolutions
.
add
(
'rejected'
),
);
// Send one complete pointer sequence
indefinite
.
addPointer
(
down
);
accepting
.
addPointer
(
down
);
tester
.
closeArena
(
5
);
tester
.
async
.
flushMicrotasks
();
tester
.
route
(
down
);
tester
.
route
(
up
);
expect
(
resolutions
,
<
String
>[
'accepted'
]);
resolutions
.
clear
();
// Send a follow-on sequence that breaks preAcceptSlopTolerance
indefinite
.
addPointer
(
down2
);
accepting
.
addPointer
(
down2
);
tester
.
closeArena
(
6
);
tester
.
async
.
flushMicrotasks
();
tester
.
route
(
down2
);
tester
.
route
(
move2
);
expect
(
resolutions
,
<
String
>[
'rejected'
]);
tester
.
route
(
up2
);
expect
(
resolutions
,
<
String
>[
'rejected'
]);
});
});
}
class
TestGestureRecognizer
extends
GestureRecognizer
{
TestGestureRecognizer
({
Object
?
debugOwner
})
:
super
(
debugOwner:
debugOwner
);
@override
String
get
debugDescription
=>
'debugDescription content'
;
@override
void
addPointer
(
PointerDownEvent
event
)
{
}
@override
void
acceptGesture
(
int
pointer
)
{
}
@override
void
rejectGesture
(
int
pointer
)
{
}
}
/// Gesture recognizer that adds itself to the gesture arena but never
/// resolves itself.
class
IndefiniteGestureRecognizer
extends
GestureRecognizer
{
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
GestureBinding
.
instance
!.
gestureArena
.
add
(
event
.
pointer
,
this
);
}
@override
void
acceptGesture
(
int
pointer
)
{
}
@override
void
rejectGesture
(
int
pointer
)
{
}
@override
String
get
debugDescription
=>
'Unresolving'
;
}
/// Gesture recognizer that resolves with [resolution] when it handles an event
/// on the primary pointer of type [T]
class
TestPrimaryPointerGestureRecognizer
<
T
extends
PointerEvent
>
extends
PrimaryPointerGestureRecognizer
{
TestPrimaryPointerGestureRecognizer
(
this
.
resolution
,
{
this
.
onAcceptGesture
,
this
.
onRejectGesture
,
double
?
preAcceptSlopTolerance
,
double
?
postAcceptSlopTolerance
,
})
:
super
(
preAcceptSlopTolerance:
preAcceptSlopTolerance
,
postAcceptSlopTolerance:
postAcceptSlopTolerance
,
);
final
GestureDisposition
resolution
;
final
VoidCallback
?
onAcceptGesture
;
final
VoidCallback
?
onRejectGesture
;
@override
void
acceptGesture
(
int
pointer
)
{
super
.
acceptGesture
(
pointer
);
if
(
onAcceptGesture
!=
null
)
{
onAcceptGesture
!();
}
}
@override
void
rejectGesture
(
int
pointer
)
{
super
.
rejectGesture
(
pointer
);
if
(
onRejectGesture
!=
null
)
{
onRejectGesture
!();
}
}
@override
void
handlePrimaryPointer
(
PointerEvent
event
)
{
if
(
event
is
T
)
{
resolve
(
resolution
);
}
}
@override
String
get
debugDescription
=>
'TestPrimaryPointer'
;
}
}
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