Fix Dimensions window values on Android < 15#53254
Fix Dimensions window values on Android < 15#53254zoontek wants to merge 4 commits intofacebook:mainfrom
Conversation
22726c1 to
c95b5aa
Compare
|
@alanleedev has imported this pull request. If you are a Meta employee, you can view this in D80237818. |
c95b5aa to
47d8ed5
Compare
|
|
@alanleedev has imported this pull request. If you are a Meta employee, you can view this in D80237818. |
|
@zoontek There was a question if we could to" keep initDisplayMetrics as a backwards-compat API and have it call both". I haven't quite figured out the internal crash yet. And it does seem like new API does make things bit more fragile. Do you have any thoughts here? |
|
@alanleedev One alternative could be to extract the is UI thread method from AndroidX, set both screen and window dimensions when |
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
This PR is stale because it has been open for 180 days with no activity. It will be closed in 7 days unless you comment on it or remove the "Stale" label. |
9e4c7de to
6ccb1ef
Compare
|
As |
|
8b4c84a to
84d709e
Compare
| } | ||
|
|
||
| @JvmStatic | ||
| public fun getDisplayMetricsWritableMap(fontScale: Double): WritableMap { |
There was a problem hiding this comment.
The methods have been moved to DeviceInfoModule.kt, as they are only used there.
| } | ||
|
|
||
| @Test | ||
| fun getDisplayMetricsWritableMap_returnsCorrectMap() { |
There was a problem hiding this comment.
This test has been moved to DeviceInfoModuleTest.kt
| @Before | ||
| fun setUp() { | ||
| context = RuntimeEnvironment.getApplication() | ||
| DisplayMetricsHolder.setWindowDisplayMetrics(null) |
There was a problem hiding this comment.
PixelUtil.kt is not using window display metrics since this commit. Those can be safely removed.
| + notchHeight; | ||
|
|
||
| int heightPixels = getContext().getResources().getDisplayMetrics().heightPixels; | ||
| final ReactContext reactContext = getCurrentReactContext(); |
There was a problem hiding this comment.
This is the same logic used in DeviceInfoModule.kt getWindowDisplayMetrics, but it has been inlined instead of extracted as a function, since checkForKeyboardEventsLegacy will be deleted here
423f52e to
cc6c878
Compare
9e07deb to
9ffbd21
Compare
| layout.text, | ||
| layout, | ||
| DisplayMetricsHolder.getWindowDisplayMetrics(), | ||
| DisplayMetricsHolder.getScreenDisplayMetrics(), |
There was a problem hiding this comment.
This is OK, as it's only used for screen density.
Summary:
This PR (initially created for edge-to-edge opt-in support, rebased multiple times) fixes the
DimensionsAPIwindowvalues on Android < 15, when edge-to-edge is enabled.Currently the window height doesn't include the status and navigation bar heights (but it does on Android >= 15):
Using
WindowMetricsCalculatorfrom AndroidX:Fixes #47080
Changelog:
[Android] [Fixed] Fix
Dimensionswindowvalues on Android < 15 when edge-to-edge is enabledTest Plan:
Run the example app on an Android < 15 device.