Skip to content

Commit d2af134

Browse files
author
Casey Hillers
authored
Revert "Fix Slider semantic node size (#115285)" (#116294)
This reverts commit 8473da2.
1 parent 29422d2 commit d2af134

File tree

4 files changed

+504
-233
lines changed

4 files changed

+504
-233
lines changed

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

+57-75
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,22 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
821821
// in range_slider.dart.
822822
Size screenSize() => MediaQuery.of(context).size;
823823

824-
void handleDidGainAccessibilityFocus() {
825-
// Automatically activate the slider when it receives a11y focus.
826-
if (!focusNode.hasFocus && focusNode.canRequestFocus) {
827-
focusNode.requestFocus();
828-
}
824+
VoidCallback? handleDidGainAccessibilityFocus;
825+
switch (theme.platform) {
826+
case TargetPlatform.android:
827+
case TargetPlatform.fuchsia:
828+
case TargetPlatform.iOS:
829+
case TargetPlatform.linux:
830+
case TargetPlatform.macOS:
831+
break;
832+
case TargetPlatform.windows:
833+
handleDidGainAccessibilityFocus = () {
834+
// Automatically activate the slider when it receives a11y focus.
835+
if (!focusNode.hasFocus && focusNode.canRequestFocus) {
836+
focusNode.requestFocus();
837+
}
838+
};
839+
break;
829840
}
830841

831842
final Map<ShortcutActivator, Intent> shortcutMap;
@@ -846,35 +857,38 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
846857
? math.min(MediaQuery.of(context).textScaleFactor, 1.3)
847858
: MediaQuery.of(context).textScaleFactor;
848859

849-
return FocusableActionDetector(
850-
actions: _actionMap,
851-
shortcuts: shortcutMap,
852-
focusNode: focusNode,
853-
autofocus: widget.autofocus,
854-
enabled: _enabled,
855-
onShowFocusHighlight: _handleFocusHighlightChanged,
856-
onShowHoverHighlight: _handleHoverChanged,
857-
mouseCursor: effectiveMouseCursor,
858-
includeFocusSemantics: false,
859-
child: CompositedTransformTarget(
860-
link: _layerLink,
861-
child: _SliderRenderObjectWidget(
862-
key: _renderObjectKey,
863-
value: _convert(widget.value),
864-
secondaryTrackValue: (widget.secondaryTrackValue != null) ? _convert(widget.secondaryTrackValue!) : null,
865-
divisions: widget.divisions,
866-
label: widget.label,
867-
sliderTheme: sliderTheme,
868-
textScaleFactor: textScaleFactor,
869-
screenSize: screenSize(),
870-
onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null,
871-
onChangeStart: _handleDragStart,
872-
onChangeEnd: _handleDragEnd,
873-
state: this,
874-
semanticFormatterCallback: widget.semanticFormatterCallback,
875-
onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,
876-
hasFocus: _focused,
877-
hovering: _hovering,
860+
return Semantics(
861+
container: true,
862+
slider: true,
863+
onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,
864+
child: FocusableActionDetector(
865+
actions: _actionMap,
866+
shortcuts: shortcutMap,
867+
focusNode: focusNode,
868+
autofocus: widget.autofocus,
869+
enabled: _enabled,
870+
onShowFocusHighlight: _handleFocusHighlightChanged,
871+
onShowHoverHighlight: _handleHoverChanged,
872+
mouseCursor: effectiveMouseCursor,
873+
child: CompositedTransformTarget(
874+
link: _layerLink,
875+
child: _SliderRenderObjectWidget(
876+
key: _renderObjectKey,
877+
value: _convert(widget.value),
878+
secondaryTrackValue: (widget.secondaryTrackValue != null) ? _convert(widget.secondaryTrackValue!) : null,
879+
divisions: widget.divisions,
880+
label: widget.label,
881+
sliderTheme: sliderTheme,
882+
textScaleFactor: textScaleFactor,
883+
screenSize: screenSize(),
884+
onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null,
885+
onChangeStart: _handleDragStart,
886+
onChangeEnd: _handleDragEnd,
887+
state: this,
888+
semanticFormatterCallback: widget.semanticFormatterCallback,
889+
hasFocus: _focused,
890+
hovering: _hovering,
891+
),
878892
),
879893
),
880894
);
@@ -935,7 +949,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
935949
required this.onChangeEnd,
936950
required this.state,
937951
required this.semanticFormatterCallback,
938-
required this.onDidGainAccessibilityFocus,
939952
required this.hasFocus,
940953
required this.hovering,
941954
});
@@ -951,7 +964,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
951964
final ValueChanged<double>? onChangeStart;
952965
final ValueChanged<double>? onChangeEnd;
953966
final SemanticFormatterCallback? semanticFormatterCallback;
954-
final VoidCallback? onDidGainAccessibilityFocus;
955967
final _SliderState state;
956968
final bool hasFocus;
957969
final bool hovering;
@@ -972,7 +984,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
972984
state: state,
973985
textDirection: Directionality.of(context),
974986
semanticFormatterCallback: semanticFormatterCallback,
975-
onDidGainAccessibilityFocus: onDidGainAccessibilityFocus,
976987
platform: Theme.of(context).platform,
977988
hasFocus: hasFocus,
978989
hovering: hovering,
@@ -997,7 +1008,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
9971008
..onChangeEnd = onChangeEnd
9981009
..textDirection = Directionality.of(context)
9991010
..semanticFormatterCallback = semanticFormatterCallback
1000-
..onDidGainAccessibilityFocus = onDidGainAccessibilityFocus
10011011
..platform = Theme.of(context).platform
10021012
..hasFocus = hasFocus
10031013
..hovering = hovering
@@ -1019,7 +1029,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
10191029
required TargetPlatform platform,
10201030
required ValueChanged<double>? onChanged,
10211031
required SemanticFormatterCallback? semanticFormatterCallback,
1022-
required this.onDidGainAccessibilityFocus,
10231032
required this.onChangeStart,
10241033
required this.onChangeEnd,
10251034
required _SliderState state,
@@ -1105,7 +1114,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
11051114
bool _active = false;
11061115
double _currentDragValue = 0.0;
11071116
Rect? overlayRect;
1108-
late Offset _thumbCenter;
11091117

11101118
// This rect is used in gesture calculations, where the gesture coordinates
11111119
// are relative to the sliders origin. Therefore, the offset is passed as
@@ -1251,7 +1259,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
12511259
}
12521260
}
12531261

1254-
VoidCallback? onDidGainAccessibilityFocus;
12551262
ValueChanged<double>? onChangeStart;
12561263
ValueChanged<double>? onChangeEnd;
12571264

@@ -1575,10 +1582,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
15751582
sliderTheme: _sliderTheme,
15761583
isDiscrete: isDiscrete,
15771584
);
1578-
_thumbCenter = Offset(trackRect.left + visualPosition * trackRect.width, trackRect.center.dy);
1585+
final Offset thumbCenter = Offset(trackRect.left + visualPosition * trackRect.width, trackRect.center.dy);
15791586
if (isInteractive) {
15801587
final Size overlaySize = sliderTheme.overlayShape!.getPreferredSize(isInteractive, false);
1581-
overlayRect = Rect.fromCircle(center: _thumbCenter, radius: overlaySize.width / 2.0);
1588+
overlayRect = Rect.fromCircle(center: thumbCenter, radius: overlaySize.width / 2.0);
15821589
}
15831590
final Offset? secondaryOffset = (secondaryVisualPosition != null) ? Offset(trackRect.left + secondaryVisualPosition * trackRect.width, trackRect.center.dy) : null;
15841591

