move to onTapUp (#69422)
This commit is contained in:
parent
22f3cd8a67
commit
3aba15f95d
@ -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>
|
|||||||
}
|
}
|
||||||
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>
|
|||||||
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>
|
|||||||
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,15 +1101,19 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
|||||||
cursor: effectiveMouseCursor,
|
cursor: effectiveMouseCursor,
|
||||||
onEnter: _handleMouseEnter,
|
onEnter: _handleMouseEnter,
|
||||||
onExit: _handleMouseExit,
|
onExit: _handleMouseExit,
|
||||||
child: GestureDetector(
|
child: Semantics(
|
||||||
onTapDown: enabled ? _handleTapDown : null,
|
onTap: widget.excludeFromSemantics || widget.onTap == null ? null : _simulateTap,
|
||||||
onTap: enabled ? () => _handleTap(context) : null,
|
onLongPress: widget.excludeFromSemantics || widget.onLongPress == null ? null : _simulateLongPress,
|
||||||
onTapCancel: enabled ? _handleTapCancel : null,
|
child: GestureDetector(
|
||||||
onDoubleTap: widget.onDoubleTap != null ? _handleDoubleTap : null,
|
onTapDown: enabled ? _handleTapDown : null,
|
||||||
onLongPress: widget.onLongPress != null ? () => _handleLongPress(context) : null,
|
onTap: enabled ? _handleTap : null,
|
||||||
behavior: HitTestBehavior.opaque,
|
onTapCancel: enabled ? _handleTapCancel : null,
|
||||||
excludeFromSemantics: widget.excludeFromSemantics,
|
onDoubleTap: widget.onDoubleTap != null ? _handleDoubleTap : null,
|
||||||
child: widget.child,
|
onLongPress: widget.onLongPress != null ? _handleLongPress : null,
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
excludeFromSemantics: true,
|
||||||
|
child: widget.child,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -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,
|
||||||
|
));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user