Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fc71b65

Browse files
authored
Put the view focus functionality behind a (disabled by default) flag (#52527)
Put the view focus functionality behind a (disabled by default) flag Should unblock flutter/flutter#143259 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 0605d72 commit fc71b65

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/web_ui/lib/src/engine/platform_dispatcher/view_focus_binding.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'package:meta/meta.dart';
67
import 'package:ui/src/engine.dart';
78
import 'package:ui/ui.dart' as ui;
89

910
/// Tracks the [FlutterView]s focus changes.
1011
final class ViewFocusBinding {
1112
ViewFocusBinding(this._viewManager, this._onViewFocusChange);
1213

14+
15+
/// Wether [FlutterView] focus changes will be reported and performed.
16+
///
17+
/// DO NOT rely on this bit as it will go away soon. You're warned :)!
18+
@visibleForTesting
19+
static bool isEnabled = false;
20+
1321
final FlutterViewManager _viewManager;
1422
final ui.ViewFocusChangeCallback _onViewFocusChange;
1523

@@ -35,6 +43,9 @@ final class ViewFocusBinding {
3543
}
3644

3745
void changeViewFocus(int viewId, ui.ViewFocusState state) {
46+
if (!isEnabled) {
47+
return;
48+
}
3849
final DomElement? viewElement = _viewManager[viewId]?.dom.rootElement;
3950

4051
if (state == ui.ViewFocusState.focused) {
@@ -69,6 +80,10 @@ final class ViewFocusBinding {
6980
});
7081

7182
void _handleFocusChange(DomElement? focusedElement) {
83+
if (!isEnabled) {
84+
return;
85+
}
86+
7287
final int? viewId = _viewId(focusedElement);
7388
if (viewId == _lastViewId) {
7489
return;

lib/web_ui/test/engine/platform_dispatcher/view_focus_binding_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ void testMain() {
1717
late EnginePlatformDispatcher dispatcher;
1818

1919
setUp(() {
20-
domDocument.activeElement?.blur();
21-
EngineSemantics.instance.semanticsEnabled = false;
20+
ViewFocusBinding.isEnabled = true;
2221

2322
dispatcher = EnginePlatformDispatcher.instance;
2423
dispatchedViewFocusEvents = <ui.ViewFocusEvent>[];
2524
dispatcher.onViewFocusChange = dispatchedViewFocusEvents.add;
2625
});
2726

27+
tearDown(() {
28+
ViewFocusBinding.isEnabled = false;
29+
EngineSemantics.instance.semanticsEnabled = false;
30+
});
31+
2832
test('The view is focusable and reachable by keyboard when registered', () async {
2933
final EngineFlutterView view = createAndRegisterView(dispatcher);
3034

0 commit comments

Comments
 (0)