Unverified Commit 6ff844a9 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Scaffold resizeToAvoidBottomPadding uses view insets (#13437)

Now that keyboard height is modelled as a (bottom) view inset, migrate
scaffold bottom resizing to use view insets instead of bottom padding,
which, after an engine roll, will only be used for safe areas.

Until the aforementioned engine roll, the keyboard height is still
included in both bottom padding and view insets. As such
resizeToAvoidBottomPadding still drives bottom padding removal until
that roll lands.

Renames _ScaffoldLayout.bottomPadding to bottomViewInset
parent 60effb99
...@@ -39,13 +39,13 @@ enum _ScaffoldSlot { ...@@ -39,13 +39,13 @@ enum _ScaffoldSlot {
class _ScaffoldLayout extends MultiChildLayoutDelegate { class _ScaffoldLayout extends MultiChildLayoutDelegate {
_ScaffoldLayout({ _ScaffoldLayout({
@required this.statusBarHeight, @required this.statusBarHeight,
@required this.bottomPadding, @required this.bottomViewInset,
@required this.endPadding, // for floating action button @required this.endPadding, // for floating action button
@required this.textDirection, @required this.textDirection,
}); });
final double statusBarHeight; final double statusBarHeight;
final double bottomPadding; final double bottomViewInset;
final double endPadding; final double endPadding;
final TextDirection textDirection; final TextDirection textDirection;
...@@ -59,7 +59,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { ...@@ -59,7 +59,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
// so the app bar's shadow is drawn on top of the body. // so the app bar's shadow is drawn on top of the body.
final BoxConstraints fullWidthConstraints = looseConstraints.tighten(width: size.width); final BoxConstraints fullWidthConstraints = looseConstraints.tighten(width: size.width);
final double bottom = math.max(0.0, size.height - bottomPadding); final double bottom = math.max(0.0, size.height - bottomViewInset);
double contentTop = 0.0; double contentTop = 0.0;
double contentBottom = bottom; double contentBottom = bottom;
...@@ -161,7 +161,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { ...@@ -161,7 +161,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
@override @override
bool shouldRelayout(_ScaffoldLayout oldDelegate) { bool shouldRelayout(_ScaffoldLayout oldDelegate) {
return oldDelegate.statusBarHeight != statusBarHeight return oldDelegate.statusBarHeight != statusBarHeight
|| oldDelegate.bottomPadding != bottomPadding || oldDelegate.bottomViewInset != bottomViewInset
|| oldDelegate.endPadding != endPadding || oldDelegate.endPadding != endPadding
|| oldDelegate.textDirection != textDirection; || oldDelegate.textDirection != textDirection;
} }
...@@ -810,7 +810,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -810,7 +810,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
@required bool removeLeftPadding, @required bool removeLeftPadding,
@required bool removeTopPadding, @required bool removeTopPadding,
@required bool removeRightPadding, @required bool removeRightPadding,
bool removeBottomPadding, // defaults to widget.resizeToAvoidBottomPadding @required bool removeBottomPadding,
}) { }) {
if (child != null) { if (child != null) {
children.add( children.add(
...@@ -821,7 +821,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -821,7 +821,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeft: removeLeftPadding, removeLeft: removeLeftPadding,
removeTop: removeTopPadding, removeTop: removeTopPadding,
removeRight: removeRightPadding, removeRight: removeRightPadding,
removeBottom: removeBottomPadding ?? widget.resizeToAvoidBottomPadding, removeBottom: removeBottomPadding,
child: child, child: child,
), ),
), ),
...@@ -861,6 +861,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -861,6 +861,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeftPadding: false, removeLeftPadding: false,
removeTopPadding: widget.appBar != null, removeTopPadding: widget.appBar != null,
removeRightPadding: false, removeRightPadding: false,
removeBottomPadding: widget.bottomNavigationBar != null,
); );
if (widget.appBar != null) { if (widget.appBar != null) {
...@@ -892,6 +893,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -892,6 +893,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeftPadding: false, removeLeftPadding: false,
removeTopPadding: true, removeTopPadding: true,
removeRightPadding: false, removeRightPadding: false,
removeBottomPadding: widget.resizeToAvoidBottomPadding,
); );
} }
...@@ -918,6 +920,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -918,6 +920,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeftPadding: false, removeLeftPadding: false,
removeTopPadding: true, removeTopPadding: true,
removeRightPadding: false, removeRightPadding: false,
removeBottomPadding: widget.resizeToAvoidBottomPadding,
); );
} }
...@@ -929,6 +932,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -929,6 +932,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeftPadding: false, removeLeftPadding: false,
removeTopPadding: true, removeTopPadding: true,
removeRightPadding: false, removeRightPadding: false,
removeBottomPadding: false,
); );
} }
...@@ -949,6 +953,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -949,6 +953,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeftPadding: false, removeLeftPadding: false,
removeTopPadding: true, removeTopPadding: true,
removeRightPadding: false, removeRightPadding: false,
removeBottomPadding: widget.resizeToAvoidBottomPadding,
); );
} }
...@@ -1038,10 +1043,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -1038,10 +1043,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
children: children, children: children,
delegate: new _ScaffoldLayout( delegate: new _ScaffoldLayout(
statusBarHeight: mediaQuery.padding.top, statusBarHeight: mediaQuery.padding.top,
// TODO(cbracken): this should use viewInsets.bottom only. bottomViewInset: widget.resizeToAvoidBottomPadding ? mediaQuery.viewInsets.bottom : 0.0,
bottomPadding: widget.resizeToAvoidBottomPadding
? math.max(mediaQuery.padding.bottom, mediaQuery.viewInsets.bottom)
: 0.0,
endPadding: endPadding, endPadding: endPadding,
textDirection: textDirection, textDirection: textDirection,
), ),
......
...@@ -32,7 +32,7 @@ void main() { ...@@ -32,7 +32,7 @@ void main() {
await tester.pumpWidget(new Directionality( await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new MediaQuery( child: new MediaQuery(
data: const MediaQueryData(padding: const EdgeInsets.only(bottom: 100.0)), data: const MediaQueryData(viewInsets: const EdgeInsets.only(bottom: 100.0)),
child: new Scaffold( child: new Scaffold(
appBar: new AppBar(title: const Text('Title')), appBar: new AppBar(title: const Text('Title')),
body: new Container(key: bodyKey), body: new Container(key: bodyKey),
...@@ -46,7 +46,7 @@ void main() { ...@@ -46,7 +46,7 @@ void main() {
await tester.pumpWidget(new Directionality( await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new MediaQuery( child: new MediaQuery(
data: const MediaQueryData(padding: const EdgeInsets.only(bottom: 100.0)), data: const MediaQueryData(viewInsets: const EdgeInsets.only(bottom: 100.0)),
child: new Scaffold( child: new Scaffold(
appBar: new AppBar(title: const Text('Title')), appBar: new AppBar(title: const Text('Title')),
body: new Container(key: bodyKey), body: new Container(key: bodyKey),
...@@ -59,48 +59,13 @@ void main() { ...@@ -59,48 +59,13 @@ void main() {
expect(bodyBox.size, equals(const Size(800.0, 544.0))); expect(bodyBox.size, equals(const Size(800.0, 544.0)));
}); });
testWidgets('Scaffold bottom padding is the greater of window padding or view inset', (WidgetTester tester) async {
final Key bodyKey = new UniqueKey();
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 50.0),
viewInsets: const EdgeInsets.only(bottom: 100.0),
),
child: new Scaffold(
body: new Container(key: bodyKey),
),
),
));
final RenderBox bodyBox = tester.renderObject(find.byKey(bodyKey));
expect(bodyBox.size, equals(const Size(800.0, 500.0)));
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 200.0),
viewInsets: const EdgeInsets.only(bottom: 100.0),
),
child: new Scaffold(
body: new Container(key: bodyKey),
),
),
));
expect(bodyBox.size, equals(const Size(800.0, 400.0)));
});
testWidgets('Scaffold large bottom padding test', (WidgetTester tester) async { testWidgets('Scaffold large bottom padding test', (WidgetTester tester) async {
final Key bodyKey = new UniqueKey(); final Key bodyKey = new UniqueKey();
await tester.pumpWidget(new Directionality( await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new MediaQuery( child: new MediaQuery(
data: const MediaQueryData( data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 700.0), viewInsets: const EdgeInsets.only(bottom: 700.0),
), ),
child: new Scaffold( child: new Scaffold(
body: new Container(key: bodyKey), body: new Container(key: bodyKey),
...@@ -115,7 +80,7 @@ void main() { ...@@ -115,7 +80,7 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new MediaQuery( child: new MediaQuery(
data: const MediaQueryData( data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 500.0), viewInsets: const EdgeInsets.only(bottom: 500.0),
), ),
child: new Scaffold( child: new Scaffold(
body: new Container(key: bodyKey), body: new Container(key: bodyKey),
...@@ -129,7 +94,7 @@ void main() { ...@@ -129,7 +94,7 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new MediaQuery( child: new MediaQuery(
data: const MediaQueryData( data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 580.0), viewInsets: const EdgeInsets.only(bottom: 580.0),
), ),
child: new Scaffold( child: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
...@@ -185,7 +150,7 @@ void main() { ...@@ -185,7 +150,7 @@ void main() {
textDirection: textDirection, textDirection: textDirection,
child: const MediaQuery( child: const MediaQuery(
data: const MediaQueryData( data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 200.0), viewInsets: const EdgeInsets.only(bottom: 200.0),
), ),
child: const Scaffold( child: const Scaffold(
floatingActionButton: const FloatingActionButton( floatingActionButton: const FloatingActionButton(
...@@ -585,8 +550,9 @@ void main() { ...@@ -585,8 +550,9 @@ void main() {
left: 20.0, left: 20.0,
top: 30.0, top: 30.0,
right: 50.0, right: 50.0,
bottom: 70.0, bottom: 60.0,
), ),
viewInsets: const EdgeInsets.only(bottom: 70.0),
), ),
child: new Scaffold( child: new Scaffold(
appBar: new PreferredSize( appBar: new PreferredSize(
...@@ -655,8 +621,8 @@ void main() { ...@@ -655,8 +621,8 @@ void main() {
expect(tester.getRect(find.byKey(insideBody)), new Rect.fromLTRB(20.0, 43.0, 750.0, 338.0)); expect(tester.getRect(find.byKey(insideBody)), new Rect.fromLTRB(20.0, 43.0, 750.0, 338.0));
expect(tester.getRect(find.byKey(insideFloatingActionButton)), new Rect.fromLTRB(36.0, 245.0, 113.0, 322.0)); expect(tester.getRect(find.byKey(insideFloatingActionButton)), new Rect.fromLTRB(36.0, 245.0, 113.0, 322.0));
expect(tester.getRect(find.byKey(insidePersistentFooterButton)), new Rect.fromLTRB(28.0, 347.0, 128.0, 437.0)); expect(tester.getRect(find.byKey(insidePersistentFooterButton)), new Rect.fromLTRB(28.0, 347.0, 128.0, 437.0));
expect(tester.getRect(find.byKey(insideDrawer)), new Rect.fromLTRB(596.0, 30.0, 750.0, 530.0)); expect(tester.getRect(find.byKey(insideDrawer)), new Rect.fromLTRB(596.0, 30.0, 750.0, 540.0));
expect(tester.getRect(find.byKey(insideBottomNavigationBar)), new Rect.fromLTRB(20.0, 445.0, 750.0, 530.0)); expect(tester.getRect(find.byKey(insideBottomNavigationBar)), new Rect.fromLTRB(20.0, 445.0, 750.0, 470.0));
}); });
testWidgets('Simultaneous drawers on either side', (WidgetTester tester) async { testWidgets('Simultaneous drawers on either side', (WidgetTester tester) async {
......
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