Commit f8a2fc7c authored by Sebastian Podjasek's avatar Sebastian Podjasek Committed by xster

Implement resizeToAvoidBottomPadding in CupertinoPageScaffold (#20929)

parent 38d155a4
...@@ -22,8 +22,10 @@ class CupertinoPageScaffold extends StatelessWidget { ...@@ -22,8 +22,10 @@ class CupertinoPageScaffold extends StatelessWidget {
Key key, Key key,
this.navigationBar, this.navigationBar,
this.backgroundColor = CupertinoColors.white, this.backgroundColor = CupertinoColors.white,
this.resizeToAvoidBottomInset = true,
@required this.child, @required this.child,
}) : assert(child != null), }) : assert(child != null),
assert(resizeToAvoidBottomInset != null),
super(key: key); super(key: key);
/// The [navigationBar], typically a [CupertinoNavigationBar], is drawn at the /// The [navigationBar], typically a [CupertinoNavigationBar], is drawn at the
...@@ -49,6 +51,15 @@ class CupertinoPageScaffold extends StatelessWidget { ...@@ -49,6 +51,15 @@ class CupertinoPageScaffold extends StatelessWidget {
/// By default uses [CupertinoColors.white] color. /// By default uses [CupertinoColors.white] color.
final Color backgroundColor; final Color backgroundColor;
/// Whether the [child] should size itself to avoid the window's bottom inset.
///
/// For example, if there is an onscreen keyboard displayed above the
/// scaffold, the body can be resized to avoid overlapping the keyboard, which
/// prevents widgets inside the body from being obscured by the keyboard.
///
/// Defaults to true.
final bool resizeToAvoidBottomInset;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<Widget> stacked = <Widget>[]; final List<Widget> stacked = <Widget>[];
...@@ -59,15 +70,20 @@ class CupertinoPageScaffold extends StatelessWidget { ...@@ -59,15 +70,20 @@ class CupertinoPageScaffold extends StatelessWidget {
// TODO(xster): Use real size after partial layout instead of preferred size. // TODO(xster): Use real size after partial layout instead of preferred size.
// https://github.com/flutter/flutter/issues/12912 // https://github.com/flutter/flutter/issues/12912
final double topPadding = navigationBar.preferredSize.height final double topPadding =
+ existingMediaQuery.padding.top; navigationBar.preferredSize.height + existingMediaQuery.padding.top;
// Propagate bottom padding and include viewInsets if appropriate
final double bottomPadding = resizeToAvoidBottomInset
? existingMediaQuery.viewInsets.bottom
: 0.0;
// If navigation bar is opaquely obstructing, directly shift the main content // If navigation bar is opaquely obstructing, directly shift the main content
// down. If translucent, let main content draw behind navigation bar but hint the // down. If translucent, let main content draw behind navigation bar but hint the
// obstructed area. // obstructed area.
if (navigationBar.fullObstruction) { if (navigationBar.fullObstruction) {
paddedContent = new Padding( paddedContent = new Padding(
padding: new EdgeInsets.only(top: topPadding), padding: new EdgeInsets.only(top: topPadding, bottom: bottomPadding),
child: child, child: child,
); );
} else { } else {
...@@ -77,7 +93,10 @@ class CupertinoPageScaffold extends StatelessWidget { ...@@ -77,7 +93,10 @@ class CupertinoPageScaffold extends StatelessWidget {
top: topPadding, top: topPadding,
), ),
), ),
child: new Padding(
padding: new EdgeInsets.only(bottom: bottomPadding),
child: child, child: child,
),
); );
} }
} }
......
...@@ -25,6 +25,55 @@ void main() { ...@@ -25,6 +25,55 @@ void main() {
expect(tester.getTopLeft(find.byType(Center)), const Offset(0.0, 0.0)); expect(tester.getTopLeft(find.byType(Center)), const Offset(0.0, 0.0));
}); });
testWidgets('Contents padding from viewInsets', (WidgetTester tester) async {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(viewInsets: EdgeInsets.only(bottom: 100.0)),
child: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Opaque'),
backgroundColor: Color(0xFFF8F8F8),
),
child: Container(),
),
),
));
expect(tester.getSize(find.byType(Container)).height, 600.0 - 44.0 - 100.0);
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(viewInsets: EdgeInsets.only(bottom: 100.0)),
child: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Transparent'),
),
child: Container(),
),
),
));
expect(tester.getSize(find.byType(Container)).height, 600.0 - 100.0);
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(viewInsets: EdgeInsets.only(bottom: 100.0)),
child: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Title'),
),
resizeToAvoidBottomInset: false,
child: Container(),
),
),
));
expect(tester.getSize(find.byType(Container)).height, 600.0);
});
testWidgets('Contents are between opaque bars', (WidgetTester tester) async { testWidgets('Contents are between opaque bars', (WidgetTester tester) async {
const Center page1Center = Center(); const Center page1Center = Center();
......
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