Skip to content

Commit 0e4cb8e

Browse files
auto-submit[bot]auto-submit[bot]
andauthored
Reverts "Add framework-side hitTestBehavior support to Semantics (flutter#178817)" (flutter#179100)
<!-- start_original_pr_link --> Reverts: flutter#178817 <!-- end_original_pr_link --> <!-- start_initiating_author --> Initiated by: Piinks <!-- end_initiating_author --> <!-- start_revert_reason --> Reason for reverting: change was landed during tree closure <!-- end_revert_reason --> <!-- start_original_pr_author --> Original PR Author: flutter-zl <!-- end_original_pr_author --> <!-- start_reviewers --> Reviewed By: {chunhtai} <!-- end_reviewers --> <!-- start_revert_body --> This change reverts the following previous change: This is a reland of flutter#177570, which was reverted in flutter#178744 due to test failures. The original PR introduced `hitTestBehavior` to the semantics framework but incorrectly applied `opaque` behavior to `ModalRoute`, which blocked platform views from receiving pointer events. Instead of making the entire modal opaque, we: 1. Keep `ModalRoute` without explicit `hitTestBehavior` (defaults to `defer`) 2. Make only the dialog/sheet content opaque (blocks clicks to barrier) 3. Platform views remain clickable because they're outside the opaque content boundary Fixes flutter#149001 Original PR: flutter#177570 Revert: flutter#178744 <!-- end_revert_body --> Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com>
1 parent 8f3f89f commit 0e4cb8e

File tree

14 files changed

+88
-407
lines changed

14 files changed

+88
-407
lines changed

packages/flutter/lib/src/material/bottom_sheet.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
library;
77

88
import 'dart:math' as math;
9-
import 'dart:ui' show SemanticsHitTestBehavior;
109

1110
import 'package:flutter/foundation.dart';
1211
import 'package:flutter/gestures.dart';
@@ -1118,13 +1117,10 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
11181117
),
11191118
);
11201119

1121-
Widget bottomSheet = useSafeArea
1120+
final Widget bottomSheet = useSafeArea
11221121
? SafeArea(bottom: false, child: content)
11231122
: MediaQuery.removePadding(context: context, removeTop: true, child: content);
11241123

1125-
// Prevent clicks inside the bottom sheet from passing through to the barrier
1126-
bottomSheet = Semantics(hitTestBehavior: SemanticsHitTestBehavior.opaque, child: bottomSheet);
1127-
11281124
return capturedThemes?.wrap(bottomSheet) ?? bottomSheet;
11291125
}
11301126

packages/flutter/lib/src/material/dialog.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// @docImport 'text_button.dart';
1111
library;
1212

13-
import 'dart:ui' show SemanticsHitTestBehavior, SemanticsRole, clampDouble, lerpDouble;
13+
import 'dart:ui' show SemanticsRole, clampDouble, lerpDouble;
1414

1515
import 'package:flutter/cupertino.dart';
1616
import 'package:flutter/foundation.dart';
@@ -1676,8 +1676,6 @@ class DialogRoute<T> extends RawDialogRoute<T> {
16761676
if (useSafeArea) {
16771677
dialog = SafeArea(child: dialog);
16781678
}
1679-
// Prevent clicks inside the dialog from passing through to the barrier
1680-
dialog = Semantics(hitTestBehavior: SemanticsHitTestBehavior.opaque, child: dialog);
16811679
return dialog;
16821680
},
16831681
barrierLabel: barrierLabel ?? MaterialLocalizations.of(context).modalBarrierDismissLabel,

