Skip to content

Conversation

@NickGerleman
Copy link
Contributor

@NickGerleman NickGerleman commented Oct 14, 2023

Summary

This cleans up 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. 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+).

Test Plan

On Android API 34 emulator, set an explicit windowSoftInputMode for RNTesterActivity and check the keyboard events page run via buck install rntester-android.

adjustResize (RN default) adjustPan adjustNothing
image image image

Differential Revision: D50297761

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 14, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D50297761

@analysis-bot
Copy link

analysis-bot commented Oct 14, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 17,149,234 +6
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 20,521,885 +7
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 4466001
Branch: main

@github-actions
Copy link

github-actions bot commented Oct 14, 2023

Warnings
⚠️ One hour and a half have passed and the E2E jobs haven't finished yet.

Generated by 🚫 dangerJS against 8560c12

} else {
return;
}
ViewGroup.LayoutParams rootLayoutParams = getRootView().getLayoutParams();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kot331107
Copy link
Contributor

@NickGerleman yes, it works in my app and looks much better then drilling getParent()

@facebook-github-bot
Copy link
Contributor

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
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D50297761

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Oct 17, 2023
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in bb9cc0c.

Othinn pushed a commit to Othinn/react-native that referenced this pull request Oct 30, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants