Unverified Commit 276cbb1c authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Apply media bottom padding in BottomNavigationBar (#13431)

Updates scaffold to expose bottom padding to the associated
BottonNavigationBar (if present). BottomNavigationBar is now responsible
for adjusting itself to account for bottom padding.

This change is necessary to support the updated BottomNavigationBar
layout for the iPhone X.
parent 6f773944
...@@ -436,6 +436,9 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr ...@@ -436,6 +436,9 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasDirectionality(context)); assert(debugCheckHasDirectionality(context));
// Labels apply up to _bottomMargin padding. Remainder is media padding.
final double additionalBottomPadding = math.max(MediaQuery.of(context).padding.bottom - _kBottomMargin, 0.0);
Color backgroundColor; Color backgroundColor;
switch (widget.type) { switch (widget.type) {
case BottomNavigationBarType.fixed: case BottomNavigationBarType.fixed:
...@@ -453,7 +456,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr ...@@ -453,7 +456,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
), ),
), ),
new ConstrainedBox( new ConstrainedBox(
constraints: const BoxConstraints(minHeight: kBottomNavigationBarHeight), constraints: new BoxConstraints(minHeight: kBottomNavigationBarHeight + additionalBottomPadding),
child: new Stack( child: new Stack(
children: <Widget>[ children: <Widget>[
new Positioned.fill( new Positioned.fill(
...@@ -466,7 +469,14 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr ...@@ -466,7 +469,14 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
), ),
new Material( // Splashes. new Material( // Splashes.
type: MaterialType.transparency, type: MaterialType.transparency,
child: _createContainer(_createTiles()), child: new Padding(
padding: new EdgeInsets.only(bottom: additionalBottomPadding),
child: new MediaQuery.removePadding(
context: context,
removeBottom: true,
child: _createContainer(_createTiles()),
),
),
), ),
], ],
), ),
......
...@@ -65,6 +65,35 @@ void main() { ...@@ -65,6 +65,35 @@ void main() {
expect(find.text('Alarm'), findsOneWidget); expect(find.text('Alarm'), findsOneWidget);
}); });
testWidgets('BottomNavigationBar adds bottom padding to height', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new MediaQuery(
data: const MediaQueryData(padding: const EdgeInsets.only(bottom: 40.0)),
child: new Scaffold(
bottomNavigationBar: new BottomNavigationBar(
items: <BottomNavigationBarItem>[
const BottomNavigationBarItem(
icon: const Icon(Icons.ac_unit),
title: const Text('AC')
),
const BottomNavigationBarItem(
icon: const Icon(Icons.access_alarm),
title: const Text('Alarm')
)
]
)
)
)
)
);
const double labelBottomMargin = 8.0; // _kBottomMargin in implementation.
const double additionalPadding = 40.0 - labelBottomMargin;
const double expectedHeight = kBottomNavigationBarHeight + additionalPadding;
expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight);
});
testWidgets('BottomNavigationBar action size test', (WidgetTester tester) async { testWidgets('BottomNavigationBar action size test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new MaterialApp( new MaterialApp(
......
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