packages/flutter/lib/src/rendering/custom_paint.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,6 @@ class RenderCustomPaint extends RenderProxyBox {
10461046
if (config.validationResult != properties.validationResult) {
10471047
config.validationResult = properties.validationResult;
10481048
}
1049-
if (properties.hitTestBehavior != null) {
1050-
config.hitTestBehavior = properties.hitTestBehavior!;
1051-
}
10521049
if (properties.inputType != null) {
10531050
config.inputType = properties.inputType!;
10541051
}

packages/flutter/lib/src/rendering/object.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4940,10 +4940,6 @@ mixin SemanticsAnnotationsMixin on RenderObject {
49404940
config.validationResult = _properties.validationResult;
49414941
}
49424942

4943-
if (_properties.hitTestBehavior != null) {
4944-
config.hitTestBehavior = _properties.hitTestBehavior!;
4945-
}
4946-
49474943
if (_properties.inputType != null) {
49484944
config.inputType = _properties.inputType!;
49494945
}

packages/flutter/lib/src/rendering/platform_view.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
/// @docImport 'package:flutter/widgets.dart';
66
library;
77

8-
import 'dart:ui' as ui show SemanticsHitTestBehavior;
9-
108
import 'package:flutter/foundation.dart';
119
import 'package:flutter/gestures.dart';
1210
import 'package:flutter/scheduler.dart';
@@ -269,9 +267,6 @@ class RenderAndroidView extends PlatformViewRenderBox {
269267

270268
if (_viewController.isCreated) {
271269
config.platformViewId = _viewController.viewId;
272-
// Platform views should allow pointer events to pass through to the
273-
// underlying platform view content.
274-
config.hitTestBehavior = ui.SemanticsHitTestBehavior.transparent;
275270
}
276271
}
277272
}
@@ -377,9 +372,6 @@ abstract class RenderDarwinPlatformView<T extends DarwinPlatformViewController>
377372
super.describeSemanticsConfiguration(config);
378373
config.isSemanticBoundary = true;
379374
config.platformViewId = _viewController.id;
380-
// Platform views should allow pointer events to pass through to the
381-
// underlying platform view content.
382-
config.hitTestBehavior = ui.SemanticsHitTestBehavior.transparent;
383375
}
384376

385377
@override
@@ -745,9 +737,6 @@ class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin {
745737
super.describeSemanticsConfiguration(config);
746738
config.isSemanticBoundary = true;
747739
config.platformViewId = _controller.viewId;
748-
// Platform views should allow pointer events to pass through to the
749-
// underlying platform view content.
750-
config.hitTestBehavior = ui.SemanticsHitTestBehavior.transparent;
751740
}
752741
}
753742

packages/flutter/lib/src/semantics/semantics.dart

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import 'dart:ui'
2828
StringAttribute,
2929
TextDirection,
3030
Tristate;
31-
import 'dart:ui' as ui show SemanticsHitTestBehavior;
3231

