Unverified Commit 33c4cd0f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add semantics to cupertino slider (#20476)

parent 5311dff1
......@@ -331,6 +331,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
_position.animateTo(newValue, curve: Curves.fastOutSlowIn);
else
_position.value = newValue;
markNeedsSemanticsUpdate();
}
int get divisions => _divisions;
......@@ -503,8 +504,12 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
config.isSemanticBoundary = isInteractive;
if (isInteractive) {
config.textDirection = textDirection;
config.onIncrease = _increaseAction;
config.onDecrease = _decreaseAction;
config.value = '${(value * 100).round()}%';
config.increasedValue = '${((value + _semanticActionUnit).clamp(0.0, 1.0) * 100).round()}%';
config.decreasedValue = '${((value - _semanticActionUnit).clamp(0.0, 1.0) * 100).round()}%';
}
}
......
......@@ -289,6 +289,10 @@ void main() {
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
value: '50%',
increasedValue: '60%',
decreasedValue: '40%',
textDirection: TextDirection.ltr,
actions: SemanticsAction.decrease.index | SemanticsAction.increase.index,
),
]
......@@ -314,4 +318,45 @@ void main() {
semantics.dispose();
});
testWidgets('Slider Semantics can be updated', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
double value = 0.5;
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new CupertinoSlider(
value: value,
onChanged: (double v) { },
),
));
expect(tester.getSemanticsData(find.byType(CupertinoSlider)), matchesSemanticsData(
hasIncreaseAction: true,
hasDecreaseAction: true,
value: '50%',
increasedValue: '60%',
decreasedValue: '40%',
textDirection: TextDirection.ltr,
));
value = 0.6;
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new CupertinoSlider(
value: value,
onChanged: (double v) { },
),
));
expect(tester.getSemanticsData(find.byType(CupertinoSlider)), matchesSemanticsData(
hasIncreaseAction: true,
hasDecreaseAction: true,
value: '60%',
increasedValue: '70%',
decreasedValue: '50%',
textDirection: TextDirection.ltr,
));
handle.dispose();
});
}
......@@ -304,6 +304,8 @@ Matcher matchesSemanticsData({
String label,
String hint,
String value,
String increasedValue,
String decreasedValue,
TextDirection textDirection,
Rect rect,
Size size,
......@@ -447,6 +449,8 @@ Matcher matchesSemanticsData({
label: label,
hint: hint,
value: value,
increasedValue: increasedValue,
decreasedValue: decreasedValue,
actions: actions,
flags: flags,
textDirection: textDirection,
......@@ -1514,6 +1518,8 @@ class _MatchesSemanticsData extends Matcher {
_MatchesSemanticsData({
this.label,
this.value,
this.increasedValue,
this.decreasedValue,
this.hint,
this.flags,
this.actions,
......@@ -1527,6 +1533,8 @@ class _MatchesSemanticsData extends Matcher {
final String label;
final String value;
final String hint;
final String increasedValue;
final String decreasedValue;
final SemanticsHintOverrides hintOverrides;
final List<SemanticsAction> actions;
final List<CustomSemanticsAction> customActions;
......@@ -1544,6 +1552,10 @@ class _MatchesSemanticsData extends Matcher {
description.add('with value: $value ');
if (hint != null)
description.add('with hint: $hint ');
if (increasedValue != null)
description.add('with increasedValue: $increasedValue');
if (decreasedValue != null)
description.add('with decreasedValue: $decreasedValue');
if (actions != null)
description.add('with actions:').addDescriptionOf(actions);
if (flags != null)
......@@ -1573,6 +1585,10 @@ class _MatchesSemanticsData extends Matcher {
return failWithDescription(matchState, 'hint was: ${data.hint}');
if (value != null && value != data.value)
return failWithDescription(matchState, 'value was: ${data.value}');
if (increasedValue != null && increasedValue != data.increasedValue)
return failWithDescription(matchState, 'increasedValue was: ${data.increasedValue}');
if (decreasedValue != null && decreasedValue != data.decreasedValue)
return failWithDescription(matchState, 'decreasedValue was: ${data.decreasedValue}');
if (textDirection != null && textDirection != data.textDirection)
return failWithDescription(matchState, 'textDirection was: $textDirection');
if (rect != null && rect != data.rect)
......
......@@ -398,6 +398,8 @@ void main() {
label: 'foo',
hint: 'bar',
value: 'baz',
increasedValue: 'a',
decreasedValue: 'b',
textDirection: TextDirection.rtl,
onTapHint: 'scan',
onLongPressHint: 'fill',
......@@ -412,6 +414,8 @@ void main() {
label: 'foo',
hint: 'bar',
value: 'baz',
increasedValue: 'a',
decreasedValue: 'b',
textDirection: TextDirection.rtl,
hasTapAction: true,
hasLongPressAction: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment