Commit 5e1af2f3 authored by Adam Barth's avatar Adam Barth

[rename fixit] DismissDirection left -> endToStart, right -> startToEnd

Removes an LTR bias in DismissDirection.

Fixes #2562
parent ede5dfce
...@@ -135,8 +135,8 @@ class CardCollectionState extends State<CardCollection> { ...@@ -135,8 +135,8 @@ class CardCollectionState extends State<CardCollection> {
buildDrawerColorRadioItem("Teal", Colors.teal, _primaryColor, _selectColor), buildDrawerColorRadioItem("Teal", Colors.teal, _primaryColor, _selectColor),
new Divider(), new Divider(),
buildDrawerDirectionRadioItem("Dismiss horizontally", DismissDirection.horizontal, _dismissDirection, _changeDismissDirection, icon: Icons.code), buildDrawerDirectionRadioItem("Dismiss horizontally", DismissDirection.horizontal, _dismissDirection, _changeDismissDirection, icon: Icons.code),
buildDrawerDirectionRadioItem("Dismiss left", DismissDirection.left, _dismissDirection, _changeDismissDirection, icon: Icons.arrow_back), buildDrawerDirectionRadioItem("Dismiss left", DismissDirection.endToStart, _dismissDirection, _changeDismissDirection, icon: Icons.arrow_back),
buildDrawerDirectionRadioItem("Dismiss right", DismissDirection.right, _dismissDirection, _changeDismissDirection, icon: Icons.arrow_forward), buildDrawerDirectionRadioItem("Dismiss right", DismissDirection.startToEnd, _dismissDirection, _changeDismissDirection, icon: Icons.arrow_forward),
new Divider(), new Divider(),
buildFontRadioItem("Left-align text", new TextStyle(textAlign: TextAlign.left), _textStyle, _changeTextStyle, icon: Icons.format_align_left, enabled: !_editable), buildFontRadioItem("Left-align text", new TextStyle(textAlign: TextAlign.left), _textStyle, _changeTextStyle, icon: Icons.format_align_left, enabled: !_editable),
buildFontRadioItem("Center-align text", new TextStyle(textAlign: TextAlign.center), _textStyle, _changeTextStyle, icon: Icons.format_align_center, enabled: !_editable), buildFontRadioItem("Center-align text", new TextStyle(textAlign: TextAlign.center), _textStyle, _changeTextStyle, icon: Icons.format_align_center, enabled: !_editable),
...@@ -338,22 +338,24 @@ class CardCollectionState extends State<CardCollection> { ...@@ -338,22 +338,24 @@ class CardCollectionState extends State<CardCollection> {
case DismissDirection.horizontal: case DismissDirection.horizontal:
backgroundMessage = "Swipe in either direction"; backgroundMessage = "Swipe in either direction";
break; break;
case DismissDirection.left: case DismissDirection.endToStart:
backgroundMessage = "Swipe left to dismiss"; backgroundMessage = "Swipe left to dismiss";
break; break;
case DismissDirection.right: case DismissDirection.startToEnd:
backgroundMessage = "Swipe right to dismiss"; backgroundMessage = "Swipe right to dismiss";
break; break;
default: default:
backgroundMessage = "Unsupported dismissDirection"; backgroundMessage = "Unsupported dismissDirection";
} }
// TODO(abarth): This icon is wrong in RTL.
Widget leftArrowIcon = new Icon(icon: Icons.arrow_back, size: 36.0); Widget leftArrowIcon = new Icon(icon: Icons.arrow_back, size: 36.0);
if (_dismissDirection == DismissDirection.right) if (_dismissDirection == DismissDirection.startToEnd)
leftArrowIcon = new Opacity(opacity: 0.1, child: leftArrowIcon); leftArrowIcon = new Opacity(opacity: 0.1, child: leftArrowIcon);
// TODO(abarth): This icon is wrong in RTL.
Widget rightArrowIcon = new Icon(icon: Icons.arrow_forward, size: 36.0); Widget rightArrowIcon = new Icon(icon: Icons.arrow_forward, size: 36.0);
if (_dismissDirection == DismissDirection.left) if (_dismissDirection == DismissDirection.endToStart)
rightArrowIcon = new Opacity(opacity: 0.1, child: rightArrowIcon); rightArrowIcon = new Opacity(opacity: 0.1, child: rightArrowIcon);
// The background Widget appears behind the Dismissable card when the card // The background Widget appears behind the Dismissable card when the card
......
...@@ -61,10 +61,10 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> { ...@@ -61,10 +61,10 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
_dismissDirection = DismissDirection.horizontal; _dismissDirection = DismissDirection.horizontal;
break; break;
case LeaveBehindDemoAction.leftSwipe: case LeaveBehindDemoAction.leftSwipe:
_dismissDirection = DismissDirection.left; _dismissDirection = DismissDirection.endToStart;
break; break;
case LeaveBehindDemoAction.rightSwipe: case LeaveBehindDemoAction.rightSwipe:
_dismissDirection = DismissDirection.right; _dismissDirection = DismissDirection.startToEnd;
break; break;
} }
} }
...@@ -87,7 +87,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> { ...@@ -87,7 +87,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
setState(() { setState(() {
leaveBehindItems.remove(item); leaveBehindItems.remove(item);
}); });
final String action = (direction == DismissDirection.left) ? 'archived' : 'deleted'; final String action = (direction == DismissDirection.endToStart) ? 'archived' : 'deleted';
_scaffoldKey.currentState.showSnackBar(new SnackBar( _scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text('You $action item ${item.index}'), content: new Text('You $action item ${item.index}'),
action: new SnackBarAction( action: new SnackBarAction(
...@@ -143,12 +143,12 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> { ...@@ -143,12 +143,12 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
), ),
new CheckedPopupMenuItem<LeaveBehindDemoAction>( new CheckedPopupMenuItem<LeaveBehindDemoAction>(
value: LeaveBehindDemoAction.leftSwipe, value: LeaveBehindDemoAction.leftSwipe,
checked: _dismissDirection == DismissDirection.left, checked: _dismissDirection == DismissDirection.endToStart,
child: new Text('Only swipe left') child: new Text('Only swipe left')
), ),
new CheckedPopupMenuItem<LeaveBehindDemoAction>( new CheckedPopupMenuItem<LeaveBehindDemoAction>(
value: LeaveBehindDemoAction.rightSwipe, value: LeaveBehindDemoAction.rightSwipe,
checked: _dismissDirection == DismissDirection.right, checked: _dismissDirection == DismissDirection.startToEnd,
child: new Text('Only swipe right') child: new Text('Only swipe right')
) )
] ]
......
...@@ -25,11 +25,13 @@ enum DismissDirection { ...@@ -25,11 +25,13 @@ enum DismissDirection {
/// The [Dismissable] can be dismissed by dragging either left or right. /// The [Dismissable] can be dismissed by dragging either left or right.
horizontal, horizontal,
/// The [Dismissable] can be dismissed by dragging left only. /// The [Dismissable] can be dismissed by dragging in the reverse of the
left, /// reading direction (e.g., from right to left in left-to-right languages).
endToStart,
/// The [Dismissable] can be dismissed by dragging right only. /// The [Dismissable] can be dismissed by dragging in the reading direction
right, /// (e.g., from left to right in left-to-right languages).
startToEnd,
/// The [Dismissable] can be dismissed by dragging up only. /// The [Dismissable] can be dismissed by dragging up only.
up, up,
...@@ -115,13 +117,13 @@ class _DismissableState extends State<Dismissable> { ...@@ -115,13 +117,13 @@ class _DismissableState extends State<Dismissable> {
bool get _directionIsXAxis { bool get _directionIsXAxis {
return config.direction == DismissDirection.horizontal return config.direction == DismissDirection.horizontal
|| config.direction == DismissDirection.left || config.direction == DismissDirection.endToStart
|| config.direction == DismissDirection.right; || config.direction == DismissDirection.startToEnd;
} }
DismissDirection get _dismissDirection { DismissDirection get _dismissDirection {
if (_directionIsXAxis) if (_directionIsXAxis)
return _dragExtent > 0 ? DismissDirection.right : DismissDirection.left; return _dragExtent > 0 ? DismissDirection.startToEnd : DismissDirection.endToStart;
return _dragExtent > 0 ? DismissDirection.down : DismissDirection.up; return _dragExtent > 0 ? DismissDirection.down : DismissDirection.up;
} }
...@@ -162,13 +164,13 @@ class _DismissableState extends State<Dismissable> { ...@@ -162,13 +164,13 @@ class _DismissableState extends State<Dismissable> {
break; break;
case DismissDirection.up: case DismissDirection.up:
case DismissDirection.left: case DismissDirection.endToStart:
if (_dragExtent + delta < 0) if (_dragExtent + delta < 0)
_dragExtent += delta; _dragExtent += delta;
break; break;
case DismissDirection.down: case DismissDirection.down:
case DismissDirection.right: case DismissDirection.startToEnd:
if (_dragExtent + delta > 0) if (_dragExtent + delta > 0)
_dragExtent += delta; _dragExtent += delta;
break; break;
...@@ -201,7 +203,7 @@ class _DismissableState extends State<Dismissable> { ...@@ -201,7 +203,7 @@ class _DismissableState extends State<Dismissable> {
switch(config.direction) { switch(config.direction) {
case DismissDirection.horizontal: case DismissDirection.horizontal:
return vx.abs() > _kMinFlingVelocity; return vx.abs() > _kMinFlingVelocity;
case DismissDirection.left: case DismissDirection.endToStart:
return -vx > _kMinFlingVelocity; return -vx > _kMinFlingVelocity;
default: default:
return vx > _kMinFlingVelocity; return vx > _kMinFlingVelocity;
...@@ -275,7 +277,7 @@ class _DismissableState extends State<Dismissable> { ...@@ -275,7 +277,7 @@ class _DismissableState extends State<Dismissable> {
Widget background = config.background; Widget background = config.background;
if (config.secondaryBackground != null) { if (config.secondaryBackground != null) {
final DismissDirection direction = _dismissDirection; final DismissDirection direction = _dismissDirection;
if (direction == DismissDirection.left || direction == DismissDirection.up) if (direction == DismissDirection.endToStart || direction == DismissDirection.up)
background = config.secondaryBackground; background = config.secondaryBackground;
} }
......
...@@ -58,13 +58,13 @@ void dismissElement(WidgetTester tester, Element itemElement, { DismissDirection ...@@ -58,13 +58,13 @@ void dismissElement(WidgetTester tester, Element itemElement, { DismissDirection
Point downLocation; Point downLocation;
Point upLocation; Point upLocation;
switch(gestureDirection) { switch(gestureDirection) {
case DismissDirection.left: case DismissDirection.endToStart:
// getTopRight() returns a point that's just beyond itemWidget's right // getTopRight() returns a point that's just beyond itemWidget's right
// edge and outside the Dismissable event listener's bounds. // edge and outside the Dismissable event listener's bounds.
downLocation = tester.getTopRight(itemElement) + const Offset(-0.1, 0.0); downLocation = tester.getTopRight(itemElement) + const Offset(-0.1, 0.0);
upLocation = tester.getTopLeft(itemElement); upLocation = tester.getTopLeft(itemElement);
break; break;
case DismissDirection.right: case DismissDirection.startToEnd:
// we do the same thing here to keep the test symmetric // we do the same thing here to keep the test symmetric
downLocation = tester.getTopLeft(itemElement) + const Offset(0.1, 0.0); downLocation = tester.getTopLeft(itemElement) + const Offset(0.1, 0.0);
upLocation = tester.getTopRight(itemElement); upLocation = tester.getTopRight(itemElement);
...@@ -129,15 +129,15 @@ void main() { ...@@ -129,15 +129,15 @@ void main() {
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.right); dismissItem(tester, 0, gestureDirection: DismissDirection.startToEnd);
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0])); expect(dismissedItems, equals([0]));
expect(reportedDismissDirection, DismissDirection.right); expect(reportedDismissDirection, DismissDirection.startToEnd);
dismissItem(tester, 1, gestureDirection: DismissDirection.left); dismissItem(tester, 1, gestureDirection: DismissDirection.endToStart);
expect(tester.findText('1'), isNull); expect(tester.findText('1'), isNull);
expect(dismissedItems, equals([0, 1])); expect(dismissedItems, equals([0, 1]));
expect(reportedDismissDirection, DismissDirection.left); expect(reportedDismissDirection, DismissDirection.endToStart);
}); });
}); });
...@@ -165,38 +165,38 @@ void main() { ...@@ -165,38 +165,38 @@ void main() {
test('drag-left with DismissDirection.left triggers dismiss', () { test('drag-left with DismissDirection.left triggers dismiss', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.vertical; scrollDirection = Axis.vertical;
dismissDirection = DismissDirection.left; dismissDirection = DismissDirection.endToStart;
dismissedItems = <int>[]; dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.right); dismissItem(tester, 0, gestureDirection: DismissDirection.startToEnd);
expect(tester.findText('0'), isNotNull); expect(tester.findText('0'), isNotNull);
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 1, gestureDirection: DismissDirection.right); dismissItem(tester, 1, gestureDirection: DismissDirection.startToEnd);
dismissItem(tester, 0, gestureDirection: DismissDirection.left); dismissItem(tester, 0, gestureDirection: DismissDirection.endToStart);
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0])); expect(dismissedItems, equals([0]));
dismissItem(tester, 1, gestureDirection: DismissDirection.left); dismissItem(tester, 1, gestureDirection: DismissDirection.endToStart);
}); });
}); });
test('drag-right with DismissDirection.right triggers dismiss', () { test('drag-right with DismissDirection.right triggers dismiss', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.vertical; scrollDirection = Axis.vertical;
dismissDirection = DismissDirection.right; dismissDirection = DismissDirection.startToEnd;
dismissedItems = <int>[]; dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.left); dismissItem(tester, 0, gestureDirection: DismissDirection.endToStart);
expect(tester.findText('0'), isNotNull); expect(tester.findText('0'), isNotNull);
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.right); dismissItem(tester, 0, gestureDirection: DismissDirection.startToEnd);
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0])); expect(dismissedItems, equals([0]));
}); });
...@@ -292,12 +292,12 @@ void main() { ...@@ -292,12 +292,12 @@ void main() {
)); ));
expect(tester.findText('1'), isNotNull); expect(tester.findText('1'), isNotNull);
expect(tester.findText('2'), isNotNull); expect(tester.findText('2'), isNotNull);
dismissElement(tester, tester.findText('2'), gestureDirection: DismissDirection.right); dismissElement(tester, tester.findText('2'), gestureDirection: DismissDirection.startToEnd);
tester.pump(); // start the slide away tester.pump(); // start the slide away
tester.pump(new Duration(seconds: 1)); // finish the slide away tester.pump(new Duration(seconds: 1)); // finish the slide away
expect(tester.findText('1'), isNotNull); expect(tester.findText('1'), isNotNull);
expect(tester.findText('2'), isNull); expect(tester.findText('2'), isNull);
dismissElement(tester, tester.findText('1'), gestureDirection: DismissDirection.right); dismissElement(tester, tester.findText('1'), gestureDirection: DismissDirection.startToEnd);
tester.pump(); // start the slide away tester.pump(); // start the slide away
tester.pump(new Duration(seconds: 1)); // finish the slide away (at which point the child is no longer included in the tree) tester.pump(new Duration(seconds: 1)); // finish the slide away (at which point the child is no longer included in the tree)
expect(tester.findText('1'), isNull); expect(tester.findText('1'), isNull);
......
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