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
2225405f
Commit
2225405f
authored
Oct 27, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a position to the onTap callback
Fixes #1807
parent
e77cad81
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
39 deletions
+61
-39
main.dart
examples/game/lib/main.dart
+1
-1
tap.dart
packages/flutter/lib/src/gestures/tap.dart
+46
-28
ink_well.dart
packages/flutter/lib/src/material/ink_well.dart
+2
-2
gesture_detector.dart
packages/flutter/lib/src/widgets/gesture_detector.dart
+12
-8
No files found.
examples/game/lib/main.dart
View file @
2225405f
...
...
@@ -169,7 +169,7 @@ class TextureButtonState extends State<TextureButton> {
)
)
),
onTapDown:
()
{
onTapDown:
(
_
)
{
setState
(()
{
_highlight
=
true
;
});
...
...
packages/flutter/lib/src/gestures/tap.dart
View file @
2225405f
...
...
@@ -11,28 +11,37 @@ import 'events.dart';
import
'pointer_router.dart'
;
import
'recognizer.dart'
;
typedef
void
GestureTapDownCallback
(
ui
.
Point
globalPosition
);
typedef
void
GestureTapUpCallback
(
ui
.
Point
globalPosition
);
typedef
void
GestureTapCallback
(
);
typedef
void
GestureTapCancelCallback
(
);
/// 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
);
TapGestureRecognizer
({
PointerRouter
router
,
this
.
onTapDown
,
this
.
onTapUp
,
this
.
onTap
,
this
.
onTapCancel
})
:
super
(
router:
router
);
GestureTapDownCallback
onTapDown
;
GestureTapDownCallback
onTapUp
;
GestureTapCallback
onTap
;
GestureTapCallback
onTapDown
;
GestureTapCallback
onTapCancel
;
GestureTapCancelCallback
onTapCancel
;
bool
_wonArena
=
false
;
bool
_didTap
=
false
;
Point
_finalPosition
;
void
handlePrimaryPointer
(
PointerInputEvent
event
)
{
if
(
event
.
type
==
'pointerdown'
)
{
if
(
onTapDown
!=
null
)
onTapDown
();
onTapDown
(
event
.
position
);
}
else
if
(
event
.
type
==
'pointerup'
)
{
_
didTap
=
true
;
_
finalPosition
=
event
.
position
;
_check
();
}
}
...
...
@@ -50,15 +59,17 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
if
(
pointer
==
primaryPointer
)
{
assert
(
state
==
GestureRecognizerState
.
defunct
);
_wonArena
=
false
;
_
didTap
=
false
;
_
finalPosition
=
null
;
if
(
onTapCancel
!=
null
)
onTapCancel
();
}
}
void
_check
()
{
if
(
_wonArena
&&
_
didTap
)
{
if
(
_wonArena
&&
_
finalPosition
!=
null
)
{
resolve
(
GestureDisposition
.
accepted
);
if
(
onTapUp
!=
null
)
onTapUp
(
_finalPosition
);
if
(
onTap
!=
null
)
onTap
();
}
...
...
@@ -76,7 +87,7 @@ class _TapTracker {
assert
(
event
.
type
==
'pointerdown'
);
}
int
pointer
;
final
int
pointer
;
GestureArenaEntry
entry
;
ui
.
Point
_initialPosition
;
bool
_isTrackingPointer
;
...
...
@@ -102,7 +113,7 @@ class _TapTracker {
}
enum
TapResolution
{
enum
_
TapResolution
{
tap
,
cancel
}
...
...
@@ -113,17 +124,15 @@ enum TapResolution {
class
_TapGesture
extends
_TapTracker
{
_TapGesture
({
this
.
gestureRecognizer
,
PointerInputEvent
event
})
:
super
(
event:
event
)
{
:
super
(
event:
event
)
{
entry
=
GestureArena
.
instance
.
add
(
event
.
pointer
,
gestureRecognizer
);
_wonArena
=
false
;
_didTap
=
false
;
startTrackingPointer
(
gestureRecognizer
.
router
,
handleEvent
);
}
MultiTapGestureRecognizer
gestureRecognizer
;
final
MultiTapGestureRecognizer
gestureRecognizer
;
bool
_wonArena
;
bool
_didTap
;
bool
_wonArena
=
false
;
ui
.
Point
_finalPosition
;
void
handleEvent
(
PointerInputEvent
event
)
{
assert
(
event
.
pointer
==
pointer
);
...
...
@@ -133,7 +142,7 @@ class _TapGesture extends _TapTracker {
cancel
();
}
else
if
(
event
.
type
==
'pointerup'
)
{
stopTrackingPointer
(
gestureRecognizer
.
router
,
handleEvent
);
_
didTap
=
true
;
_
finalPosition
=
event
.
position
;
_check
();
}
}
...
...
@@ -145,7 +154,7 @@ class _TapGesture extends _TapTracker {
void
reject
()
{
stopTrackingPointer
(
gestureRecognizer
.
router
,
handleEvent
);
gestureRecognizer
.
_resolveTap
(
pointer
,
TapResolution
.
cance
l
);
gestureRecognizer
.
_resolveTap
(
pointer
,
_TapResolution
.
cancel
,
nul
l
);
}
void
cancel
()
{
...
...
@@ -158,8 +167,8 @@ class _TapGesture extends _TapTracker {
}
void
_check
()
{
if
(
_wonArena
&&
_
didTap
)
gestureRecognizer
.
_resolveTap
(
pointer
,
TapResolution
.
tap
);
if
(
_wonArena
&&
_
finalPosition
!=
null
)
gestureRecognizer
.
_resolveTap
(
pointer
,
_TapResolution
.
tap
,
_finalPosition
);
}
}
...
...
@@ -169,12 +178,19 @@ class _TapGesture extends _TapTracker {
/// 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
});
MultiTapGestureRecognizer
({
this
.
router
,
this
.
onTapDown
,
this
.
onTapUp
,
this
.
onTap
,
this
.
onTapCancel
});
PointerRouter
router
;
GestureTapDownCallback
onTapDown
;
GestureTapDownCallback
onTapUp
;
GestureTapCallback
onTap
;
GestureTapCallback
onTapDown
;
GestureTapCallback
onTapCancel
;
GestureTapCancelCallback
onTapCancel
;
Map
<
int
,
_TapGesture
>
_gestureMap
=
new
Map
<
int
,
_TapGesture
>();
...
...
@@ -185,7 +201,7 @@ class MultiTapGestureRecognizer extends DisposableArenaMember {
event:
event
);
if
(
onTapDown
!=
null
)
onTapDown
();
onTapDown
(
event
.
position
);
}
void
acceptGesture
(
int
pointer
)
{
...
...
@@ -198,9 +214,11 @@ class MultiTapGestureRecognizer extends DisposableArenaMember {
_gestureMap
[
pointer
]?.
reject
();
}
void
_resolveTap
(
int
pointer
,
TapResolution
resolu
tion
)
{
void
_resolveTap
(
int
pointer
,
_TapResolution
resolution
,
ui
.
Point
globalPosi
tion
)
{
_gestureMap
.
remove
(
pointer
);
if
(
resolution
==
TapResolution
.
tap
)
{
if
(
resolution
==
_TapResolution
.
tap
)
{
if
(
onTapUp
!=
null
)
onTapUp
(
globalPosition
);
if
(
onTap
!=
null
)
onTap
();
}
else
{
...
...
packages/flutter/lib/src/material/ink_well.dart
View file @
2225405f
...
...
@@ -41,7 +41,7 @@ class InkWell extends StatefulComponent {
final
_HighlightChangedCallback
onHighlightChanged
;
final
Color
defaultColor
;
final
Color
highlightColor
;
_InkWellState
createState
()
=>
new
_InkWellState
();
}
...
...
@@ -237,7 +237,7 @@ class _RenderInkSplashes extends RenderProxyBox {
_longPress
=
null
;
}
void
_handleTapDown
()
{
void
_handleTapDown
(
_
)
{
if
(
onHighlightChanged
!=
null
)
onHighlightChanged
(
true
);
}
...
...
packages/flutter/lib/src/widgets/gesture_detector.dart
View file @
2225405f
...
...
@@ -9,9 +9,10 @@ import 'basic.dart';
import
'framework.dart'
;
export
'package:flutter/gestures.dart'
show
GestureTapDownCallback
,
GestureTapUpCallback
,
GestureTapCallback
,
GestureTapCallback
,
GestureTapCallback
,
GestureTapCancelCallback
,
GestureShowPressCallback
,
GestureLongPressCallback
,
GestureDragStartCallback
,
...
...
@@ -31,10 +32,11 @@ class GestureDetector extends StatefulComponent {
const
GestureDetector
({
Key
key
,
this
.
child
,
this
.
onTap
,
this
.
onDoubleTap
,
this
.
onTapDown
,
this
.
onTapUp
,
this
.
onTap
,
this
.
onTapCancel
,
this
.
onDoubleTap
,
this
.
onShowPress
,
this
.
onLongPress
,
this
.
onVerticalDragStart
,
...
...
@@ -53,9 +55,10 @@ class GestureDetector extends StatefulComponent {
final
Widget
child
;
final
GestureTapDownCallback
onTapDown
;
final
GestureTapDownCallback
onTapUp
;
final
GestureTapCallback
onTap
;
final
GestureTapCallback
onTapDown
;
final
GestureTapCallback
onTapCancel
;
final
GestureTapCancelCallback
onTapCancel
;
final
GestureTapCallback
onDoubleTap
;
final
GestureShowPressCallback
onShowPress
;
...
...
@@ -125,13 +128,14 @@ class _GestureDetectorState extends State<GestureDetector> {
}
void
_syncTap
()
{
if
(
config
.
onTap
==
null
&&
config
.
onTapDown
==
null
&&
config
.
onTapCancel
==
null
)
{
if
(
config
.
onTap
Down
==
null
&&
config
.
onTapUp
==
null
&&
config
.
onTap
==
null
&&
config
.
onTapCancel
==
null
)
{
_tap
=
_ensureDisposed
(
_tap
);
}
else
{
_tap
??=
new
TapGestureRecognizer
(
router:
_router
);
_tap
..
onTap
=
config
.
onTap
..
onTapDown
=
config
.
onTapDown
..
onTapUp
=
config
.
onTapUp
..
onTap
=
config
.
onTap
..
onTapCancel
=
config
.
onTapCancel
;
}
}
...
...
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