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 { ...@@ -331,6 +331,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
_position.animateTo(newValue, curve: Curves.fastOutSlowIn); _position.animateTo(newValue, curve: Curves.fastOutSlowIn);
else else
_position.value = newValue; _position.value = newValue;
markNeedsSemanticsUpdate();
} }
int get divisions => _divisions; int get divisions => _divisions;
...@@ -503,8 +504,12 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { ...@@ -503,8 +504,12 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
config.isSemanticBoundary = isInteractive; config.isSemanticBoundary = isInteractive;
if (isInteractive) { if (isInteractive) {
config.textDirection = textDirection;
config.onIncrease = _increaseAction; config.onIncrease = _increaseAction;
config.onDecrease = _decreaseAction; 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() { ...@@ -289,6 +289,10 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
id: 1, id: 1,
value: '50%',
increasedValue: '60%',
decreasedValue: '40%',
textDirection: TextDirection.ltr,
actions: SemanticsAction.decrease.index | SemanticsAction.increase.index, actions: SemanticsAction.decrease.index | SemanticsAction.increase.index,
), ),
] ]
...@@ -314,4 +318,45 @@ void main() { ...@@ -314,4 +318,45 @@ void main() {
semantics.dispose(); 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({ ...@@ -304,6 +304,8 @@ Matcher matchesSemanticsData({
String label, String label,
String hint, String hint,
String value, String value,
String increasedValue,
String decreasedValue,
TextDirection textDirection, TextDirection textDirection,
Rect rect, Rect rect,
Size size, Size size,
...@@ -447,6 +449,8 @@ Matcher matchesSemanticsData({ ...@@ -447,6 +449,8 @@ Matcher matchesSemanticsData({
label: label, label: label,
hint: hint, hint: hint,
value: value, value: value,
increasedValue: increasedValue,
decreasedValue: decreasedValue,
actions: actions, actions: actions,
flags: flags, flags: flags,
textDirection: textDirection, textDirection: textDirection,
...@@ -1514,6 +1518,8 @@ class _MatchesSemanticsData extends Matcher { ...@@ -1514,6 +1518,8 @@ class _MatchesSemanticsData extends Matcher {
_MatchesSemanticsData({ _MatchesSemanticsData({
this.label, this.label,
this.value, this.value,
this.increasedValue,
this.decreasedValue,
this.hint, this.hint,
this.flags, this.flags,
this.actions, this.actions,
...@@ -1527,6 +1533,8 @@ class _MatchesSemanticsData extends Matcher { ...@@ -1527,6 +1533,8 @@ class _MatchesSemanticsData extends Matcher {
final String label; final String label;
final String value; final String value;
final String hint; final String hint;
final String increasedValue;
final String decreasedValue;
final SemanticsHintOverrides hintOverrides; final SemanticsHintOverrides hintOverrides;
final List<SemanticsAction> actions; final List<SemanticsAction> actions;
final List<CustomSemanticsAction> customActions; final List<CustomSemanticsAction> customActions;
...@@ -1544,6 +1552,10 @@ class _MatchesSemanticsData extends Matcher { ...@@ -1544,6 +1552,10 @@ class _MatchesSemanticsData extends Matcher {
description.add('with value: $value '); description.add('with value: $value ');
if (hint != null) if (hint != null)
description.add('with hint: $hint '); description.add('with hint: $hint ');
if (increasedValue != null)
description.add('with increasedValue: $increasedValue');
if (decreasedValue != null)
description.add('with decreasedValue: $decreasedValue');
if (actions != null) if (actions != null)
description.add('with actions:').addDescriptionOf(actions); description.add('with actions:').addDescriptionOf(actions);
if (flags != null) if (flags != null)
...@@ -1573,6 +1585,10 @@ class _MatchesSemanticsData extends Matcher { ...@@ -1573,6 +1585,10 @@ class _MatchesSemanticsData extends Matcher {
return failWithDescription(matchState, 'hint was: ${data.hint}'); return failWithDescription(matchState, 'hint was: ${data.hint}');
if (value != null && value != data.value) if (value != null && value != data.value)
return failWithDescription(matchState, 'value was: ${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) if (textDirection != null && textDirection != data.textDirection)
return failWithDescription(matchState, 'textDirection was: $textDirection'); return failWithDescription(matchState, 'textDirection was: $textDirection');
if (rect != null && rect != data.rect) if (rect != null && rect != data.rect)
......
...@@ -398,6 +398,8 @@ void main() { ...@@ -398,6 +398,8 @@ void main() {
label: 'foo', label: 'foo',
hint: 'bar', hint: 'bar',
value: 'baz', value: 'baz',
increasedValue: 'a',
decreasedValue: 'b',
textDirection: TextDirection.rtl, textDirection: TextDirection.rtl,
onTapHint: 'scan', onTapHint: 'scan',
onLongPressHint: 'fill', onLongPressHint: 'fill',
...@@ -412,6 +414,8 @@ void main() { ...@@ -412,6 +414,8 @@ void main() {
label: 'foo', label: 'foo',
hint: 'bar', hint: 'bar',
value: 'baz', value: 'baz',
increasedValue: 'a',
decreasedValue: 'b',
textDirection: TextDirection.rtl, textDirection: TextDirection.rtl,
hasTapAction: true, hasTapAction: true,
hasLongPressAction: 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