Unverified Commit 5a7224d1 authored by luckysmg's avatar luckysmg Committed by GitHub

Fix bar height changes when toggle keyboard (#106542)

parent 0b617e93
......@@ -156,7 +156,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMediaQuery(context));
final double bottomPadding = MediaQuery.of(context).padding.bottom;
final double bottomPadding = MediaQuery.of(context).viewPadding.bottom;
final Color backgroundColor = CupertinoDynamicColor.resolve(
this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor,
......
......@@ -1114,7 +1114,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
final BottomNavigationBarLandscapeLayout layout = widget.landscapeLayout
?? bottomTheme.landscapeLayout
?? BottomNavigationBarLandscapeLayout.spread;
final double additionalBottomPadding = MediaQuery.of(context).padding.bottom;
final double additionalBottomPadding = MediaQuery.of(context).viewPadding.bottom;
Color? backgroundColor;
switch (_effectiveType) {
......
......@@ -316,7 +316,7 @@ Future<void> main() async {
// Verify height with bottom padding.
await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(bottom: 40.0)),
data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: 40.0)),
child: CupertinoTabScaffold(
tabBar: tabBar,
tabBuilder: (BuildContext context, int index) {
......@@ -359,7 +359,7 @@ Future<void> main() async {
// Verify height with bottom padding.
const double bottomPadding = 40.0;
await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(bottom: bottomPadding)),
data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: bottomPadding)),
child: CupertinoTabScaffold(
tabBar: tabBar,
tabBuilder: (BuildContext context, int index) {
......@@ -370,6 +370,60 @@ Future<void> main() async {
expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding);
});
testWidgets('Ensure bar height will not change when toggle keyboard', (WidgetTester tester) async {
const double tabBarHeight = 56.0;
final CupertinoTabBar tabBar = CupertinoTabBar(
height: tabBarHeight,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))),
label: 'Aka',
),
BottomNavigationBarItem(
icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))),
label: 'Shiro',
),
],
);
const double bottomPadding = 34.0;
// Test the height is correct when keyboard not showing.
// So viewInset should be 0.0.
await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.only(bottom: bottomPadding),
viewPadding: EdgeInsets.only(bottom: bottomPadding),
),
child: CupertinoTabScaffold(
tabBar: tabBar,
tabBuilder: (BuildContext context, int index) {
return const Placeholder();
},
),
));
expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding);
// Now show keyboard, and test the bar height will not change.
await pumpWidgetWithBoilerplate(tester,
MediaQuery(
data: const MediaQueryData(
viewPadding: EdgeInsets.only(bottom: bottomPadding),
viewInsets: EdgeInsets.only(bottom: 336.0),
),
child: CupertinoTabScaffold(
tabBar: tabBar,
tabBuilder: (BuildContext context, int index) {
return const Placeholder();
},
),
),
);
// Expect the bar height should not change.
expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding);
});
testWidgets('Opaque background does not add blur effects', (WidgetTester tester) async {
await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(),
......
......@@ -991,7 +991,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(bottom: 40.0)),
data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: 40.0)),
child: Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
......@@ -1018,7 +1018,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(bottom: 40.0)),
data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: 40.0)),
child: Scaffold(
bottomNavigationBar: BottomNavigationBar(
selectedFontSize: 8,
......@@ -1042,6 +1042,58 @@ void main() {
expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight);
});
testWidgets('BottomNavigationBar height will not change when toggle keyboard', (WidgetTester tester) async {
final Widget child = Scaffold(
bottomNavigationBar: BottomNavigationBar(
selectedFontSize: 8,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit),
label: 'AC',
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
label: 'Alarm',
),
],
),
);
// Test the bar height is correct when not showing the keyboard.
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(
viewPadding: EdgeInsets.only(bottom: 40.0),
padding: EdgeInsets.only(bottom: 40.0),
),
child: child,
),
),
);
// Expect the height is the correct.
const double expectedHeight = kBottomNavigationBarHeight + 40.0;
expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight);
// Now we show the keyboard.
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(
viewPadding: EdgeInsets.only(bottom: 40.0),
viewInsets: EdgeInsets.only(bottom: 336.0),
),
child: child,
),
),
);
// Expect the height is the same.
expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight);
});
testWidgets('BottomNavigationBar action size test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
......
......@@ -672,7 +672,7 @@ void main() {
home: MediaQuery(
data: const MediaQueryData(
// Representing a navigational notch at the bottom of the screen
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 40.0),
viewPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 40.0),
),
child: Scaffold(
body: SingleChildScrollView(
......
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