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