[CP][stable][web] Fix resizeToAvoidBottomInset on Android web (#179581)#180535
Conversation
Fixes flutter#175074 There was an implicit expectation in the resizing code: When the virtual keyboard is up on mobile, the view's `physicalSize` remains fixed, and any resizes (presumably caused by the virtual keyboard itself) should be considered as `viewInsets`. This expectation was broken inadvertently by my PR: flutter#172493 <hr> The sequence of events that lead to the reported issue: 1. View's physical size is calculated based on window size. 2. Text editing starts, virtual keyboard comes up. 3. View's physical size remains unchanged, and the difference caused by the keyboard is reported as view insets to the framework. 4. (so far so good). 5. When `resizeToAvoidBottomInset` is true, the framework will re-render its content to fit the available size. 6. The new render call comes with a new size that's basically `physical height - bottom inset`. 7. The engine takes that new size and applies it to the DOM. 8. (now the view's DOM element has been resized incorrectly). 9. ... 10. Eventually, this leads to the new insets being calculated incorrectly resulting in negative insets which cause the framework to throw. <hr> The fix involves the following: 1. Respect the expectation mentioned above: when the keyboard is up, view's physical size should remain unchanged. 2. *_If_* we ever end up with negative insets, catch it earlier in the engine so it's easier to debug the root cause. 3. New regression test.
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request is a cherry-pick to fix an issue on Android web where the app view does not correctly resize after the virtual keyboard is closed. The changes introduce logic to preserve the view's physical size while the keyboard is active, relying on view insets for layout adjustments. This prevents the framework from prematurely shrinking the physical size, which caused the rendering issue upon keyboard dismissal. The method renames (_didResize to _handleBrowserResize and resize to handleFrameworkResize) improve code clarity. Additionally, a new assertion for non-negative view insets is a great defensive measure, and the new unit tests correctly validate the fix. The changes are well-implemented and address the issue effectively.
camsim99
left a comment
There was a problem hiding this comment.
LGTM thanks for this fix!
48cd386
into
flutter:flutter-3.38-candidate.0
Manual CP of the original PR: #179581
The "cherry-pick template" linked in https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process/e7b042dd481d4ac66477fb281b6e626e8dba8a4e seems to be broken, so I copied the template from previous CP.
Issue Link:
#175074
Impact Description:
All Android users are affected.
Changelog Description:
When the virtual keyboard is closed, the area behind it remains blank and the app only draws in the area that used to be above the keyboard.
Workaround:
None
Risk:
What is the risk level of this cherry-pick?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?