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
5d0c090d
Commit
5d0c090d
authored
Oct 26, 2015
by
krisgiesing
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1799 from krisgiesing/tap-fix
Restore previous tap behaviors: no timeout, one pointer
parents
b1b47435
f2fd5e32
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
76 additions
and
38 deletions
+76
-38
constants.dart
packages/flutter/lib/src/gestures/constants.dart
+1
-1
double_tap.dart
packages/flutter/lib/src/gestures/double_tap.dart
+0
-2
long_press.dart
packages/flutter/lib/src/gestures/long_press.dart
+1
-1
show_press.dart
packages/flutter/lib/src/gestures/show_press.dart
+1
-1
tap.dart
packages/flutter/lib/src/gestures/tap.dart
+62
-22
ink_well.dart
packages/flutter/lib/src/material/ink_well.dart
+2
-2
double_tap_test.dart
packages/unit/test/gestures/double_tap_test.dart
+3
-3
tap_test.dart
packages/unit/test/gestures/tap_test.dart
+6
-6
No files found.
packages/flutter/lib/src/gestures/constants.dart
View file @
5d0c090d
...
...
@@ -6,7 +6,7 @@
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java
const
Duration
kLongPressTimeout
=
const
Duration
(
milliseconds:
500
);
const
Duration
k
Tap
Timeout
=
const
Duration
(
milliseconds:
100
);
const
Duration
k
Press
Timeout
=
const
Duration
(
milliseconds:
100
);
const
Duration
kJumpTapTimeout
=
const
Duration
(
milliseconds:
500
);
const
Duration
kDoubleTapTimeout
=
const
Duration
(
milliseconds:
300
);
const
Duration
kDoubleTapMinTime
=
const
Duration
(
milliseconds:
40
);
...
...
packages/flutter/lib/src/gestures/double_tap.dart
View file @
5d0c090d
...
...
@@ -52,7 +52,6 @@ class DoubleTapGestureRecognizer extends DisposableArenaMember {
entry:
GestureArena
.
instance
.
add
(
event
.
pointer
,
this
)
);
_trackers
[
event
.
pointer
]
=
tracker
;
tracker
.
startTimer
(()
=>
_reject
(
tracker
));
tracker
.
startTrackingPointer
(
router
,
handleEvent
);
}
...
...
@@ -145,7 +144,6 @@ class DoubleTapGestureRecognizer extends DisposableArenaMember {
}
void
_freezeTracker
(
TapTracker
tracker
)
{
tracker
.
stopTimer
();
tracker
.
stopTrackingPointer
(
router
,
handleEvent
);
}
...
...
packages/flutter/lib/src/gestures/long_press.dart
View file @
5d0c090d
...
...
@@ -12,7 +12,7 @@ typedef void GestureLongPressCallback();
class
LongPressGestureRecognizer
extends
PrimaryPointerGestureRecognizer
{
LongPressGestureRecognizer
({
PointerRouter
router
,
this
.
onLongPress
})
:
super
(
router:
router
,
deadline:
k
TapTimeout
+
k
LongPressTimeout
);
:
super
(
router:
router
,
deadline:
kLongPressTimeout
);
GestureLongPressCallback
onLongPress
;
...
...
packages/flutter/lib/src/gestures/show_press.dart
View file @
5d0c090d
...
...
@@ -11,7 +11,7 @@ typedef void GestureShowPressCallback();
class
ShowPressGestureRecognizer
extends
PrimaryPointerGestureRecognizer
{
ShowPressGestureRecognizer
({
PointerRouter
router
,
this
.
onShowPress
})
:
super
(
router:
router
,
deadline:
k
Tap
Timeout
);
:
super
(
router:
router
,
deadline:
k
Press
Timeout
);
GestureShowPressCallback
onShowPress
;
...
...
packages/flutter/lib/src/gestures/tap.dart
View file @
5d0c090d
...
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:ui'
as
ui
;
import
'arena.dart'
;
...
...
@@ -13,9 +12,56 @@ import 'recognizer.dart';
typedef
void
GestureTapCallback
(
);
enum
TapResolution
{
tap
,
cancel
/// TapGestureRecognizer is a tap recognizer that tracks only one primary
/// pointer per gesture. That is, during tap recognition, extra pointer events
/// are ignored: down-1, down-2, up-1, up-2 produces only one tap on up-1.
class
TapGestureRecognizer
extends
PrimaryPointerGestureRecognizer
{
TapGestureRecognizer
({
PointerRouter
router
,
this
.
onTap
})
:
super
(
router:
router
);
GestureTapCallback
onTap
;
GestureTapCallback
onTapDown
;
GestureTapCallback
onTapCancel
;
bool
_wonArena
=
false
;
bool
_didTap
=
false
;
void
handlePrimaryPointer
(
PointerInputEvent
event
)
{
if
(
event
.
type
==
'pointerdown'
)
{
if
(
onTapDown
!=
null
)
onTapDown
();
}
else
if
(
event
.
type
==
'pointerup'
)
{
_didTap
=
true
;
_check
();
}
}
void
acceptGesture
(
int
pointer
)
{
super
.
acceptGesture
(
pointer
);
if
(
pointer
==
primaryPointer
)
{
_wonArena
=
true
;
_check
();
}
}
void
rejectGesture
(
int
pointer
)
{
super
.
rejectGesture
(
pointer
);
if
(
pointer
==
primaryPointer
)
{
assert
(
state
==
GestureRecognizerState
.
defunct
);
_wonArena
=
false
;
_didTap
=
false
;
if
(
onTapCancel
!=
null
)
onTapCancel
();
}
}
void
_check
()
{
if
(
_wonArena
&&
_didTap
)
{
resolve
(
GestureDisposition
.
accepted
);
if
(
onTap
!=
null
)
onTap
();
}
}
}
/// TapTracker helps track individual tap sequences as part of a
...
...
@@ -33,18 +79,6 @@ class TapTracker {
GestureArenaEntry
entry
;
ui
.
Point
_initialPosition
;
bool
_isTrackingPointer
;
Timer
_timer
;
void
startTimer
(
void
callback
())
{
_timer
??=
new
Timer
(
kTapTimeout
,
callback
);
}
void
stopTimer
()
{
if
(
_timer
!=
null
)
{
_timer
.
cancel
();
_timer
=
null
;
}
}
void
startTrackingPointer
(
PointerRouter
router
,
PointerRoute
route
)
{
if
(!
_isTrackingPointer
)
{
...
...
@@ -67,6 +101,11 @@ class TapTracker {
}
enum
TapResolution
{
tap
,
cancel
}
/// TapGesture represents a full gesture resulting from a single tap
/// sequence. Tap gestures are passive, meaning that they will not
/// pre-empt any other arena member in play.
...
...
@@ -77,11 +116,10 @@ class TapGesture extends TapTracker {
entry
=
GestureArena
.
instance
.
add
(
event
.
pointer
,
gestureRecognizer
);
_wonArena
=
false
;
_didTap
=
false
;
startTimer
(
cancel
);
startTrackingPointer
(
gestureRecognizer
.
router
,
handleEvent
);
}
TapGestureRecognizer
gestureRecognizer
;
Multi
TapGestureRecognizer
gestureRecognizer
;
bool
_wonArena
;
bool
_didTap
;
...
...
@@ -93,7 +131,6 @@ class TapGesture extends TapTracker {
}
else
if
(
event
.
type
==
'pointercancel'
)
{
cancel
();
}
else
if
(
event
.
type
==
'pointerup'
)
{
stopTimer
();
stopTrackingPointer
(
gestureRecognizer
.
router
,
handleEvent
);
_didTap
=
true
;
_check
();
...
...
@@ -106,7 +143,6 @@ class TapGesture extends TapTracker {
}
void
reject
()
{
stopTimer
();
stopTrackingPointer
(
gestureRecognizer
.
router
,
handleEvent
);
gestureRecognizer
.
_resolveTap
(
pointer
,
TapResolution
.
cancel
);
}
...
...
@@ -127,8 +163,12 @@ class TapGesture extends TapTracker {
}
class
TapGestureRecognizer
extends
DisposableArenaMember
{
TapGestureRecognizer
({
this
.
router
,
this
.
onTap
,
this
.
onTapDown
,
this
.
onTapCancel
});
/// MultiTapGestureRecognizer is a tap recognizer that treats taps
/// independently. That is, each pointer sequence that could resolve to a tap
/// does so independently of others: down-1, down-2, up-1, up-2 produces two
/// taps, on up-1 and up-2.
class
MultiTapGestureRecognizer
extends
DisposableArenaMember
{
MultiTapGestureRecognizer
({
this
.
router
,
this
.
onTap
,
this
.
onTapDown
,
this
.
onTapCancel
});
PointerRouter
router
;
GestureTapCallback
onTap
;
...
...
packages/flutter/lib/src/material/ink_well.dart
View file @
5d0c090d
...
...
@@ -35,8 +35,8 @@ class _InkSplash {
duration:
new
Duration
(
milliseconds:
(
_targetRadius
/
_kSplashUnconfirmedVelocity
).
floor
())
)..
addListener
(
_handleRadiusChange
);
// Wait k
Tap
Timeout to avoid creating tiny splashes during scrolls.
_startTimer
=
new
Timer
(
k
Tap
Timeout
,
_play
);
// Wait k
Press
Timeout to avoid creating tiny splashes during scrolls.
_startTimer
=
new
Timer
(
k
Press
Timeout
,
_play
);
}
final
Point
position
;
...
...
packages/unit/test/gestures/double_tap_test.dart
View file @
5d0c090d
...
...
@@ -223,7 +223,7 @@ void main() {
tap
.
dispose
();
});
test
(
'Intra-tap delay
cancels
double tap'
,
()
{
test
(
'Intra-tap delay
does not cancel
double tap'
,
()
{
PointerRouter
router
=
new
PointerRouter
();
DoubleTapGestureRecognizer
tap
=
new
DoubleTapGestureRecognizer
(
router:
router
);
...
...
@@ -252,9 +252,9 @@ void main() {
expect
(
doubleTapRecognized
,
isFalse
);
router
.
route
(
up2
);
expect
(
doubleTapRecognized
,
is
Fals
e
);
expect
(
doubleTapRecognized
,
is
Tru
e
);
GestureArena
.
instance
.
sweep
(
2
);
expect
(
doubleTapRecognized
,
is
Fals
e
);
expect
(
doubleTapRecognized
,
is
Tru
e
);
});
tap
.
dispose
();
...
...
packages/unit/test/gestures/tap_test.dart
View file @
5d0c090d
...
...
@@ -84,7 +84,7 @@ void main() {
tap
.
dispose
();
});
test
(
'Should recognize two overlapping taps'
,
()
{
test
(
'Should
not
recognize two overlapping taps'
,
()
{
PointerRouter
router
=
new
PointerRouter
();
TapGestureRecognizer
tap
=
new
TapGestureRecognizer
(
router:
router
);
...
...
@@ -112,9 +112,9 @@ void main() {
expect
(
tapsRecognized
,
1
);
router
.
route
(
up2
);
expect
(
tapsRecognized
,
2
);
expect
(
tapsRecognized
,
1
);
GestureArena
.
instance
.
sweep
(
2
);
expect
(
tapsRecognized
,
2
);
expect
(
tapsRecognized
,
1
);
tap
.
dispose
();
});
...
...
@@ -144,7 +144,7 @@ void main() {
tap
.
dispose
();
});
test
(
'Timeout
cancels
tap'
,
()
{
test
(
'Timeout
does not cancel
tap'
,
()
{
PointerRouter
router
=
new
PointerRouter
();
TapGestureRecognizer
tap
=
new
TapGestureRecognizer
(
router:
router
);
...
...
@@ -163,9 +163,9 @@ void main() {
async
.
elapse
(
new
Duration
(
milliseconds:
500
));
expect
(
tapRecognized
,
isFalse
);
router
.
route
(
up1
);
expect
(
tapRecognized
,
is
Fals
e
);
expect
(
tapRecognized
,
is
Tru
e
);
GestureArena
.
instance
.
sweep
(
1
);
expect
(
tapRecognized
,
is
Fals
e
);
expect
(
tapRecognized
,
is
Tru
e
);
});
tap
.
dispose
();
...
...
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