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
c482edac
Unverified
Commit
c482edac
authored
Jun 04, 2019
by
Tong Mu
Committed by
GitHub
Jun 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Move declaration of semantic handlers from detectors to recognizers (#33475)" (#33851)
This reverts commit
572f349f
.
parent
71b8465b
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
115 additions
and
591 deletions
+115
-591
gestures.dart
packages/flutter/lib/gestures.dart
+0
-1
long_press.dart
packages/flutter/lib/src/gestures/long_press.dart
+0
-18
monodrag.dart
packages/flutter/lib/src/gestures/monodrag.dart
+0
-62
recognizer.dart
packages/flutter/lib/src/gestures/recognizer.dart
+0
-16
semantics.dart
packages/flutter/lib/src/gestures/semantics.dart
+0
-69
tap.dart
packages/flutter/lib/src/gestures/tap.dart
+0
-20
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+16
-16
gesture_detector.dart
packages/flutter/lib/src/widgets/gesture_detector.dart
+99
-92
drag_test.dart
packages/flutter/test/gestures/drag_test.dart
+0
-116
long_press_test.dart
packages/flutter/test/gestures/long_press_test.dart
+0
-31
tap_test.dart
packages/flutter/test/gestures/tap_test.dart
+0
-29
gesture_detector_semantics_test.dart
...flutter/test/widgets/gesture_detector_semantics_test.dart
+0
-121
No files found.
packages/flutter/lib/gestures.dart
View file @
c482edac
...
...
@@ -28,7 +28,6 @@ export 'src/gestures/pointer_router.dart';
export
'src/gestures/pointer_signal_resolver.dart'
;
export
'src/gestures/recognizer.dart'
;
export
'src/gestures/scale.dart'
;
export
'src/gestures/semantics.dart'
;
export
'src/gestures/tap.dart'
;
export
'src/gestures/team.dart'
;
export
'src/gestures/velocity_tracker.dart'
;
packages/flutter/lib/src/gestures/long_press.dart
View file @
c482edac
...
...
@@ -6,7 +6,6 @@ import 'arena.dart';
import
'constants.dart'
;
import
'events.dart'
;
import
'recognizer.dart'
;
import
'semantics.dart'
;
/// Callback signature for [LongPressGestureRecognizer.onLongPress].
///
...
...
@@ -215,23 +214,6 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// callback.
GestureLongPressEndCallback
onLongPressEnd
;
@override
SemanticsGestureConfiguration
get
semanticsConfiguration
{
return
_semanticsConfiguration
??=
SemanticsGestureConfiguration
(
onLongPress:
()
{
if
(
onLongPressStart
!=
null
)
onLongPressStart
(
const
LongPressStartDetails
());
if
(
onLongPress
!=
null
)
onLongPress
();
if
(
onLongPressEnd
!=
null
)
onLongPressEnd
(
const
LongPressEndDetails
());
if
(
onLongPressUp
!=
null
)
onLongPressUp
();
},
);
}
SemanticsGestureConfiguration
_semanticsConfiguration
;
@override
bool
isPointerAllowed
(
PointerDownEvent
event
)
{
switch
(
event
.
buttons
)
{
...
...
packages/flutter/lib/src/gestures/monodrag.dart
View file @
c482edac
...
...
@@ -10,7 +10,6 @@ import 'constants.dart';
import
'drag_details.dart'
;
import
'events.dart'
;
import
'recognizer.dart'
;
import
'semantics.dart'
;
import
'velocity_tracker.dart'
;
enum
_DragState
{
...
...
@@ -457,23 +456,6 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer {
PointerDeviceKind
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
@override
SemanticsGestureConfiguration
get
semanticsConfiguration
{
return
_semanticsConfiguration
??=
SemanticsGestureConfiguration
(
onVerticalDragUpdate:
(
DragUpdateDetails
updateDetails
)
{
if
(
onDown
!=
null
)
onDown
(
DragDownDetails
());
if
(
onStart
!=
null
)
onStart
(
DragStartDetails
());
if
(
onUpdate
!=
null
)
onUpdate
(
updateDetails
);
if
(
onEnd
!=
null
)
onEnd
(
DragEndDetails
(
primaryVelocity:
0.0
));
},
);
}
SemanticsGestureConfiguration
_semanticsConfiguration
;
@override
bool
_isFlingGesture
(
VelocityEstimate
estimate
)
{
final
double
minVelocity
=
minFlingVelocity
??
kMinFlingVelocity
;
...
...
@@ -513,23 +495,6 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
PointerDeviceKind
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
@override
SemanticsGestureConfiguration
get
semanticsConfiguration
{
return
_semanticsConfiguration
??=
SemanticsGestureConfiguration
(
onHorizontalDragUpdate:
(
DragUpdateDetails
updateDetails
)
{
if
(
onDown
!=
null
)
onDown
(
DragDownDetails
());
if
(
onStart
!=
null
)
onStart
(
DragStartDetails
());
if
(
onUpdate
!=
null
)
onUpdate
(
updateDetails
);
if
(
onEnd
!=
null
)
onEnd
(
DragEndDetails
(
primaryVelocity:
0.0
));
},
);
}
SemanticsGestureConfiguration
_semanticsConfiguration
;
@override
bool
_isFlingGesture
(
VelocityEstimate
estimate
)
{
final
double
minVelocity
=
minFlingVelocity
??
kMinFlingVelocity
;
...
...
@@ -563,33 +528,6 @@ class PanGestureRecognizer extends DragGestureRecognizer {
/// Create a gesture recognizer for tracking movement on a plane.
PanGestureRecognizer
({
Object
debugOwner
})
:
super
(
debugOwner:
debugOwner
);
@override
SemanticsGestureConfiguration
get
semanticsConfiguration
{
return
_semanticsConfiguration
??=
SemanticsGestureConfiguration
(
onHorizontalDragUpdate:
(
DragUpdateDetails
updateDetails
)
{
if
(
onDown
!=
null
)
onDown
(
DragDownDetails
());
if
(
onStart
!=
null
)
onStart
(
DragStartDetails
());
if
(
onUpdate
!=
null
)
onUpdate
(
updateDetails
);
if
(
onEnd
!=
null
)
onEnd
(
DragEndDetails
());
},
onVerticalDragUpdate:
(
DragUpdateDetails
updateDetails
)
{
if
(
onDown
!=
null
)
onDown
(
DragDownDetails
());
if
(
onStart
!=
null
)
onStart
(
DragStartDetails
());
if
(
onUpdate
!=
null
)
onUpdate
(
updateDetails
);
if
(
onEnd
!=
null
)
onEnd
(
DragEndDetails
());
},
);
}
SemanticsGestureConfiguration
_semanticsConfiguration
;
@override
bool
_isFlingGesture
(
VelocityEstimate
estimate
)
{
final
double
minVelocity
=
minFlingVelocity
??
kMinFlingVelocity
;
...
...
packages/flutter/lib/src/gestures/recognizer.dart
View file @
c482edac
...
...
@@ -15,7 +15,6 @@ import 'constants.dart';
import
'debug.dart'
;
import
'events.dart'
;
import
'pointer_router.dart'
;
import
'semantics.dart'
;
import
'team.dart'
;
export
'pointer_router.dart'
show
PointerRouter
;
...
...
@@ -143,21 +142,6 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
return
_pointerToKind
[
pointer
];
}
/// Returns the semantics configuration of this gesture recognizer, for example
/// for accessibility purposes. It is queried by the recognizer's
/// [RawGestureDetector] to build a collective semantics annotation.
///
/// This method should be overridden by subclasses that are interested in
/// semantic gestures.
///
/// The returned [SemanticsGestureConfiguration] object should be annotated in
/// a manner that describes the current state, and should remain consistant
/// behaviors across different calls. It is recommended to cache the returned
/// object.
SemanticsGestureConfiguration
get
semanticsConfiguration
{
return
null
;
}
/// Releases any resources used by the object.
///
/// This method is called by the owner of this gesture recognizer
...
...
packages/flutter/lib/src/gestures/semantics.dart
deleted
100644 → 0
View file @
71b8465b
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'drag_details.dart'
;
/// Called when the user taps with a semantics device.
typedef
SemanticsTapCallback
=
void
Function
();
/// Called when the user presses for a long period of time with a semantics
/// device.
typedef
SemanticsLongPressCallback
=
void
Function
();
/// Called when the user drags with a semantics device.
typedef
SemanticsDragUpdateCallback
=
void
Function
(
DragUpdateDetails
details
);
/// Describes the semantics configuration of a gesture recognizer, for example
/// for accessibility purposes. It is queried by the recognizer's
/// [RawGestureDetector] to build a collective semantics annotation.
///
/// When a [RawGestureDetector] receives a semantics gesture, it will invoke
/// the corresponding method that each recognizer reports in the configuration.
///
/// See also:
///
/// * [GestureRecognizer.semanticsConfiguration], a method that returns this
/// class.
class
SemanticsGestureConfiguration
{
/// Initialize the semantics handler configuration by declaring the handlers
/// for each kind of semantics events.
SemanticsGestureConfiguration
({
this
.
onTap
,
this
.
onLongPress
,
this
.
onHorizontalDragUpdate
,
this
.
onVerticalDragUpdate
,
});
/// Called when the user taps with a semantics device.
///
/// See also:
///
/// * [RenderSemanticsGestureHandler.onTap], which calls this handler with
/// the help of [RawGestureRecognizer].
final
SemanticsTapCallback
onTap
;
/// Called when the user presses for a long period of time with a semantics
/// device.
///
/// See also:
///
/// * [RenderSemanticsGestureHandler.onLongPress], which calls this handler
/// with the help of [RawGestureRecognizer].
final
SemanticsLongPressCallback
onLongPress
;
/// Called when the user scrolls to the left or to the right with a semantics
/// device.
///
/// See also:
///
/// * [RenderSemanticsGestureHandler.onHorizontalDragUpdate], which calls
/// this handler with the help of [RawGestureRecognizer].
final
SemanticsDragUpdateCallback
onHorizontalDragUpdate
;
/// Called when the user scrolls up or down with a semantics device.
///
/// See also:
///
/// * [RenderSemanticsGestureHandler.onVerticalDragUpdate], which calls
/// this handler with the help of [RawGestureRecognizer].
final
SemanticsDragUpdateCallback
onVerticalDragUpdate
;
}
packages/flutter/lib/src/gestures/tap.dart
View file @
c482edac
...
...
@@ -8,7 +8,6 @@ import 'arena.dart';
import
'constants.dart'
;
import
'events.dart'
;
import
'recognizer.dart'
;
import
'semantics.dart'
;
/// Details for [GestureTapDownCallback], such as position
///
...
...
@@ -238,25 +237,6 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
// different set of buttons, the gesture is canceled.
int
_initialButtons
;
@override
SemanticsGestureConfiguration
get
semanticsConfiguration
{
// This method must always return a non-null configuration with a non-null
// onTap, even when there are no handlers related to semantics, because the
// handler properties are mutable, and assigning properties will not notify
// RawGestureDetector to update its combined configuration.
return
_semanticsConfiguration
??=
SemanticsGestureConfiguration
(
onTap:
()
{
if
(
onTapDown
!=
null
)
onTapDown
(
TapDownDetails
());
if
(
onTapUp
!=
null
)
onTapUp
(
TapUpDetails
());
if
(
onTap
!=
null
)
onTap
();
},
);
}
SemanticsGestureConfiguration
_semanticsConfiguration
;
@override
bool
isPointerAllowed
(
PointerDownEvent
event
)
{
switch
(
event
.
buttons
)
{
...
...
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
c482edac
...
...
@@ -3234,10 +3234,10 @@ class RenderSemanticsGestureHandler extends RenderProxyBox {
/// The [scrollFactor] argument must not be null.
RenderSemanticsGestureHandler
({
RenderBox
child
,
Semantics
TapCallback
onTap
,
Semantics
LongPressCallback
onLongPress
,
Semantics
DragUpdateCallback
onHorizontalDragUpdate
,
Semantics
DragUpdateCallback
onVerticalDragUpdate
,
Gesture
TapCallback
onTap
,
Gesture
LongPressCallback
onLongPress
,
Gesture
DragUpdateCallback
onHorizontalDragUpdate
,
Gesture
DragUpdateCallback
onVerticalDragUpdate
,
this
.
scrollFactor
=
0.8
,
})
:
assert
(
scrollFactor
!=
null
),
_onTap
=
onTap
,
...
...
@@ -3269,9 +3269,9 @@ class RenderSemanticsGestureHandler extends RenderProxyBox {
}
/// Called when the user taps on the render object.
Semantics
TapCallback
get
onTap
=>
_onTap
;
Semantics
TapCallback
_onTap
;
set
onTap
(
Semantics
TapCallback
value
)
{
Gesture
TapCallback
get
onTap
=>
_onTap
;
Gesture
TapCallback
_onTap
;
set
onTap
(
Gesture
TapCallback
value
)
{
if
(
_onTap
==
value
)
return
;
final
bool
hadHandler
=
_onTap
!=
null
;
...
...
@@ -3281,9 +3281,9 @@ class RenderSemanticsGestureHandler extends RenderProxyBox {
}
/// Called when the user presses on the render object for a long period of time.
Semantics
LongPressCallback
get
onLongPress
=>
_onLongPress
;
Semantics
LongPressCallback
_onLongPress
;
set
onLongPress
(
Semantics
LongPressCallback
value
)
{
Gesture
LongPressCallback
get
onLongPress
=>
_onLongPress
;
Gesture
LongPressCallback
_onLongPress
;
set
onLongPress
(
Gesture
LongPressCallback
value
)
{
if
(
_onLongPress
==
value
)
return
;
final
bool
hadHandler
=
_onLongPress
!=
null
;
...
...
@@ -3293,9 +3293,9 @@ class RenderSemanticsGestureHandler extends RenderProxyBox {
}
/// Called when the user scrolls to the left or to the right.
Semantics
DragUpdateCallback
get
onHorizontalDragUpdate
=>
_onHorizontalDragUpdate
;
Semantics
DragUpdateCallback
_onHorizontalDragUpdate
;
set
onHorizontalDragUpdate
(
Semantics
DragUpdateCallback
value
)
{
Gesture
DragUpdateCallback
get
onHorizontalDragUpdate
=>
_onHorizontalDragUpdate
;
Gesture
DragUpdateCallback
_onHorizontalDragUpdate
;
set
onHorizontalDragUpdate
(
Gesture
DragUpdateCallback
value
)
{
if
(
_onHorizontalDragUpdate
==
value
)
return
;
final
bool
hadHandler
=
_onHorizontalDragUpdate
!=
null
;
...
...
@@ -3305,9 +3305,9 @@ class RenderSemanticsGestureHandler extends RenderProxyBox {
}
/// Called when the user scrolls up or down.
Semantics
DragUpdateCallback
get
onVerticalDragUpdate
=>
_onVerticalDragUpdate
;
Semantics
DragUpdateCallback
_onVerticalDragUpdate
;
set
onVerticalDragUpdate
(
Semantics
DragUpdateCallback
value
)
{
Gesture
DragUpdateCallback
get
onVerticalDragUpdate
=>
_onVerticalDragUpdate
;
Gesture
DragUpdateCallback
_onVerticalDragUpdate
;
set
onVerticalDragUpdate
(
Gesture
DragUpdateCallback
value
)
{
if
(
_onVerticalDragUpdate
==
value
)
return
;
final
bool
hadHandler
=
_onVerticalDragUpdate
!=
null
;
...
...
packages/flutter/lib/src/widgets/gesture_detector.dart
View file @
c482edac
...
...
@@ -105,87 +105,6 @@ class GestureRecognizerFactoryWithHandlers<T extends GestureRecognizer> extends
void
initializer
(
T
instance
)
=>
_initializer
(
instance
);
}
// Retrieve semantics handlers from the given recognizers and combine them into
// collective callbacks, one for each kind of semantics gesture.
//
// This class stores the handlers instead of the recognizers, therefore any
// change to the recognzier list needs to be followed by [buildHandlers].
class
_CombinedSemanticsHandlers
{
_CombinedSemanticsHandlers
({
Iterable
<
GestureRecognizer
>
recognizers
,
})
{
buildHandlers
(
recognizers
);
}
final
List
<
SemanticsTapCallback
>
_tapHandlers
=
<
SemanticsTapCallback
>[];
final
List
<
SemanticsLongPressCallback
>
_longPressHandlers
=
<
SemanticsLongPressCallback
>[];
final
List
<
SemanticsDragUpdateCallback
>
_horizontalHandlers
=
<
SemanticsDragUpdateCallback
>[];
final
List
<
SemanticsDragUpdateCallback
>
_verticalHandlers
=
<
SemanticsDragUpdateCallback
>[];
// The following getters of handlers return null unless any recognizers
// show interest in the corresponding kind of semantics gestures.
SemanticsTapCallback
get
onTap
{
return
_tapHandlers
.
isEmpty
?
null
:
_handleTap
;
}
SemanticsLongPressCallback
get
onLongPress
{
return
_longPressHandlers
.
isEmpty
?
null
:
_handleLongPress
;
}
SemanticsDragUpdateCallback
get
onHorizontalDragUpdate
{
return
_horizontalHandlers
.
isEmpty
?
null
:
_handleHorizontalDragUpdate
;
}
SemanticsDragUpdateCallback
get
onVerticalDragUpdate
{
return
_verticalHandlers
.
isEmpty
?
null
:
_handleVerticalDragUpdate
;
}
// Clear internal cache of lists of callbacks, and build anew from the given
// recognziers.
void
buildHandlers
(
Iterable
<
GestureRecognizer
>
recognizers
)
{
_tapHandlers
.
clear
();
_longPressHandlers
.
clear
();
_horizontalHandlers
.
clear
();
_verticalHandlers
.
clear
();
if
(
recognizers
==
null
)
return
;
for
(
GestureRecognizer
recognizer
in
recognizers
)
{
final
SemanticsGestureConfiguration
configuration
=
recognizer
.
semanticsConfiguration
;
if
(
configuration
==
null
)
continue
;
if
(
configuration
.
onTap
!=
null
)
_tapHandlers
.
add
(
configuration
.
onTap
);
if
(
configuration
.
onLongPress
!=
null
)
_longPressHandlers
.
add
(
configuration
.
onLongPress
);
if
(
configuration
.
onHorizontalDragUpdate
!=
null
)
_horizontalHandlers
.
add
(
configuration
.
onHorizontalDragUpdate
);
if
(
configuration
.
onVerticalDragUpdate
!=
null
)
_verticalHandlers
.
add
(
configuration
.
onVerticalDragUpdate
);
}
}
void
_handleTap
()
{
for
(
SemanticsTapCallback
callback
in
_tapHandlers
)
callback
();
}
void
_handleLongPress
()
{
for
(
SemanticsTapCallback
callback
in
_longPressHandlers
)
callback
();
}
void
_handleHorizontalDragUpdate
(
DragUpdateDetails
details
)
{
for
(
SemanticsDragUpdateCallback
callback
in
_horizontalHandlers
)
callback
(
details
);
}
void
_handleVerticalDragUpdate
(
DragUpdateDetails
details
)
{
for
(
SemanticsDragUpdateCallback
callback
in
_verticalHandlers
)
callback
(
details
);
}
}
/// A widget that detects gestures.
///
/// Attempts to recognize gestures that correspond to its non-null callbacks.
...
...
@@ -892,8 +811,6 @@ class RawGestureDetector extends StatefulWidget {
/// State for a [RawGestureDetector].
class
RawGestureDetectorState
extends
State
<
RawGestureDetector
>
{
Map
<
Type
,
GestureRecognizer
>
_recognizers
=
const
<
Type
,
GestureRecognizer
>{};
final
_CombinedSemanticsHandlers
_semanticsHandlers
=
_CombinedSemanticsHandlers
();
@override
void
initState
()
{
...
...
@@ -995,7 +912,6 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
if
(!
_recognizers
.
containsKey
(
type
))
oldRecognizers
[
type
].
dispose
();
}
_semanticsHandlers
.
buildHandlers
(
_recognizers
.
values
);
}
void
_handlePointerDown
(
PointerDownEvent
event
)
{
...
...
@@ -1008,6 +924,92 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
return
widget
.
child
==
null
?
HitTestBehavior
.
translucent
:
HitTestBehavior
.
deferToChild
;
}
void
_handleSemanticsTap
()
{
final
TapGestureRecognizer
recognizer
=
_recognizers
[
TapGestureRecognizer
];
assert
(
recognizer
!=
null
);
if
(
recognizer
.
onTapDown
!=
null
)
recognizer
.
onTapDown
(
TapDownDetails
());
if
(
recognizer
.
onTapUp
!=
null
)
recognizer
.
onTapUp
(
TapUpDetails
());
if
(
recognizer
.
onTap
!=
null
)
recognizer
.
onTap
();
}
void
_handleSemanticsLongPress
()
{
final
LongPressGestureRecognizer
recognizer
=
_recognizers
[
LongPressGestureRecognizer
];
assert
(
recognizer
!=
null
);
if
(
recognizer
.
onLongPressStart
!=
null
)
recognizer
.
onLongPressStart
(
const
LongPressStartDetails
());
if
(
recognizer
.
onLongPress
!=
null
)
recognizer
.
onLongPress
();
if
(
recognizer
.
onLongPressEnd
!=
null
)
recognizer
.
onLongPressEnd
(
const
LongPressEndDetails
());
if
(
recognizer
.
onLongPressUp
!=
null
)
recognizer
.
onLongPressUp
();
}
void
_handleSemanticsHorizontalDragUpdate
(
DragUpdateDetails
updateDetails
)
{
{
final
HorizontalDragGestureRecognizer
recognizer
=
_recognizers
[
HorizontalDragGestureRecognizer
];
if
(
recognizer
!=
null
)
{
if
(
recognizer
.
onDown
!=
null
)
recognizer
.
onDown
(
DragDownDetails
());
if
(
recognizer
.
onStart
!=
null
)
recognizer
.
onStart
(
DragStartDetails
());
if
(
recognizer
.
onUpdate
!=
null
)
recognizer
.
onUpdate
(
updateDetails
);
if
(
recognizer
.
onEnd
!=
null
)
recognizer
.
onEnd
(
DragEndDetails
(
primaryVelocity:
0.0
));
return
;
}
}
{
final
PanGestureRecognizer
recognizer
=
_recognizers
[
PanGestureRecognizer
];
if
(
recognizer
!=
null
)
{
if
(
recognizer
.
onDown
!=
null
)
recognizer
.
onDown
(
DragDownDetails
());
if
(
recognizer
.
onStart
!=
null
)
recognizer
.
onStart
(
DragStartDetails
());
if
(
recognizer
.
onUpdate
!=
null
)
recognizer
.
onUpdate
(
updateDetails
);
if
(
recognizer
.
onEnd
!=
null
)
recognizer
.
onEnd
(
DragEndDetails
());
return
;
}
}
}
void
_handleSemanticsVerticalDragUpdate
(
DragUpdateDetails
updateDetails
)
{
{
final
VerticalDragGestureRecognizer
recognizer
=
_recognizers
[
VerticalDragGestureRecognizer
];
if
(
recognizer
!=
null
)
{
if
(
recognizer
.
onDown
!=
null
)
recognizer
.
onDown
(
DragDownDetails
());
if
(
recognizer
.
onStart
!=
null
)
recognizer
.
onStart
(
DragStartDetails
());
if
(
recognizer
.
onUpdate
!=
null
)
recognizer
.
onUpdate
(
updateDetails
);
if
(
recognizer
.
onEnd
!=
null
)
recognizer
.
onEnd
(
DragEndDetails
(
primaryVelocity:
0.0
));
return
;
}
}
{
final
PanGestureRecognizer
recognizer
=
_recognizers
[
PanGestureRecognizer
];
if
(
recognizer
!=
null
)
{
if
(
recognizer
.
onDown
!=
null
)
recognizer
.
onDown
(
DragDownDetails
());
if
(
recognizer
.
onStart
!=
null
)
recognizer
.
onStart
(
DragStartDetails
());
if
(
recognizer
.
onUpdate
!=
null
)
recognizer
.
onUpdate
(
updateDetails
);
if
(
recognizer
.
onEnd
!=
null
)
recognizer
.
onEnd
(
DragEndDetails
());
return
;
}
}
}
@override
Widget
build
(
BuildContext
context
)
{
Widget
result
=
Listener
(
...
...
@@ -1066,16 +1068,21 @@ class _GestureSemantics extends SingleChildRenderObjectWidget {
_updateHandlers
(
renderObject
);
}
Semantics
TapCallback
get
_onTapHandler
{
return
owner
.
_
semanticsHandlers
.
onTap
;
Gesture
TapCallback
get
_onTapHandler
{
return
owner
.
_
recognizers
.
containsKey
(
TapGestureRecognizer
)
?
owner
.
_handleSemanticsTap
:
null
;
}
SemanticsTapCallback
get
_onLongPressHandler
{
return
owner
.
_semanticsHandlers
.
onLongPress
;
GestureTapCallback
get
_onLongPressHandler
{
return
owner
.
_recognizers
.
containsKey
(
LongPressGestureRecognizer
)
?
owner
.
_handleSemanticsLongPress
:
null
;
}
SemanticsDragUpdateCallback
get
_onHorizontalDragUpdateHandler
{
return
owner
.
_semanticsHandlers
.
onHorizontalDragUpdate
;
GestureDragUpdateCallback
get
_onHorizontalDragUpdateHandler
{
return
owner
.
_recognizers
.
containsKey
(
HorizontalDragGestureRecognizer
)
||
owner
.
_recognizers
.
containsKey
(
PanGestureRecognizer
)
?
owner
.
_handleSemanticsHorizontalDragUpdate
:
null
;
}
SemanticsDragUpdateCallback
get
_onVerticalDragUpdateHandler
{
return
owner
.
_semanticsHandlers
.
onVerticalDragUpdate
;
GestureDragUpdateCallback
get
_onVerticalDragUpdateHandler
{
return
owner
.
_recognizers
.
containsKey
(
VerticalDragGestureRecognizer
)
||
owner
.
_recognizers
.
containsKey
(
PanGestureRecognizer
)
?
owner
.
_handleSemanticsVerticalDragUpdate
:
null
;
}
}
packages/flutter/test/gestures/drag_test.dart
View file @
c482edac
...
...
@@ -845,120 +845,4 @@ void main() {
tap
.
dispose
();
recognized
.
clear
();
});
group
(
'Semantic gesture configuration:'
,
()
{
test
(
'HorizontalDragGestureRecognizer
\'
s semantic handlers are correctly called'
,
()
{
final
List
<
String
>
logs
=
<
String
>[];
final
HorizontalDragGestureRecognizer
drag
=
HorizontalDragGestureRecognizer
()
..
onDown
=
(
_
)
{
logs
.
add
(
'onDown'
);
}
..
onStart
=
(
_
)
{
logs
.
add
(
'onStart'
);
}
..
onUpdate
=
(
_
)
{
logs
.
add
(
'onUpdate'
);
}
..
onEnd
=
(
_
)
{
logs
.
add
(
'onEnd'
);
};
final
SemanticsGestureConfiguration
configuration
=
drag
.
semanticsConfiguration
;
expect
(
configuration
,
isNotNull
);
expect
(
configuration
.
onTap
,
isNull
);
expect
(
configuration
.
onLongPress
,
isNull
);
expect
(
configuration
.
onHorizontalDragUpdate
,
isNotNull
);
expect
(
configuration
.
onVerticalDragUpdate
,
isNull
);
configuration
.
onHorizontalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
11
,
13
),
));
expect
(
logs
,
<
String
>[
'onDown'
,
'onStart'
,
'onUpdate'
,
'onEnd'
]);
logs
.
clear
();
// Assigning handler should update the configuration handler's behavior but
// keep the configuration object
drag
..
onDown
=
null
..
onStart
=
null
..
onUpdate
=
null
..
onEnd
=
null
;
final
SemanticsGestureConfiguration
configuration2
=
drag
.
semanticsConfiguration
;
expect
(
configuration
,
same
(
configuration2
));
configuration
.
onHorizontalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
12
,
14
),
));
expect
(
logs
,
<
String
>[]);
});
test
(
'VerticalDragGestureRecognizer
\'
s semantic handlers are correctly called'
,
()
{
final
List
<
String
>
logs
=
<
String
>[];
final
VerticalDragGestureRecognizer
drag
=
VerticalDragGestureRecognizer
()
..
onDown
=
(
_
)
{
logs
.
add
(
'onDown'
);
}
..
onStart
=
(
_
)
{
logs
.
add
(
'onStart'
);
}
..
onUpdate
=
(
_
)
{
logs
.
add
(
'onUpdate'
);
}
..
onEnd
=
(
_
)
{
logs
.
add
(
'onEnd'
);
};
final
SemanticsGestureConfiguration
configuration
=
drag
.
semanticsConfiguration
;
expect
(
configuration
,
isNotNull
);
expect
(
configuration
.
onTap
,
isNull
);
expect
(
configuration
.
onLongPress
,
isNull
);
expect
(
configuration
.
onHorizontalDragUpdate
,
isNull
);
expect
(
configuration
.
onVerticalDragUpdate
,
isNotNull
);
configuration
.
onVerticalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
11
,
13
),
));
expect
(
logs
,
<
String
>[
'onDown'
,
'onStart'
,
'onUpdate'
,
'onEnd'
]);
logs
.
clear
();
// Assigning handler should update the configuration handler's behavior but
// keep the configuration object
drag
..
onDown
=
null
..
onStart
=
null
..
onUpdate
=
null
..
onEnd
=
null
;
final
SemanticsGestureConfiguration
configuration2
=
drag
.
semanticsConfiguration
;
expect
(
configuration
,
same
(
configuration2
));
configuration
.
onVerticalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
12
,
14
),
));
expect
(
logs
,
<
String
>[]);
});
test
(
'PanGestureRecognizer
\'
s semantic handlers are correctly called'
,
()
{
final
List
<
String
>
logs
=
<
String
>[];
final
PanGestureRecognizer
drag
=
PanGestureRecognizer
()
..
onDown
=
(
_
)
{
logs
.
add
(
'onDown'
);
}
..
onStart
=
(
_
)
{
logs
.
add
(
'onStart'
);
}
..
onUpdate
=
(
_
)
{
logs
.
add
(
'onUpdate'
);
}
..
onEnd
=
(
_
)
{
logs
.
add
(
'onEnd'
);
};
final
SemanticsGestureConfiguration
configuration
=
drag
.
semanticsConfiguration
;
expect
(
configuration
,
isNotNull
);
expect
(
configuration
.
onTap
,
isNull
);
expect
(
configuration
.
onLongPress
,
isNull
);
expect
(
configuration
.
onHorizontalDragUpdate
,
isNotNull
);
expect
(
configuration
.
onVerticalDragUpdate
,
isNotNull
);
configuration
.
onVerticalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
11
,
13
),
));
expect
(
logs
,
<
String
>[
'onDown'
,
'onStart'
,
'onUpdate'
,
'onEnd'
]);
logs
.
clear
();
configuration
.
onHorizontalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
11
,
13
),
));
expect
(
logs
,
<
String
>[
'onDown'
,
'onStart'
,
'onUpdate'
,
'onEnd'
]);
logs
.
clear
();
// Assigning handler should update the configuration handler's behavior but
// keep the configuration object
drag
..
onDown
=
null
..
onStart
=
null
..
onUpdate
=
null
..
onEnd
=
null
;
final
SemanticsGestureConfiguration
configuration2
=
drag
.
semanticsConfiguration
;
expect
(
configuration
,
same
(
configuration2
));
configuration
.
onVerticalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
12
,
14
),
));
configuration
.
onHorizontalDragUpdate
(
DragUpdateDetails
(
globalPosition:
const
Offset
(
12
,
14
),
));
expect
(
logs
,
<
String
>[]);
});
});
}
packages/flutter/test/gestures/long_press_test.dart
View file @
c482edac
...
...
@@ -588,35 +588,4 @@ void main() {
longPress
.
dispose
();
recognized
.
clear
();
});
test
(
'Semantic onLongPress correctly calls handlers'
,
()
{
final
List
<
String
>
logs
=
<
String
>[];
final
LongPressGestureRecognizer
longPress
=
LongPressGestureRecognizer
()
..
onLongPressStart
=
(
_
)
{
logs
.
add
(
'onLongPressStart'
);
}
..
onLongPress
=
()
{
logs
.
add
(
'onLongPress'
);
}
..
onLongPressEnd
=
(
_
)
{
logs
.
add
(
'onLongPressEnd'
);
}
..
onLongPressUp
=
()
{
logs
.
add
(
'onLongPressUp'
);
};
final
SemanticsGestureConfiguration
configuration
=
longPress
.
semanticsConfiguration
;
expect
(
configuration
,
isNotNull
);
expect
(
configuration
.
onTap
,
isNull
);
expect
(
configuration
.
onLongPress
,
isNotNull
);
expect
(
configuration
.
onHorizontalDragUpdate
,
isNull
);
expect
(
configuration
.
onVerticalDragUpdate
,
isNull
);
configuration
.
onLongPress
();
expect
(
logs
,
<
String
>[
'onLongPressStart'
,
'onLongPress'
,
'onLongPressEnd'
,
'onLongPressUp'
]);
logs
.
clear
();
// Assigning handler should update the configuration handler's behavior but
// keep the configuration object
longPress
..
onLongPressStart
=
null
..
onLongPress
=
null
..
onLongPressEnd
=
null
..
onLongPressUp
=
null
;
final
SemanticsGestureConfiguration
configuration2
=
longPress
.
semanticsConfiguration
;
expect
(
configuration
,
same
(
configuration2
));
configuration
.
onLongPress
();
expect
(
logs
,
<
String
>[]);
});
}
packages/flutter/test/gestures/tap_test.dart
View file @
c482edac
...
...
@@ -799,33 +799,4 @@ void main() {
expect
(
recognized
,
<
String
>[
'secondaryCancel'
]);
});
});
test
(
'Semantic onTap correctly calls handlers'
,
()
{
final
List
<
String
>
logs
=
<
String
>[];
final
TapGestureRecognizer
tap
=
TapGestureRecognizer
()
..
onTapDown
=
(
_
)
{
logs
.
add
(
'onTapDown'
);
}
..
onTapUp
=
(
_
)
{
logs
.
add
(
'onTapUp'
);
}
..
onTap
=
()
{
logs
.
add
(
'onTap'
);
};
final
SemanticsGestureConfiguration
configuration
=
tap
.
semanticsConfiguration
;
expect
(
configuration
,
isNotNull
);
expect
(
configuration
.
onTap
,
isNotNull
);
expect
(
configuration
.
onLongPress
,
isNull
);
expect
(
configuration
.
onHorizontalDragUpdate
,
isNull
);
expect
(
configuration
.
onVerticalDragUpdate
,
isNull
);
configuration
.
onTap
();
expect
(
logs
,
<
String
>[
'onTapDown'
,
'onTapUp'
,
'onTap'
]);
logs
.
clear
();
// Assigning handler should update the configuration handler's behavior but
// keep the configuration object
tap
..
onTapDown
=
null
..
onTapUp
=
null
..
onTap
=
null
;
final
SemanticsGestureConfiguration
configuration2
=
tap
.
semanticsConfiguration
;
expect
(
configuration
,
same
(
configuration2
));
configuration
.
onTap
();
expect
(
logs
,
<
String
>[]);
});
}
packages/flutter/test/widgets/gesture_detector_semantics_test.dart
View file @
c482edac
...
...
@@ -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
'package:flutter/gestures.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -77,124 +76,4 @@ void main() {
semantics
.
dispose
();
});
testWidgets
(
'All registered handlers for the gesture kind are called'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
final
Set
<
String
>
logs
=
<
String
>{};
final
GlobalKey
detectorKey
=
GlobalKey
();
await
tester
.
pumpWidget
(
Center
(
child:
GestureDetector
(
key:
detectorKey
,
onHorizontalDragStart:
(
_
)
{
logs
.
add
(
'horizontal'
);
},
onPanStart:
(
_
)
{
logs
.
add
(
'pan'
);
},
child:
Container
(),
),
),
);
final
int
detectorId
=
detectorKey
.
currentContext
.
findRenderObject
().
debugSemantics
.
id
;
tester
.
binding
.
pipelineOwner
.
semanticsOwner
.
performAction
(
detectorId
,
SemanticsAction
.
scrollLeft
);
expect
(
logs
,
<
String
>{
'horizontal'
,
'pan'
});
semantics
.
dispose
();
});
testWidgets
(
'Replacing recognizers should update semantic handlers'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
// How the test is set up:
// - Base state: RawGestureDetector with a HorizontalGR
// - Calling `introduceLayoutPerformer()` adds a `TestLayoutPerformer` as
// child of RawGestureDetector.
// - TestLayoutPerformer calls RawGestureDetector.replaceGestureRecognizers
// during layout phase, which replaces the recognizers with a TapGR.
final
Set
<
String
>
logs
=
<
String
>{};
final
GlobalKey
<
RawGestureDetectorState
>
detectorKey
=
GlobalKey
();
final
VoidCallback
performLayout
=
()
{
detectorKey
.
currentState
.
replaceGestureRecognizers
(<
Type
,
GestureRecognizerFactory
>{
TapGestureRecognizer:
GestureRecognizerFactoryWithHandlers
<
TapGestureRecognizer
>(
()
=>
TapGestureRecognizer
(),
(
TapGestureRecognizer
instance
)
{
instance
..
onTap
=
()
{
logs
.
add
(
'tap'
);
};
},
)
});
};
bool
hasLayoutPerformer
=
false
;
VoidCallback
introduceLayoutPerformer
;
await
tester
.
pumpWidget
(
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setter
)
{
introduceLayoutPerformer
=
()
{
setter
(()
{
hasLayoutPerformer
=
true
;
});
};
return
Center
(
child:
RawGestureDetector
(
key:
detectorKey
,
gestures:
<
Type
,
GestureRecognizerFactory
>{
HorizontalDragGestureRecognizer:
GestureRecognizerFactoryWithHandlers
<
HorizontalDragGestureRecognizer
>(
()
=>
HorizontalDragGestureRecognizer
(),
(
HorizontalDragGestureRecognizer
instance
)
{
instance
..
onStart
=
(
_
)
{
logs
.
add
(
'horizontal'
);
};
},
)
},
child:
hasLayoutPerformer
?
TestLayoutPerformer
(
performLayout:
performLayout
)
:
null
,
),
);
},
),
);
final
int
detectorId
=
detectorKey
.
currentContext
.
findRenderObject
().
debugSemantics
.
id
;
tester
.
binding
.
pipelineOwner
.
semanticsOwner
.
performAction
(
detectorId
,
SemanticsAction
.
scrollLeft
);
expect
(
logs
,
<
String
>{
'horizontal'
});
logs
.
clear
();
introduceLayoutPerformer
();
await
tester
.
pumpAndSettle
();
tester
.
binding
.
pipelineOwner
.
semanticsOwner
.
performAction
(
detectorId
,
SemanticsAction
.
scrollLeft
);
tester
.
binding
.
pipelineOwner
.
semanticsOwner
.
performAction
(
detectorId
,
SemanticsAction
.
tap
);
expect
(
logs
,
<
String
>{
'tap'
});
logs
.
clear
();
semantics
.
dispose
();
});
}
class
TestLayoutPerformer
extends
SingleChildRenderObjectWidget
{
const
TestLayoutPerformer
({
Key
key
,
this
.
performLayout
,
})
:
super
(
key:
key
);
final
VoidCallback
performLayout
;
@override
RenderTestLayoutPerformer
createRenderObject
(
BuildContext
context
)
{
return
RenderTestLayoutPerformer
(
performLayout:
performLayout
);
}
}
class
RenderTestLayoutPerformer
extends
RenderBox
{
RenderTestLayoutPerformer
({
VoidCallback
performLayout
})
:
_performLayout
=
performLayout
;
VoidCallback
_performLayout
;
@override
void
performLayout
()
{
size
=
const
Size
(
1
,
1
);
if
(
_performLayout
!=
null
)
_performLayout
();
}
}
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