@@ -1589,7 +1596,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
15891596
sliderTheme: _sliderTheme,
15901597
enableAnimation: _enableAnimation,
15911598
textDirection: _textDirection,
1592-
thumbCenter: _thumbCenter,
1599+
thumbCenter: thumbCenter,
15931600
secondaryOffset: secondaryOffset,
15941601
isDiscrete: isDiscrete,
15951602
isEnabled: isInteractive,
@@ -1598,7 +1605,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
15981605
if (!_overlayAnimation.isDismissed) {
15991606
_sliderTheme.overlayShape!.paint(
16001607
context,
1601-
_thumbCenter,
1608+
thumbCenter,
16021609
activationAnimation: _overlayAnimation,
16031610
enableAnimation: _enableAnimation,
16041611
isDiscrete: isDiscrete,
@@ -1635,7 +1642,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
16351642
sliderTheme: _sliderTheme,
16361643
enableAnimation: _enableAnimation,
16371644
textDirection: _textDirection,
1638-
thumbCenter: _thumbCenter,
1645+
thumbCenter: thumbCenter,
16391646
isEnabled: isInteractive,
16401647
);
16411648
}
@@ -1648,7 +1655,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
16481655
if (attached) {
16491656
_sliderTheme.valueIndicatorShape!.paint(
16501657
context,
1651-
offset + _thumbCenter,
1658+
offset + thumbCenter,
16521659
activationAnimation: _valueIndicatorAnimation,
16531660
enableAnimation: _enableAnimation,
16541661
isDiscrete: isDiscrete,
@@ -1667,7 +1674,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
16671674

16681675
_sliderTheme.thumbShape!.paint(
16691676
context,
1670-
_thumbCenter,
1677+
thumbCenter,
16711678
activationAnimation: _overlayAnimation,
16721679
enableAnimation: _enableAnimation,
16731680
isDiscrete: isDiscrete,
@@ -1681,47 +1688,22 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
16811688
);
16821689
}
16831690

1684-
@override
1685-
void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, Iterable<SemanticsNode> children) {
1686-
node.rect = Rect.fromCenter(
1687-
center: _thumbCenter,
1688-
width: kMinInteractiveDimension,
1689-
height: kMinInteractiveDimension,
1690-
);
1691-
1692-
node.updateWith(config: config);
1693-
}
1694-
16951691
@override
16961692
void describeSemanticsConfiguration(SemanticsConfiguration config) {
16971693
super.describeSemanticsConfiguration(config);
16981694

16991695
// The Slider widget has its own Focus widget with semantics information,
1700-
// and want that semantics node to collect the semantics information here
1696+
// and we want that semantics node to collect the semantics information here
17011697
// so that it's all in the same node: otherwise Talkback sees that the node
17021698
// has focusable children, and it won't focus the Slider's Focus widget
17031699
// because it thinks the Focus widget's node doesn't have anything to say
17041700
// (which it doesn't, but this child does). Aggregating the semantic
17051701
// information into one node means that Talkback will recognize that it has
17061702
// something to say and focus it when it receives keyboard focus.
17071703
// (See https://github.com/flutter/flutter/issues/57038 for context).
1708-
config.isSemanticBoundary = true;
1704+
config.isSemanticBoundary = false;
17091705

17101706
config.isEnabled = isInteractive;
1711-
config.isSlider = true;
1712-
config.isFocusable = isInteractive;
1713-
config.isFocused = hasFocus;
1714-
switch (_platform) {
1715-
case TargetPlatform.android:
1716-
case TargetPlatform.fuchsia:
1717-
case TargetPlatform.iOS:
1718-
case TargetPlatform.linux:
1719-
case TargetPlatform.macOS:
1720-
break;
1721-
case TargetPlatform.windows:
1722-
config.onDidGainAccessibilityFocus = onDidGainAccessibilityFocus;
1723-
break;
1724-
}
17251707
config.textDirection = textDirection;
17261708
if (isInteractive) {
17271709
config.onIncrease = increaseAction;

0 commit comments

Comments
 (0)