-
Notifications
You must be signed in to change notification settings - Fork 25k
Refactor softInputMode check in ReactRootView.java
#40970
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
Conversation
|
This pull request was exported from Phabricator. Differential Revision: D50297761 |
Base commit: 4466001 |
| } else { | ||
| return; | ||
| } | ||
| ViewGroup.LayoutParams rootLayoutParams = getRootView().getLayoutParams(); |
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.
👍
|
@NickGerleman yes, it works in my app and looks much better then drilling |
|
This pull request was exported from Phabricator. Differential Revision: D50297761 |
Summary: This cleans up facebook@9497203 a bit, after I did some debugging and looking through Android source code. 1. `getRootView()` gives us constant-time access to root hierarchy, and we don't need to do instanceof check once per level. It also, at least in the sample activity I tried, gives us the Window's `LayoutParams`. 2. The root of the hierarchy is documented in code to do what we want. facebook@9497203 3. Calling `getRootView().getLayoutParams()`, then casting to `WindowManager.LayoutParams`, seems to show up in a lot of other widgets (inc Unity, RoboElectric), as a solution to getting this information. https://github.com/search?q=getRootView%28%29.getLayoutParams%28%29&type=code This still feels like not a 100% documented contract, so I added an assertion so we can catch if the contract isn't valid somewhere now or in the future, instead of silently breaking keyboard events. Note that this code only runs on SDK 30+ (Android 11+). Changelog: [Internal] Reviewed By: javache Differential Revision: D50297761
95ec4d3 to
8560c12
Compare
|
This pull request was exported from Phabricator. Differential Revision: D50297761 |
|
This pull request has been merged in bb9cc0c. |
Summary: Pull Request resolved: facebook#40970 This cleans up facebook@9497203 a bit, after I did some debugging and looking through Android source code. 1. `getRootView()` gives us constant-time access to root hierarchy, and we don't need to do instanceof check once per level. It also, at least in the sample activity I tried, gives us the Window's `LayoutParams`. 2. The root of the hierarchy is documented in code to do what we want. facebook@9497203 3. Calling `getRootView().getLayoutParams()`, then casting to `WindowManager.LayoutParams`, seems to show up in a lot of other widgets (inc Unity, RoboElectric), as a solution to getting this information. https://github.com/search?q=getRootView%28%29.getLayoutParams%28%29&type=code This still feels like not a 100% documented contract, so I added an assertion so we can catch if the contract isn't valid somewhere now or in the future, instead of silently breaking keyboard events. Note that this code only runs on SDK 30+ (Android 11+). Changelog: [Internal] Reviewed By: javache Differential Revision: D50297761 fbshipit-source-id: f97fb6ea1bcdb1b8e8dfcdcc178625efc0bb6b4a
Summary
This cleans up 9497203 a bit, after I did some debugging and looking through Android source code.
getRootView()gives us constant-time access to root hierarchy, and we don't need to do instanceof check once per level. It also, at least in the sample activity I tried, gives us the Window'sLayoutParams.getRootView().getLayoutParams(), then casting toWindowManager.LayoutParams, seems to show up in a lot of other widgets (inc Unity, RoboElectric), as a solution to getting this information. https://github.com/search?q=getRootView%28%29.getLayoutParams%28%29&type=codeThis still feels like not a 100% documented contract, so I added an assertion so we can catch if the contract isn't valid somewhere now or in the future, instead of silently breaking keyboard events.
Note that this code only runs on SDK 30+ (Android 11+).
Test Plan
On Android API 34 emulator, set an explicit
windowSoftInputModeforRNTesterActivityand check the keyboard events page run viabuck install rntester-android.adjustResize(RN default)adjustPanadjustNothingDifferential Revision: D50297761