Unverified Commit 673e9892 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Remove unwanted gap between navigation bar and safe area's child (#29943)

Remove the additional top padding from CupertinoPageScaffold's MediaQuery when the navigation bar is opaque (as the padding was already consumed by the navigation bar).

Related Issue: #29136
parent 393521de
......@@ -34,7 +34,8 @@ class CupertinoPageScaffold extends StatelessWidget {
/// If translucent, the main content may slide behind it.
/// Otherwise, the main content's top margin will be offset by its height.
///
/// The scaffold assumes the navigation bar will consume the [MediaQuery] top padding.
/// The scaffold assumes the navigation bar will account for the [MediaQuery] top padding,
/// also consume it if the navigation bar is opaque.
// TODO(xster): document its page transition animation when ready
final ObstructingPreferredSizeWidget navigationBar;
......@@ -92,7 +93,10 @@ class CupertinoPageScaffold extends StatelessWidget {
// obstructed area.
if (fullObstruction) {
paddedContent = MediaQuery(
data: existingMediaQuery.copyWith(
data: existingMediaQuery
// If the navigation bar is opaque, the top media query padding is fully consumed by the navigation bar.
.removePadding(removeTop: true)
.copyWith(
viewInsets: newViewInsets,
),
child: Padding(
......
......@@ -25,6 +25,34 @@ void main() {
expect(tester.getTopLeft(find.byType(Center)), const Offset(0.0, 0.0));
});
testWidgets('Opaque bar pushes contents down', (WidgetTester tester) async {
BuildContext childContext;
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(viewInsets: EdgeInsets.only(top: 20)),
child: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Opaque'),
backgroundColor: Color(0xFFF8F8F8),
),
child: Builder(
builder: (BuildContext context) {
childContext = context;
return Container();
},
),
),
),
));
expect(MediaQuery.of(childContext).padding.top, 0);
// The top of the [Container] is 44 px from the top of the screen because
// it's pushed down by the opaque navigation bar whose height is 44 px,
// and the 20 px [MediaQuery] top padding is fully absorbed by the navigation bar.
expect(tester.getRect(find.byType(Container)), Rect.fromLTRB(0, 44, 800, 600));
});
testWidgets('Contents padding from viewInsets', (WidgetTester tester) async {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
......
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