3332
import 'package:collection/collection.dart';
3433
import 'package:flutter/foundation.dart';
@@ -1021,7 +1020,6 @@ class SemanticsData with Diagnosticable {
10211020
required this.role,
10221021
required this.controlsNodes,
10231022
required this.validationResult,
1024-
required this.hitTestBehavior,
10251023
required this.inputType,
10261024
required this.locale,
10271025
this.tags,
@@ -1290,9 +1288,6 @@ class SemanticsData with Diagnosticable {
12901288
/// {@macro flutter.semantics.SemanticsProperties.validationResult}
12911289
final SemanticsValidationResult validationResult;
12921290

1293-
/// {@macro flutter.semantics.SemanticsProperties.hitTestBehavior}
1294-
final ui.SemanticsHitTestBehavior hitTestBehavior;
1295-
12961291
/// {@macro flutter.semantics.SemanticsNode.inputType}
12971292
final SemanticsInputType inputType;
12981293

@@ -1420,7 +1415,6 @@ class SemanticsData with Diagnosticable {
14201415
other.role == role &&
14211416
other.validationResult == validationResult &&
14221417
other.inputType == inputType &&
1423-
other.hitTestBehavior == hitTestBehavior &&
14241418
_sortedListsEqual(other.customSemanticsActionIds, customSemanticsActionIds) &&
14251419
setEquals<String>(controlsNodes, other.controlsNodes);
14261420
}
@@ -1457,7 +1451,8 @@ class SemanticsData with Diagnosticable {
14571451
validationResult,
14581452
controlsNodes == null ? null : Object.hashAll(controlsNodes!),
14591453
inputType,
1460-
hitTestBehavior,
1454+
traversalParentIdentifier,
1455+
traversalChildIdentifier,
14611456
),
14621457
);
14631458

@@ -1616,7 +1611,6 @@ class SemanticsProperties extends DiagnosticableTree {
16161611
this.controlsNodes,
16171612
this.inputType,
16181613
this.validationResult = SemanticsValidationResult.none,
1619-
this.hitTestBehavior,
16201614
this.onTap,
16211615
this.onLongPress,
16221616
this.onScrollLeft,
@@ -2561,13 +2555,6 @@ class SemanticsProperties extends DiagnosticableTree {
25612555
/// {@endtemplate}
25622556
final SemanticsValidationResult validationResult;
25632557

2564-
/// {@template flutter.semantics.SemanticsProperties.hitTestBehavior}
2565-
/// Describes how the semantic node should behave during hit testing.
2566-
///
2567-
/// See [ui.SemanticsHitTestBehavior] for more details.
2568-
/// {@endtemplate}
2569-
final ui.SemanticsHitTestBehavior? hitTestBehavior;
2570-
25712558
/// {@template flutter.semantics.SemanticsProperties.inputType}
25722559
/// The input type for of a editable widget.
25732560
///
@@ -3248,8 +3235,7 @@ class SemanticsNode with DiagnosticableTreeMixin {
32483235
_headingLevel != config._headingLevel ||
32493236
_linkUrl != config._linkUrl ||
32503237
_role != config.role ||
3251-
_validationResult != config.validationResult ||
3252-
_hitTestBehavior != config.hitTestBehavior;
3238+
_validationResult != config.validationResult;
32533239
}
32543240

32553241
// TAGS, LABELS, ACTIONS
@@ -3543,10 +3529,6 @@ class SemanticsNode with DiagnosticableTreeMixin {
35433529
SemanticsValidationResult get validationResult => _validationResult;
35443530
SemanticsValidationResult _validationResult = _kEmptyConfig.validationResult;
35453531

3546-
/// {@macro flutter.semantics.SemanticsProperties.hitTestBehavior}
3547-
ui.SemanticsHitTestBehavior get hitTestBehavior => _hitTestBehavior;
3548-
ui.SemanticsHitTestBehavior _hitTestBehavior = ui.SemanticsHitTestBehavior.defer;
3549-
35503532
/// {@template flutter.semantics.SemanticsNode.inputType}
35513533
/// The input type for of a editable node.
35523534
///
@@ -3627,7 +3609,6 @@ class SemanticsNode with DiagnosticableTreeMixin {
36273609
_role = config._role;
36283610
_controlsNodes = config._controlsNodes;
36293611
_validationResult = config._validationResult;
3630-
_hitTestBehavior = config._hitTestBehavior;
36313612
_inputType = config._inputType;
36323613
_locale = config.locale;
36333614

@@ -3682,7 +3663,6 @@ class SemanticsNode with DiagnosticableTreeMixin {
36823663
SemanticsRole role = _role;
36833664
Set<String>? controlsNodes = _controlsNodes;
36843665
SemanticsValidationResult validationResult = _validationResult;
3685-
ui.SemanticsHitTestBehavior hitTestBehavior = _hitTestBehavior;
36863666
SemanticsInputType inputType = _inputType;
36873667
final Locale? locale = _locale;
36883668
final Set<int> customSemanticsActionIds = <int>{};
@@ -3747,9 +3727,6 @@ class SemanticsNode with DiagnosticableTreeMixin {
37473727
if (inputType == SemanticsInputType.none) {
37483728
inputType = node._inputType;
37493729
}
3750-
if (hitTestBehavior == ui.SemanticsHitTestBehavior.defer) {
3751-
hitTestBehavior = node._hitTestBehavior;
3752-
}
37533730
if (tooltip == '') {
37543731
tooltip = node._tooltip;
37553732
}
@@ -3841,7 +3818,6 @@ class SemanticsNode with DiagnosticableTreeMixin {
38413818
role: role,
38423819
controlsNodes: controlsNodes,
38433820
validationResult: validationResult,
3844-
hitTestBehavior: hitTestBehavior,
38453821
inputType: inputType,
38463822
locale: locale,
38473823
);
@@ -4013,7 +3989,6 @@ class SemanticsNode with DiagnosticableTreeMixin {
40133989
role: data.role,
40143990
controlsNodes: data.controlsNodes?.toList(),
40153991
validationResult: data.validationResult,
4016-
hitTestBehavior: data.hitTestBehavior,
40173992
inputType: data.inputType,
40183993
locale: data.locale,
40193994
);
@@ -6440,14 +6415,6 @@ class SemanticsConfiguration {
64406415
_hasBeenAnnotated = true;
64416416
}
64426417

6443-
/// {@macro flutter.semantics.SemanticsProperties.hitTestBehavior}
6444-
ui.SemanticsHitTestBehavior get hitTestBehavior => _hitTestBehavior;
6445-
ui.SemanticsHitTestBehavior _hitTestBehavior = ui.SemanticsHitTestBehavior.defer;
6446-
set hitTestBehavior(ui.SemanticsHitTestBehavior value) {
6447-
_hitTestBehavior = value;
6448-
_hasBeenAnnotated = true;
6449-
}
6450-
64516418
/// {@macro flutter.semantics.SemanticsProperties.inputType}
64526419
SemanticsInputType get inputType => _inputType;
64536420
SemanticsInputType _inputType = SemanticsInputType.none;
@@ -6556,10 +6523,6 @@ class SemanticsConfiguration {
65566523
if (_hasExplicitRole && other._hasExplicitRole) {
65576524
return false;
65586525
}
6559-
if (_hitTestBehavior != ui.SemanticsHitTestBehavior.defer ||
6560-
other._hitTestBehavior != ui.SemanticsHitTestBehavior.defer) {
6561-
return false;
6562-
}
65636526
return true;
65646527
}
65656528

@@ -6670,11 +6633,6 @@ class SemanticsConfiguration {
66706633
child._accessiblityFocusBlockType,
66716634
);
66726635

6673-
if (_hitTestBehavior == ui.SemanticsHitTestBehavior.defer &&
6674-
child._hitTestBehavior != ui.SemanticsHitTestBehavior.defer) {
6675-
_hitTestBehavior = child._hitTestBehavior;
6676-
}
6677-
66786636
_hasBeenAnnotated = hasBeenAnnotated || child.hasBeenAnnotated;
66796637
}
66806638

@@ -6720,8 +6678,7 @@ class SemanticsConfiguration {
67206678
.._role = _role
67216679
.._controlsNodes = _controlsNodes
67226680
.._validationResult = _validationResult
6723-
.._inputType = _inputType
6724-
.._hitTestBehavior = _hitTestBehavior;
6681+
.._inputType = _inputType;
67256682
}
67266683
}
67276684

packages/flutter/lib/src/widgets/basic.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
library;
1010

1111
import 'dart:math' as math;
12-
import 'dart:ui'
13-
as ui
14-
show Image, ImageFilter, SemanticsHitTestBehavior, SemanticsInputType, TextHeightBehavior;
12+
import 'dart:ui' as ui show Image, ImageFilter, SemanticsInputType, TextHeightBehavior;
1513

1614
import 'package:flutter/animation.dart';
1715
import 'package:flutter/foundation.dart';
@@ -4050,7 +4048,6 @@ sealed class _SemanticsBase extends SingleChildRenderObjectWidget {
40504048
required SemanticsRole? role,
40514049
required Set<String>? controlsNodes,
40524050
required SemanticsValidationResult validationResult,
4053-
required ui.SemanticsHitTestBehavior? hitTestBehavior,
40544051
required ui.SemanticsInputType? inputType,
40554052
required Locale? localeForSubtree,
40564053
}) : this.fromProperties(
@@ -4136,7 +4133,6 @@ sealed class _SemanticsBase extends SingleChildRenderObjectWidget {
41364133
role: role,
41374134
controlsNodes: controlsNodes,
41384135
validationResult: validationResult,
4139-
hitTestBehavior: hitTestBehavior,
41404136
inputType: inputType,
41414137
),
41424138
);
@@ -4386,7 +4382,6 @@ class SliverSemantics extends _SemanticsBase {
43864382
super.role,
43874383
super.controlsNodes,
43884384
super.validationResult = SemanticsValidationResult.none,
4389-
super.hitTestBehavior,
43904385
super.inputType,
43914386
super.localeForSubtree,
43924387
}) : super(child: sliver);
@@ -7969,7 +7964,6 @@ class Semantics extends _SemanticsBase {
79697964
super.role,
79707965
super.controlsNodes,
79717966
super.validationResult = SemanticsValidationResult.none,
7972-
super.hitTestBehavior,
79737967
super.inputType,
79747968
super.localeForSubtree,
79757969
});

packages/flutter/lib/src/widgets/routes.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,6 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
23132313
// To be sorted before the _modalBarrier.
23142314
return _modalScopeCache ??= Semantics(
23152315
sortKey: const OrdinalSortKey(0.0),
2316-
hitTestBehavior: ui.SemanticsHitTestBehavior.opaque,
23172316
child: _ModalScope<T>(
23182317
key: _scopeKey,
23192318
route: this,
@@ -2617,7 +2616,6 @@ class RawDialogRoute<T> extends PopupRoute<T> {
26172616
return Semantics(
26182617
scopesRoute: true,
26192618
explicitChildNodes: true,
2620-
hitTestBehavior: ui.SemanticsHitTestBehavior.opaque,
26212619
child: DisplayFeatureSubScreen(
26222620
anchorPoint: anchorPoint,
26232621
child: _pageBuilder(context, animation, secondaryAnimation),

0 commit comments

Comments
 (0)