Unverified Commit 3aba15f9 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

move to onTapUp (#69422)

parent 22f3cd8a
...@@ -732,11 +732,14 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -732,11 +732,14 @@ class _InkResponseState extends State<_InkResponseStateWidget>
InteractiveInkFeature? _currentSplash; InteractiveInkFeature? _currentSplash;
bool _hovering = false; bool _hovering = false;
final Map<_HighlightType, InkHighlight?> _highlights = <_HighlightType, InkHighlight?>{}; final Map<_HighlightType, InkHighlight?> _highlights = <_HighlightType, InkHighlight?>{};
late Map<Type, Action<Intent>> _actionMap; late final Map<Type, Action<Intent>> _actionMap = <Type, Action<Intent>>{
ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: _simulateTap),
};
bool get highlightsExist => _highlights.values.where((InkHighlight? highlight) => highlight != null).isNotEmpty; bool get highlightsExist => _highlights.values.where((InkHighlight? highlight) => highlight != null).isNotEmpty;
final ObserverList<_ParentInkResponseState> _activeChildren = ObserverList<_ParentInkResponseState>(); final ObserverList<_ParentInkResponseState> _activeChildren = ObserverList<_ParentInkResponseState>();
@override @override
void markChildInkResponsePressed(_ParentInkResponseState childState, bool value) { void markChildInkResponsePressed(_ParentInkResponseState childState, bool value) {
assert(childState != null); assert(childState != null);
...@@ -753,17 +756,19 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -753,17 +756,19 @@ class _InkResponseState extends State<_InkResponseStateWidget>
} }
bool get _anyChildInkResponsePressed => _activeChildren.isNotEmpty; bool get _anyChildInkResponsePressed => _activeChildren.isNotEmpty;
void _handleAction(ActivateIntent intent) { void _simulateTap([ActivateIntent? intent]) {
_startSplash(context: context); _startSplash(context: context);
_handleTap(context); _handleTap();
}
void _simulateLongPress() {
_startSplash(context: context);
_handleLongPress();
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_actionMap = <Type, Action<Intent>>{
ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: _handleAction),
};
FocusManager.instance.addHighlightModeListener(_handleFocusHighlightModeChange); FocusManager.instance.addHighlightModeListener(_handleFocusHighlightModeChange);
} }
...@@ -975,7 +980,7 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -975,7 +980,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
updateHighlight(_HighlightType.pressed, value: true); updateHighlight(_HighlightType.pressed, value: true);
} }
void _handleTap(BuildContext context) { void _handleTap() {
_currentSplash?.confirm(); _currentSplash?.confirm();
_currentSplash = null; _currentSplash = null;
updateHighlight(_HighlightType.pressed, value: false); updateHighlight(_HighlightType.pressed, value: false);
...@@ -1002,7 +1007,7 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -1002,7 +1007,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
widget.onDoubleTap!(); widget.onDoubleTap!();
} }
void _handleLongPress(BuildContext context) { void _handleLongPress() {
_currentSplash?.confirm(); _currentSplash?.confirm();
_currentSplash = null; _currentSplash = null;
if (widget.onLongPress != null) { if (widget.onLongPress != null) {
...@@ -1096,19 +1101,23 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -1096,19 +1101,23 @@ class _InkResponseState extends State<_InkResponseStateWidget>
cursor: effectiveMouseCursor, cursor: effectiveMouseCursor,
onEnter: _handleMouseEnter, onEnter: _handleMouseEnter,
onExit: _handleMouseExit, onExit: _handleMouseExit,
child: Semantics(
onTap: widget.excludeFromSemantics || widget.onTap == null ? null : _simulateTap,
onLongPress: widget.excludeFromSemantics || widget.onLongPress == null ? null : _simulateLongPress,
child: GestureDetector( child: GestureDetector(
onTapDown: enabled ? _handleTapDown : null, onTapDown: enabled ? _handleTapDown : null,
onTap: enabled ? () => _handleTap(context) : null, onTap: enabled ? _handleTap : null,
onTapCancel: enabled ? _handleTapCancel : null, onTapCancel: enabled ? _handleTapCancel : null,
onDoubleTap: widget.onDoubleTap != null ? _handleDoubleTap : null, onDoubleTap: widget.onDoubleTap != null ? _handleDoubleTap : null,
onLongPress: widget.onLongPress != null ? () => _handleLongPress(context) : null, onLongPress: widget.onLongPress != null ? _handleLongPress : null,
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
excludeFromSemantics: widget.excludeFromSemantics, excludeFromSemantics: true,
child: widget.child, child: widget.child,
), ),
), ),
), ),
), ),
),
); );
} }
} }
......
...@@ -1288,4 +1288,48 @@ void main() { ...@@ -1288,4 +1288,48 @@ void main() {
await tester.pumpWidget(buildFrame(enabled: false)); await tester.pumpWidget(buildFrame(enabled: false));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
}); });
testWidgets('InkWell does not attach semantics handler for onTap if it was not provided an onTap handler', (WidgetTester tester) async {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: InkWell(
onLongPress: () { },
child: const Text('Foo'),
),
),
),
));
expect(tester.getSemantics(find.bySemanticsLabel('Foo')), matchesSemantics(
label: 'Foo',
hasTapAction: false,
hasLongPressAction: true,
isFocusable: true,
textDirection: TextDirection.ltr,
));
// Add tap handler and confirm addition to semantic actions.
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: InkWell(
onLongPress: () { },
onTap: () { },
child: const Text('Foo'),
),
),
),
));
expect(tester.getSemantics(find.bySemanticsLabel('Foo')), matchesSemantics(
label: 'Foo',
hasTapAction: true,
hasLongPressAction: true,
isFocusable: true,
textDirection: TextDirection.ltr,
));
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment