-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Implement resizeToAvoidBottomPadding in CupertinoPageScaffold #20929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement resizeToAvoidBottomPadding in CupertinoPageScaffold #20929
Conversation
xster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your addition. Please also add a test for this in test/cupertino/scaffold_test.dart. A mock MediaQuery with a viewInsets can be added above the scaffold.
| data: existingMediaQuery.copyWith( | ||
| padding: existingMediaQuery.padding.copyWith( | ||
| top: topPadding, | ||
| bottom: bottomPadding, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah my apologies, I misread your previous code. You weren't adding the MediaQuery.padding.bottom as padding, you were just propagating it down. That was correct.
This should just be existingMediaQuery.padding.bottom + bottomPadding as you had it before.
|
I had to wrap |
xster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the changes. I see what's happening with the tests. A few more comments. Please bear with me.
| @required this.child, | ||
| }) : assert(child != null), | ||
| super(key: key); | ||
| }) : assert(child != null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave as before. There's 2 spaces now
| /// prevents widgets inside the body from being obscured by the keyboard. | ||
| /// | ||
| /// Defaults to true. | ||
| final bool resizeToAvoidBottomPadding; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is a good opportunity to make sure the API naming is current. Unfortunately the Material scaffold's name was created before we distinguished between full 'insets' where the usable view area shrinks due to things like keyboard and 'paddings' where it's obstructions from things like the home bar and notch etc.
Let's name this resizeToAvoidBottomInset
| /// By default uses [CupertinoColors.white] color. | ||
| final Color backgroundColor; | ||
|
|
||
| /// Whether the [child] should size itself to avoid the window's bottom padding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window's bottom inset.
|
|
||
| // Propagate bottom padding and include viewInsets if appropriate | ||
| final double bottomPadding = resizeToAvoidBottomPadding | ||
| ? existingMediaQuery.viewInsets.bottom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just 4 spaces
| data: existingMediaQuery.copyWith( | ||
| padding: existingMediaQuery.padding.copyWith( | ||
| top: topPadding, | ||
| bottom: existingMediaQuery.padding.bottom + bottomPadding, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this a bit more carefully, I see what's happening in the tests. Instead of converting MediaQuery insets into MediaQuery paddings, we want to directly apply the insets to the contents.
In other words, leave the MediaQuery part as is but wrap that whole thing with a Padding with a bottom padding from the inset. This matches the Material scaffold's behavior more and you can remove the SafeAreas in the test.
xster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for the changes! I'll merge it in when the build tree is green
| ), | ||
| ), | ||
| child: child, | ||
| child: Padding( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the linter doesn't currently pop a warning for these but we're still using Dart1 syntax for the time being. new Padding here.
| this.backgroundColor = CupertinoColors.white, | ||
| this.resizeToAvoidBottomInset = true, | ||
| @required this.child, | ||
| }) : assert(child != null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert that resizeToAvoidBottomInset is not null like child here
Currently CupertinoPageScaffold doesn't use viewInsets to pad content as Material Scaffold does.
You can see actual master behavior below and fixed version next to it.
Repository for above PoC app: https://github.com/SPodjasek/flutter_scaffold_poc