Put the view focus functionality behind a (disabled by default) flag (flutter/engine#52527)
Put the view focus functionality behind a (disabled by default) flag Should unblock https://github.com/flutter/flutter/pull/143259 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
@@ -10,6 +11,13 @@ import 'package:ui/ui.dart' as ui;
|
||||
final class ViewFocusBinding {
|
||||
ViewFocusBinding(this._viewManager, this._onViewFocusChange);
|
||||
|
||||
|
||||
/// Wether [FlutterView] focus changes will be reported and performed.
|
||||
///
|
||||
/// DO NOT rely on this bit as it will go away soon. You're warned :)!
|
||||
@visibleForTesting
|
||||
static bool isEnabled = false;
|
||||
|
||||
final FlutterViewManager _viewManager;
|
||||
final ui.ViewFocusChangeCallback _onViewFocusChange;
|
||||
|
||||
@@ -35,6 +43,9 @@ final class ViewFocusBinding {
|
||||
}
|
||||
|
||||
void changeViewFocus(int viewId, ui.ViewFocusState state) {
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
final DomElement? viewElement = _viewManager[viewId]?.dom.rootElement;
|
||||
|
||||
if (state == ui.ViewFocusState.focused) {
|
||||
@@ -69,6 +80,10 @@ final class ViewFocusBinding {
|
||||
});
|
||||
|
||||
void _handleFocusChange(DomElement? focusedElement) {
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int? viewId = _viewId(focusedElement);
|
||||
if (viewId == _lastViewId) {
|
||||
return;
|
||||
|
||||
@@ -17,14 +17,18 @@ void testMain() {
|
||||
late EnginePlatformDispatcher dispatcher;
|
||||
|
||||
setUp(() {
|
||||
domDocument.activeElement?.blur();
|
||||
EngineSemantics.instance.semanticsEnabled = false;
|
||||
ViewFocusBinding.isEnabled = true;
|
||||
|
||||
dispatcher = EnginePlatformDispatcher.instance;
|
||||
dispatchedViewFocusEvents = <ui.ViewFocusEvent>[];
|
||||
dispatcher.onViewFocusChange = dispatchedViewFocusEvents.add;
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
ViewFocusBinding.isEnabled = false;
|
||||
EngineSemantics.instance.semanticsEnabled = false;
|
||||
});
|
||||
|
||||
test('The view is focusable and reachable by keyboard when registered', () async {
|
||||
final EngineFlutterView view = createAndRegisterView(dispatcher);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user