mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Migrate SemanticsBinding to onSemanticsActionEvent (#128254)
Follow-up to https://github.com/flutter/engine/pull/42493.
This commit is contained in:
parent
130e84ecd2
commit
17f86df8bd
@ -221,11 +221,12 @@ abstract class BindingBase {
|
||||
/// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and
|
||||
/// [WidgetsBinding]. Each of these bindings define behaviors that interact
|
||||
/// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers
|
||||
/// listeners with the [ChannelBuffers], and [RendererBinding]
|
||||
/// listeners with the [ChannelBuffers], [RendererBinding]
|
||||
/// registers [ui.PlatformDispatcher.onMetricsChanged],
|
||||
/// [ui.PlatformDispatcher.onTextScaleFactorChanged],
|
||||
/// [ui.PlatformDispatcher.onSemanticsEnabledChanged], and
|
||||
/// [ui.PlatformDispatcher.onSemanticsAction] handlers.
|
||||
/// [ui.PlatformDispatcher.onTextScaleFactorChanged], and [SemanticsBinding]
|
||||
/// registers [ui.PlatformDispatcher.onSemanticsEnabledChanged],
|
||||
/// [ui.PlatformDispatcher.onSemanticsActionEvent], and
|
||||
/// [ui.PlatformDispatcher.onAccessibilityFeaturesChanged] handlers.
|
||||
///
|
||||
/// Each of these other bindings could individually access a
|
||||
/// [ui.PlatformDispatcher] statically, but that would preclude the ability to
|
||||
|
||||
@ -2,14 +2,14 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui show AccessibilityFeatures, SemanticsAction, SemanticsUpdateBuilder;
|
||||
import 'dart:ui' as ui show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'debug.dart';
|
||||
|
||||
export 'dart:ui' show AccessibilityFeatures, SemanticsUpdateBuilder;
|
||||
export 'dart:ui' show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder;
|
||||
|
||||
/// The glue between the semantics layer and the Flutter engine.
|
||||
mixin SemanticsBinding on BindingBase {
|
||||
@ -20,7 +20,7 @@ mixin SemanticsBinding on BindingBase {
|
||||
_accessibilityFeatures = platformDispatcher.accessibilityFeatures;
|
||||
platformDispatcher
|
||||
..onSemanticsEnabledChanged = _handleSemanticsEnabledChanged
|
||||
..onSemanticsAction = _handleSemanticsAction
|
||||
..onSemanticsActionEvent = _handleSemanticsActionEvent
|
||||
..onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged;
|
||||
_handleSemanticsEnabledChanged();
|
||||
}
|
||||
@ -111,12 +111,12 @@ mixin SemanticsBinding on BindingBase {
|
||||
}
|
||||
}
|
||||
|
||||
void _handleSemanticsAction(int id, ui.SemanticsAction action, ByteData? args) {
|
||||
performSemanticsAction(SemanticsActionEvent(
|
||||
nodeId: id,
|
||||
type: action,
|
||||
arguments: args != null ? const StandardMessageCodec().decodeMessage(args) : null,
|
||||
));
|
||||
void _handleSemanticsActionEvent(ui.SemanticsActionEvent action) {
|
||||
final Object? arguments = action.arguments;
|
||||
final ui.SemanticsActionEvent decodedAction = arguments is ByteData
|
||||
? action.copyWith(arguments: const StandardMessageCodec().decodeMessage(arguments))
|
||||
: action;
|
||||
performSemanticsAction(decodedAction);
|
||||
}
|
||||
|
||||
/// Called whenever the platform requests an action to be performed on a
|
||||
@ -130,9 +130,9 @@ mixin SemanticsBinding on BindingBase {
|
||||
/// perform the given `action` on the [SemanticsNode] specified by
|
||||
/// [SemanticsActionEvent.nodeId].
|
||||
///
|
||||
/// See [dart:ui.PlatformDispatcher.onSemanticsAction].
|
||||
/// See [dart:ui.PlatformDispatcher.onSemanticsActionEvent].
|
||||
@protected
|
||||
void performSemanticsAction(SemanticsActionEvent action);
|
||||
void performSemanticsAction(ui.SemanticsActionEvent action);
|
||||
|
||||
/// The currently active set of [AccessibilityFeatures].
|
||||
///
|
||||
@ -180,27 +180,6 @@ mixin SemanticsBinding on BindingBase {
|
||||
}
|
||||
}
|
||||
|
||||
/// An event to request a [SemanticsAction] of [type] to be performed on the
|
||||
/// [SemanticsNode] identified by [nodeId].
|
||||
///
|
||||
/// Used by [SemanticsBinding.performSemanticsAction].
|
||||
@immutable
|
||||
class SemanticsActionEvent {
|
||||
/// Creates a [SemanticsActionEvent].
|
||||
///
|
||||
/// The [type] and [nodeId] are required.
|
||||
const SemanticsActionEvent({required this.type, required this.nodeId, this.arguments});
|
||||
|
||||
/// The type of action to be performed.
|
||||
final ui.SemanticsAction type;
|
||||
|
||||
/// The id of the [SemanticsNode] on which the action is to be performed.
|
||||
final int nodeId;
|
||||
|
||||
/// Optional arguments for the action.
|
||||
final Object? arguments;
|
||||
}
|
||||
|
||||
/// A reference to the semantics information generated by the framework.
|
||||
///
|
||||
/// Semantics information are only collected when there are clients interested
|
||||
|
||||
@ -42,6 +42,7 @@ void main() {
|
||||
tester.binding.performSemanticsAction(SemanticsActionEvent(
|
||||
type: SemanticsAction.showOnScreen,
|
||||
nodeId: nodeId,
|
||||
viewId: tester.view.viewId,
|
||||
));
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
@ -395,10 +395,10 @@ class TestPlatformDispatcher implements PlatformDispatcher {
|
||||
}
|
||||
|
||||
@override
|
||||
SemanticsActionCallback? get onSemanticsAction => _platformDispatcher.onSemanticsAction;
|
||||
SemanticsActionEventCallback? get onSemanticsActionEvent => _platformDispatcher.onSemanticsActionEvent;
|
||||
@override
|
||||
set onSemanticsAction(SemanticsActionCallback? callback) {
|
||||
_platformDispatcher.onSemanticsAction = callback;
|
||||
set onSemanticsActionEvent(SemanticsActionEventCallback? callback) {
|
||||
_platformDispatcher.onSemanticsActionEvent = callback;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -1880,23 +1880,6 @@ class TestWindow implements SingletonFlutterWindow {
|
||||
platformDispatcher.onSemanticsEnabledChanged = callback;
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
'Use WidgetTester.platformDispatcher.onSemanticsAction instead. '
|
||||
'Deprecated to prepare for the upcoming multi-window support. '
|
||||
'This feature was deprecated after v3.9.0-0.1.pre.'
|
||||
)
|
||||
@override
|
||||
SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction;
|
||||
@Deprecated(
|
||||
'Use WidgetTester.platformDispatcher.onSemanticsAction instead. '
|
||||
'Deprecated to prepare for the upcoming multi-window support. '
|
||||
'This feature was deprecated after v3.9.0-0.1.pre.'
|
||||
)
|
||||
@override
|
||||
set onSemanticsAction(SemanticsActionCallback? callback) {
|
||||
platformDispatcher.onSemanticsAction = callback;
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
'Use WidgetTester.platformDispatcher.accessibilityFeatures instead. '
|
||||
'Deprecated to prepare for the upcoming multi-window support. '
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user