mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Rename BannerLocation enum values (#11960)
* Rename BannerLocation enum values * topLeft -> topStart * topRight -> topEnd * bottomLeft -> bottomStart * bottomRight -> bottomEnd These names will make it easier for us to adjust the location of the banner in right-to-left mode. See the discussion on flutter-dev. * Add RTL support for Banner Fixes #11905
This commit is contained in:
parent
57e2df1139
commit
1792766a88
@ -197,7 +197,7 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
|
|||||||
opacity: new CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
|
opacity: new CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
|
||||||
child: const Banner(
|
child: const Banner(
|
||||||
message: 'PREVIEW',
|
message: 'PREVIEW',
|
||||||
location: BannerLocation.topRight,
|
location: BannerLocation.topEnd,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -24,17 +24,25 @@ const TextStyle _kTextStyle = const TextStyle(
|
|||||||
|
|
||||||
/// Where to show a [Banner].
|
/// Where to show a [Banner].
|
||||||
enum BannerLocation {
|
enum BannerLocation {
|
||||||
/// Show the banner in the top right corner.
|
/// Show the banner in the top-right corner when the ambient [Directionality]
|
||||||
topRight,
|
/// is [TextDirection.rtl] and in the top-left corner when the ambient
|
||||||
|
/// [Directionality] is [TextDirection.ltr].
|
||||||
|
topStart,
|
||||||
|
|
||||||
/// Show the banner in the top left corner.
|
/// Show the banner in the top-left corner when the ambient [Directionality]
|
||||||
topLeft,
|
/// is [TextDirection.rtl] and in the top-right corner when the ambient
|
||||||
|
/// [Directionality] is [TextDirection.ltr].
|
||||||
|
topEnd,
|
||||||
|
|
||||||
/// Show the banner in the bottom right corner.
|
/// Show the banner in the bottom-right corner when the ambient
|
||||||
bottomRight,
|
/// [Directionality] is [TextDirection.rtl] and in the bottom-left corner when
|
||||||
|
/// the ambient [Directionality] is [TextDirection.ltr].
|
||||||
|
bottomStart,
|
||||||
|
|
||||||
/// Show the banner in the bottom left corner.
|
/// Show the banner in the bottom-left corner when the ambient
|
||||||
bottomLeft,
|
/// [Directionality] is [TextDirection.rtl] and in the bottom-right corner when
|
||||||
|
/// the ambient [Directionality] is [TextDirection.ltr].
|
||||||
|
bottomEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paints a [Banner].
|
/// Paints a [Banner].
|
||||||
@ -59,12 +67,14 @@ class BannerPainter extends CustomPainter {
|
|||||||
|
|
||||||
/// The directionality of the text.
|
/// The directionality of the text.
|
||||||
///
|
///
|
||||||
/// This is used to disambiguate how to render bidirectional text. For
|
/// This value is used to disambiguate how to render bidirectional text. For
|
||||||
/// example, if the message is an English phrase followed by a Hebrew phrase,
|
/// example, if the message is an English phrase followed by a Hebrew phrase,
|
||||||
/// in a [TextDirection.ltr] context the English phrase will be on the left
|
/// in a [TextDirection.ltr] context the English phrase will be on the left
|
||||||
/// and the Hebrew phrase to its right, while in a [TextDirection.rtl]
|
/// and the Hebrew phrase to its right, while in a [TextDirection.rtl]
|
||||||
/// context, the English phrase will be on the right and the Hebrow phrase on
|
/// context, the English phrase will be on the right and the Hebrow phrase on
|
||||||
/// its left.
|
/// its left.
|
||||||
|
///
|
||||||
|
/// This value is also used to interpret the [location] of the banner.
|
||||||
final TextDirection textDirection;
|
final TextDirection textDirection;
|
||||||
|
|
||||||
/// Where to show the banner (e.g., the upper right corder).
|
/// Where to show the banner (e.g., the upper right corder).
|
||||||
@ -126,15 +136,32 @@ class BannerPainter extends CustomPainter {
|
|||||||
|
|
||||||
double _translationX(double width) {
|
double _translationX(double width) {
|
||||||
assert(location != null);
|
assert(location != null);
|
||||||
switch (location) {
|
assert(textDirection != null);
|
||||||
case BannerLocation.bottomRight:
|
switch (textDirection) {
|
||||||
return width - _kBottomOffset;
|
case TextDirection.rtl:
|
||||||
case BannerLocation.topRight:
|
switch (location) {
|
||||||
return width;
|
case BannerLocation.bottomEnd:
|
||||||
case BannerLocation.bottomLeft:
|
return _kBottomOffset;
|
||||||
return _kBottomOffset;
|
case BannerLocation.topEnd:
|
||||||
case BannerLocation.topLeft:
|
return 0.0;
|
||||||
return 0.0;
|
case BannerLocation.bottomStart:
|
||||||
|
return width - _kBottomOffset;
|
||||||
|
case BannerLocation.topStart:
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TextDirection.ltr:
|
||||||
|
switch (location) {
|
||||||
|
case BannerLocation.bottomEnd:
|
||||||
|
return width - _kBottomOffset;
|
||||||
|
case BannerLocation.topEnd:
|
||||||
|
return width;
|
||||||
|
case BannerLocation.bottomStart:
|
||||||
|
return _kBottomOffset;
|
||||||
|
case BannerLocation.topStart:
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -142,11 +169,11 @@ class BannerPainter extends CustomPainter {
|
|||||||
double _translationY(double height) {
|
double _translationY(double height) {
|
||||||
assert(location != null);
|
assert(location != null);
|
||||||
switch (location) {
|
switch (location) {
|
||||||
case BannerLocation.bottomRight:
|
case BannerLocation.bottomStart:
|
||||||
case BannerLocation.bottomLeft:
|
case BannerLocation.bottomEnd:
|
||||||
return height - _kBottomOffset;
|
return height - _kBottomOffset;
|
||||||
case BannerLocation.topRight:
|
case BannerLocation.topStart:
|
||||||
case BannerLocation.topLeft:
|
case BannerLocation.topEnd:
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -154,13 +181,28 @@ class BannerPainter extends CustomPainter {
|
|||||||
|
|
||||||
double get _rotation {
|
double get _rotation {
|
||||||
assert(location != null);
|
assert(location != null);
|
||||||
switch (location) {
|
assert(textDirection != null);
|
||||||
case BannerLocation.bottomLeft:
|
switch (textDirection) {
|
||||||
case BannerLocation.topRight:
|
case TextDirection.rtl:
|
||||||
return math.PI / 4.0;
|
switch (location) {
|
||||||
case BannerLocation.bottomRight:
|
case BannerLocation.bottomStart:
|
||||||
case BannerLocation.topLeft:
|
case BannerLocation.topEnd:
|
||||||
return -math.PI / 4.0;
|
return -math.PI / 4.0;
|
||||||
|
case BannerLocation.bottomEnd:
|
||||||
|
case BannerLocation.topStart:
|
||||||
|
return math.PI / 4.0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TextDirection.ltr:
|
||||||
|
switch (location) {
|
||||||
|
case BannerLocation.bottomStart:
|
||||||
|
case BannerLocation.topEnd:
|
||||||
|
return math.PI / 4.0;
|
||||||
|
case BannerLocation.bottomEnd:
|
||||||
|
case BannerLocation.topStart:
|
||||||
|
return -math.PI / 4.0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -265,7 +307,7 @@ class CheckedModeBanner extends StatelessWidget {
|
|||||||
child: result,
|
child: result,
|
||||||
message: 'SLOW MODE',
|
message: 'SLOW MODE',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
location: BannerLocation.topRight,
|
location: BannerLocation.topEnd,
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -17,11 +17,11 @@ class TestCanvas implements Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('A Banner with a location of topLeft paints in the top left', () {
|
test('A Banner with a location of topStart paints in the top left (LTR)', () {
|
||||||
final BannerPainter bannerPainter = new BannerPainter(
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
message: 'foo',
|
message: 'foo',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
location: BannerLocation.topLeft
|
location: BannerLocation.topStart
|
||||||
);
|
);
|
||||||
|
|
||||||
final TestCanvas canvas = new TestCanvas();
|
final TestCanvas canvas = new TestCanvas();
|
||||||
@ -44,11 +44,11 @@ void main() {
|
|||||||
expect(rotateCommand.positionalArguments[0], equals(-math.PI / 4.0));
|
expect(rotateCommand.positionalArguments[0], equals(-math.PI / 4.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('A Banner with a location of topRight paints in the top right', () {
|
test('A Banner with a location of topStart paints in the top right (RTL)', () {
|
||||||
final BannerPainter bannerPainter = new BannerPainter(
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
message: 'foo',
|
message: 'foo',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.rtl,
|
||||||
location: BannerLocation.topRight
|
location: BannerLocation.topStart,
|
||||||
);
|
);
|
||||||
|
|
||||||
final TestCanvas canvas = new TestCanvas();
|
final TestCanvas canvas = new TestCanvas();
|
||||||
@ -71,11 +71,65 @@ void main() {
|
|||||||
expect(rotateCommand.positionalArguments[0], equals(math.PI / 4.0));
|
expect(rotateCommand.positionalArguments[0], equals(math.PI / 4.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('A Banner with a location of bottomLeft paints in the bottom left', () {
|
test('A Banner with a location of topEnd paints in the top right (LTR)', () {
|
||||||
final BannerPainter bannerPainter = new BannerPainter(
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
message: 'foo',
|
message: 'foo',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
location: BannerLocation.bottomLeft
|
location: BannerLocation.topEnd
|
||||||
|
);
|
||||||
|
|
||||||
|
final TestCanvas canvas = new TestCanvas();
|
||||||
|
|
||||||
|
bannerPainter.paint(canvas, const Size(1000.0, 1000.0));
|
||||||
|
|
||||||
|
final Invocation translateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #translate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(translateCommand, isNotNull);
|
||||||
|
expect(translateCommand.positionalArguments[0], greaterThan(900.0));
|
||||||
|
expect(translateCommand.positionalArguments[1], lessThan(100.0));
|
||||||
|
|
||||||
|
final Invocation rotateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #rotate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(rotateCommand, isNotNull);
|
||||||
|
expect(rotateCommand.positionalArguments[0], equals(math.PI / 4.0));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('A Banner with a location of topEnd paints in the top left (RTL)', () {
|
||||||
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
|
message: 'foo',
|
||||||
|
textDirection: TextDirection.rtl,
|
||||||
|
location: BannerLocation.topEnd,
|
||||||
|
);
|
||||||
|
|
||||||
|
final TestCanvas canvas = new TestCanvas();
|
||||||
|
|
||||||
|
bannerPainter.paint(canvas, const Size(1000.0, 1000.0));
|
||||||
|
|
||||||
|
final Invocation translateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #translate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(translateCommand, isNotNull);
|
||||||
|
expect(translateCommand.positionalArguments[0], lessThan(100.0));
|
||||||
|
expect(translateCommand.positionalArguments[1], lessThan(100.0));
|
||||||
|
|
||||||
|
final Invocation rotateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #rotate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(rotateCommand, isNotNull);
|
||||||
|
expect(rotateCommand.positionalArguments[0], equals(-math.PI / 4.0));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('A Banner with a location of bottomStart paints in the bottom left (LTR)', () {
|
||||||
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
|
message: 'foo',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
location: BannerLocation.bottomStart
|
||||||
);
|
);
|
||||||
|
|
||||||
final TestCanvas canvas = new TestCanvas();
|
final TestCanvas canvas = new TestCanvas();
|
||||||
@ -98,11 +152,11 @@ void main() {
|
|||||||
expect(rotateCommand.positionalArguments[0], equals(math.PI / 4.0));
|
expect(rotateCommand.positionalArguments[0], equals(math.PI / 4.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('A Banner with a location of bottomRight paints in the bottom right', () {
|
test('A Banner with a location of bottomStart paints in the bottom right (RTL)', () {
|
||||||
final BannerPainter bannerPainter = new BannerPainter(
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
message: 'foo',
|
message: 'foo',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.rtl,
|
||||||
location: BannerLocation.bottomRight
|
location: BannerLocation.bottomStart,
|
||||||
);
|
);
|
||||||
|
|
||||||
final TestCanvas canvas = new TestCanvas();
|
final TestCanvas canvas = new TestCanvas();
|
||||||
@ -124,4 +178,59 @@ void main() {
|
|||||||
expect(rotateCommand, isNotNull);
|
expect(rotateCommand, isNotNull);
|
||||||
expect(rotateCommand.positionalArguments[0], equals(-math.PI / 4.0));
|
expect(rotateCommand.positionalArguments[0], equals(-math.PI / 4.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('A Banner with a location of bottomEnd paints in the bottom right (LTR)', () {
|
||||||
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
|
message: 'foo',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
location: BannerLocation.bottomEnd
|
||||||
|
);
|
||||||
|
|
||||||
|
final TestCanvas canvas = new TestCanvas();
|
||||||
|
|
||||||
|
bannerPainter.paint(canvas, const Size(1000.0, 1000.0));
|
||||||
|
|
||||||
|
final Invocation translateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #translate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(translateCommand, isNotNull);
|
||||||
|
expect(translateCommand.positionalArguments[0], greaterThan(900.0));
|
||||||
|
expect(translateCommand.positionalArguments[1], greaterThan(900.0));
|
||||||
|
|
||||||
|
final Invocation rotateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #rotate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(rotateCommand, isNotNull);
|
||||||
|
expect(rotateCommand.positionalArguments[0], equals(-math.PI / 4.0));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('A Banner with a location of bottomEnd paints in the bottom left (RTL)', () {
|
||||||
|
final BannerPainter bannerPainter = new BannerPainter(
|
||||||
|
message: 'foo',
|
||||||
|
textDirection: TextDirection.rtl,
|
||||||
|
location: BannerLocation.bottomEnd,
|
||||||
|
);
|
||||||
|
|
||||||
|
final TestCanvas canvas = new TestCanvas();
|
||||||
|
|
||||||
|
bannerPainter.paint(canvas, const Size(1000.0, 1000.0));
|
||||||
|
|
||||||
|
final Invocation translateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #translate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(translateCommand, isNotNull);
|
||||||
|
expect(translateCommand.positionalArguments[0], lessThan(100.0));
|
||||||
|
expect(translateCommand.positionalArguments[1], greaterThan(900.0));
|
||||||
|
|
||||||
|
final Invocation rotateCommand = canvas.invocations.firstWhere((Invocation invocation) {
|
||||||
|
return invocation.memberName == #rotate;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(rotateCommand, isNotNull);
|
||||||
|
expect(rotateCommand.positionalArguments[0], equals(math.PI / 4.0));
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user