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
137ec45d
Unverified
Commit
137ec45d
authored
Feb 27, 2019
by
Michael Goderbauer
Committed by
GitHub
Feb 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call onTapCancel when down pointer gets cancelled (#28546)
parent
3054a935
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
15 deletions
+81
-15
tap.dart
packages/flutter/lib/src/gestures/tap.dart
+5
-1
tap_test.dart
packages/flutter/test/gestures/tap_test.dart
+65
-2
ink_well_test.dart
packages/flutter/test/material/ink_well_test.dart
+1
-1
gesture_detector_test.dart
packages/flutter/test/widgets/gesture_detector_test.dart
+7
-8
text_selection_test.dart
packages/flutter/test/widgets/text_selection_test.dart
+3
-3
No files found.
packages/flutter/lib/src/gestures/tap.dart
View file @
137ec45d
...
...
@@ -174,6 +174,9 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
_finalPosition
=
event
.
position
;
_checkUp
();
}
else
if
(
event
is
PointerCancelEvent
)
{
if
(
_sentTapDown
&&
onTapCancel
!=
null
)
{
invokeCallback
<
void
>(
'onTapCancel'
,
onTapCancel
);
}
_reset
();
}
}
...
...
@@ -183,6 +186,7 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
if
(
_wonArenaForPrimaryPointer
&&
disposition
==
GestureDisposition
.
rejected
)
{
// This can happen if the superclass decides the primary pointer
// exceeded the touch slop, or if the recognizer is disposed.
assert
(
_sentTapDown
);
if
(
onTapCancel
!=
null
)
invokeCallback
<
void
>(
'spontaneous onTapCancel'
,
onTapCancel
);
_reset
();
...
...
@@ -211,7 +215,7 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
if
(
pointer
==
primaryPointer
)
{
// Another gesture won the arena.
assert
(
state
!=
GestureRecognizerState
.
possible
);
if
(
onTapCancel
!=
null
)
if
(
_sentTapDown
&&
onTapCancel
!=
null
)
invokeCallback
<
void
>(
'forced onTapCancel'
,
onTapCancel
);
_reset
();
}
...
...
packages/flutter/test/gestures/tap_test.dart
View file @
137ec45d
...
...
@@ -388,7 +388,6 @@ void main() {
'tapA onTapDown'
,
'tapA onTapUp'
,
'tapA onTap'
,
'tapB onTapCancel'
,
'swept 1'
,
'down 2 to A'
,
'down 2 to B'
,
...
...
@@ -398,10 +397,74 @@ void main() {
'tapA onTapDown'
,
'tapA onTapUp'
,
'tapA onTap'
,
'tapB onTapCancel'
,
'swept 2'
,
'disposed A'
,
'disposed B'
,
]);
});
testGesture
(
'PointerCancelEvent cancels tap'
,
(
GestureTester
tester
)
{
const
PointerDownEvent
down
=
PointerDownEvent
(
pointer:
5
,
position:
Offset
(
10.0
,
10.0
)
);
const
PointerCancelEvent
cancel
=
PointerCancelEvent
(
pointer:
5
,
position:
Offset
(
10.0
,
10.0
)
);
final
TapGestureRecognizer
tap
=
TapGestureRecognizer
();
final
List
<
String
>
recognized
=
<
String
>[];
tap
.
onTapDown
=
(
_
)
{
recognized
.
add
(
'down'
);
};
tap
.
onTapUp
=
(
_
)
{
recognized
.
add
(
'up'
);
};
tap
.
onTap
=
()
{
recognized
.
add
(
'tap'
);
};
tap
.
onTapCancel
=
()
{
recognized
.
add
(
'cancel'
);
};
tap
.
addPointer
(
down
);
tester
.
closeArena
(
5
);
tester
.
async
.
elapse
(
const
Duration
(
milliseconds:
5000
));
expect
(
recognized
,
<
String
>[
'down'
]);
tester
.
route
(
cancel
);
expect
(
recognized
,
<
String
>[
'down'
,
'cancel'
]);
tap
.
dispose
();
});
testGesture
(
'losing tap gesture recognizer does not send onTapCancel'
,
(
GestureTester
tester
)
{
final
TapGestureRecognizer
tap
=
TapGestureRecognizer
();
final
HorizontalDragGestureRecognizer
drag
=
HorizontalDragGestureRecognizer
();
final
List
<
String
>
recognized
=
<
String
>[];
tap
.
onTapDown
=
(
_
)
{
recognized
.
add
(
'down'
);
};
tap
.
onTapUp
=
(
_
)
{
recognized
.
add
(
'up'
);
};
tap
.
onTap
=
()
{
recognized
.
add
(
'tap'
);
};
tap
.
onTapCancel
=
()
{
recognized
.
add
(
'cancel'
);
};
tap
.
addPointer
(
down3
);
drag
.
addPointer
(
down3
);
tester
.
closeArena
(
3
);
tester
.
route
(
move3
);
GestureBinding
.
instance
.
gestureArena
.
sweep
(
3
);
expect
(
recognized
,
isEmpty
);
tap
.
dispose
();
drag
.
dispose
();
});
}
packages/flutter/test/material/ink_well_test.dart
View file @
137ec45d
...
...
@@ -54,7 +54,7 @@ void main() {
await
tester
.
tap
(
find
.
byType
(
InkWell
),
pointer:
2
);
await
tester
.
tap
(
find
.
byType
(
InkWell
),
pointer:
3
);
expect
(
log
,
equals
(<
String
>[
'
tap-cancel'
,
'
double-tap'
]));
expect
(
log
,
equals
(<
String
>[
'double-tap'
]));
log
.
clear
();
await
tester
.
longPress
(
find
.
byType
(
InkWell
),
pointer:
4
);
...
...
packages/flutter/test/widgets/gesture_detector_test.dart
View file @
137ec45d
...
...
@@ -287,33 +287,32 @@ void main() {
);
// Pointer is dragged from the center of the 800x100 gesture detector
// to a point (400,300) below it. This always causes onTapCancel to be
// called; onTap should never be called.
// to a point (400,300) below it. This should never call onTap.
Future
<
void
>
dragOut
(
Duration
timeout
)
async
{
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
400.0
,
50.0
));
// If the timeout is less than kPressTimeout the recognizer will
just trigger
// t
he onTapCancel callback
. If the timeout is greater than kLongPressTimeout
// If the timeout is less than kPressTimeout the recognizer will
not
// t
rigger any callbacks
. If the timeout is greater than kLongPressTimeout
// then onTapDown, onLongPress, and onCancel will be called.
await
tester
.
pump
(
timeout
);
await
gesture
.
moveTo
(
const
Offset
(
400.0
,
300.0
));
await
gesture
.
up
();
}
await
dragOut
(
kPressTimeout
*
0.5
);
// generates
tapCancel
await
dragOut
(
kPressTimeout
*
0.5
);
// generates
nothing
expect
(
tapDown
,
0
);
expect
(
tapCancel
,
1
);
expect
(
tapCancel
,
0
);
expect
(
tap
,
0
);
expect
(
longPress
,
0
);
await
dragOut
(
kPressTimeout
);
// generates tapDown, tapCancel
expect
(
tapDown
,
1
);
expect
(
tapCancel
,
2
);
expect
(
tapCancel
,
1
);
expect
(
tap
,
0
);
expect
(
longPress
,
0
);
await
dragOut
(
kLongPressTimeout
);
// generates tapDown, longPress, tapCancel
expect
(
tapDown
,
2
);
expect
(
tapCancel
,
3
);
expect
(
tapCancel
,
2
);
expect
(
tap
,
0
);
expect
(
longPress
,
1
);
});
...
...
packages/flutter/test/widgets/text_selection_test.dart
View file @
137ec45d
...
...
@@ -119,7 +119,7 @@ void main() {
expect
(
singleLongTapStartCount
,
0
);
});
testWidgets
(
'a very quick swipe is
just a canceled tap
'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'a very quick swipe is
ignored
'
,
(
WidgetTester
tester
)
async
{
await
pumpGestureDetector
(
tester
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
200
,
200
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
20
));
...
...
@@ -127,7 +127,7 @@ void main() {
await
tester
.
pump
();
expect
(
singleTapUpCount
,
0
);
expect
(
tapCount
,
0
);
expect
(
singleTapCancelCount
,
1
);
expect
(
singleTapCancelCount
,
0
);
expect
(
doubleTapDownCount
,
0
);
expect
(
singleLongTapStartCount
,
0
);
...
...
@@ -135,7 +135,7 @@ void main() {
// Nothing else happens on up.
expect
(
singleTapUpCount
,
0
);
expect
(
tapCount
,
0
);
expect
(
singleTapCancelCount
,
1
);
expect
(
singleTapCancelCount
,
0
);
expect
(
doubleTapDownCount
,
0
);
expect
(
singleLongTapStartCount
,
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