Set slider semantics flag for sliders (#68019)

This commit is contained in:
Xavier Chrétien 2020-10-19 11:12:03 -04:00 committed by GitHub
parent 804c3ff31f
commit f26fbb6bdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 5 deletions

View file

@ -548,6 +548,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
super.describeSemanticsConfiguration(config);
config.isSemanticBoundary = isInteractive;
config.isSlider = true;
if (isInteractive) {
config.textDirection = textDirection;
config.onIncrease = _increaseAction;

View file

@ -1529,6 +1529,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
final SemanticsConfiguration config = SemanticsConfiguration();
config.isEnabled = isEnabled;
config.textDirection = textDirection;
config.isSlider = true;
if (isEnabled) {
config.onIncrease = increaseAction;
config.onDecrease = decreaseAction;

View file

@ -707,6 +707,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
return Semantics(
container: true,
slider: true,
child: FocusableActionDetector(
actions: _actionMap,
shortcuts: _shortcutMap,

View file

@ -318,6 +318,7 @@ void main() {
increasedValue: '60%',
decreasedValue: '40%',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[SemanticsFlag.isSlider],
actions: SemanticsAction.decrease.index | SemanticsAction.increase.index,
),
],
@ -341,7 +342,14 @@ void main() {
);
expect(semantics, hasSemantics(
TestSemantics.root(),
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
id: 1,
flags: <SemanticsFlag>[SemanticsFlag.isSlider],
)
],
),
ignoreRect: true,
ignoreTransform: true,
));
@ -365,6 +373,7 @@ void main() {
);
expect(tester.getSemantics(find.byType(CupertinoSlider)), matchesSemantics(
isSlider: true,
hasIncreaseAction: true,
hasDecreaseAction: true,
value: '50%',
@ -387,6 +396,7 @@ void main() {
);
expect(tester.getSemantics(find.byType(CupertinoSlider)), matchesSemantics(
isSlider: true,
hasIncreaseAction: true,
hasDecreaseAction: true,
value: '60%',

View file

@ -1775,6 +1775,7 @@ void main() {
children: <Matcher>[
matchesSemantics(
isEnabled: true,
isSlider: true,
hasEnabledState: true,
hasIncreaseAction: true,
hasDecreaseAction: true,
@ -1784,6 +1785,7 @@ void main() {
),
matchesSemantics(
isEnabled: true,
isSlider: true,
hasEnabledState: true,
hasIncreaseAction: true,
hasDecreaseAction: true,

View file

@ -1345,7 +1345,7 @@ void main() {
children: <TestSemantics>[
TestSemantics(
id: 4,
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable],
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, SemanticsFlag.isSlider],
actions: <SemanticsAction>[SemanticsAction.increase, SemanticsAction.decrease],
value: '50%',
increasedValue: '55%',
@ -1403,6 +1403,7 @@ void main() {
SemanticsFlag.hasEnabledState,
// isFocusable is delayed by 1 frame.
SemanticsFlag.isFocusable,
SemanticsFlag.isSlider,
],
value: '50%',
increasedValue: '55%',
@ -1443,6 +1444,7 @@ void main() {
id: 4,
flags: <SemanticsFlag>[
SemanticsFlag.hasEnabledState,
SemanticsFlag.isSlider,
],
value: '50%',
increasedValue: '55%',
@ -1508,7 +1510,7 @@ void main() {
children: <TestSemantics>[
TestSemantics(
id: 4,
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable],
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, SemanticsFlag.isSlider],
actions: <SemanticsAction>[SemanticsAction.increase, SemanticsAction.decrease],
value: '50%',
increasedValue: '60%',
@ -1562,7 +1564,7 @@ void main() {
children: <TestSemantics>[
TestSemantics(
id: 5,
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState],
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState, SemanticsFlag.isSlider],
value: '50%',
increasedValue: '60%',
decreasedValue: '40%',
@ -1623,7 +1625,7 @@ void main() {
children: <TestSemantics>[
TestSemantics(
id: 4,
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable],
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, SemanticsFlag.isSlider],
actions: <SemanticsAction>[SemanticsAction.increase, SemanticsAction.decrease],
value: '40',
increasedValue: '60',

View file

@ -468,6 +468,7 @@ Matcher matchesSemantics({
bool hasToggledState = false,
bool isToggled = false,
bool hasImplicitScrolling = false,
bool isSlider = false,
// Actions //
bool hasTapAction = false,
bool hasLongPressAction = false,
@ -519,6 +520,7 @@ Matcher matchesSemantics({
if (hasToggledState) SemanticsFlag.hasToggledState,
if (isToggled) SemanticsFlag.isToggled,
if (hasImplicitScrolling) SemanticsFlag.hasImplicitScrolling,
if (isSlider) SemanticsFlag.isSlider
];
final List<SemanticsAction> actions = <SemanticsAction>[