From 4317172157efc31d2f896e7e80bb396ec17e4c72 Mon Sep 17 00:00:00 2001 From: generatedunixname89002005232357 Date: Mon, 3 Jun 2024 09:45:15 -0700 Subject: [PATCH] Revert D57878119: Multisect successfully blamed "D57878119: [RN] [Android] Fix status bar height calculation for all cutout sizes" for one test failure Summary: This diff reverts D57878119 D57878119: [RN] [Android] Fix status bar height calculation for all cutout sizes by Abbondanzo causes the following test failure: Tests affected: - [xplat/endtoend/jest-e2e/apps/fb4a/__tests__/dating/onboarding/fb4aDatingOnboardingSessionImpressionLogging-e2e.js](https://www.internalfb.com/intern/test/562949977559606/) Here's the Multisect link: https://www.internalfb.com/multisect/5267005 Here are the tasks that are relevant to this breakage: T189149205: 17 critical tests unhealthy for oncall dating_react_native_sop The backout may land if someone accepts it. If this diff has been generated in error, you can Commandeer and Abandon it. Changelog: [Internal] Reviewed By: Abbondanzo Differential Revision: D58053899 fbshipit-source-id: c65a1094259f85c8e6084b2f191ca1e4cd149510 --- .../modules/statusbar/StatusBarModule.kt | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.kt index 08401927f558f5..14857b9f2884b6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.kt @@ -12,9 +12,9 @@ import android.animation.ValueAnimator import android.animation.ValueAnimator.AnimatorUpdateListener import android.os.Build import android.view.View -import android.view.WindowInsets import android.view.WindowInsetsController import android.view.WindowManager +import android.view.WindowManager.LayoutParams import androidx.core.view.ViewCompat import com.facebook.common.logging.FLog import com.facebook.fbreact.specs.NativeStatusBarManagerAndroidSpec @@ -33,40 +33,31 @@ public class StatusBarModule(reactContext: ReactApplicationContext?) : @Suppress("DEPRECATION") override fun getTypedExportedConstants(): Map { + val context = getReactApplicationContext() + val heightResId = context.resources.getIdentifier("status_bar_height", "dimen", "android") + val height = + heightResId + .takeIf { it > 0 } + ?.let { + PixelUtil.toDIPFromPixel(context.resources.getDimensionPixelSize(it).toFloat()) + } ?: 0 + var statusBarColorString = "black" - val statusBarColor = currentActivity?.window?.statusBarColor + val statusBarColor = getCurrentActivity()?.window?.statusBarColor if (statusBarColor != null) { statusBarColorString = String.format("#%06X", 0xFFFFFF and statusBarColor) } return mapOf( - HEIGHT_KEY to PixelUtil.toDIPFromPixel(getStatusBarHeightPx()), + HEIGHT_KEY to height, DEFAULT_BACKGROUND_COLOR_KEY to statusBarColorString, ) } - @Suppress("DEPRECATION") - private fun getStatusBarHeightPx(): Float { - val activity = currentActivity ?: return 0f - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - val window = activity.window ?: return 0f - val insets = - window.decorView.rootWindowInsets.getInsets( - WindowInsets.Type.statusBars() or - WindowInsets.Type.navigationBars() or - WindowInsets.Type.displayCutout()) - insets.top.toFloat() - } else { - val window = activity.window ?: return 0f - val insets = window.decorView.rootWindowInsets - insets.systemWindowInsetTop.toFloat() - } - } - @Suppress("DEPRECATION") override fun setColor(colorDouble: Double, animated: Boolean) { val color = colorDouble.toInt() - val activity = currentActivity + val activity = getCurrentActivity() if (activity == null) { FLog.w( ReactConstants.TAG, @@ -74,7 +65,7 @@ public class StatusBarModule(reactContext: ReactApplicationContext?) : return } UiThreadUtil.runOnUiThread( - object : GuardedRunnable(reactApplicationContext) { + object : GuardedRunnable(getReactApplicationContext()) { override fun runGuarded() { val window = activity.window ?: return window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) @@ -98,7 +89,7 @@ public class StatusBarModule(reactContext: ReactApplicationContext?) : @Suppress("DEPRECATION") override fun setTranslucent(translucent: Boolean) { - val activity = currentActivity + val activity = getCurrentActivity() if (activity == null) { FLog.w( ReactConstants.TAG, @@ -106,7 +97,7 @@ public class StatusBarModule(reactContext: ReactApplicationContext?) : return } UiThreadUtil.runOnUiThread( - object : GuardedRunnable(reactApplicationContext) { + object : GuardedRunnable(getReactApplicationContext()) { override fun runGuarded() { // If the status bar is translucent hook into the window insets calculations // and consume all the top insets so no padding will be added under the status bar. @@ -131,7 +122,7 @@ public class StatusBarModule(reactContext: ReactApplicationContext?) : @Suppress("DEPRECATION") override fun setHidden(hidden: Boolean) { - val activity = currentActivity + val activity = getCurrentActivity() if (activity == null) { FLog.w( ReactConstants.TAG, @@ -153,7 +144,7 @@ public class StatusBarModule(reactContext: ReactApplicationContext?) : @Suppress("DEPRECATION") override fun setStyle(style: String?) { - val activity = currentActivity + val activity = getCurrentActivity() if (activity == null) { FLog.w( ReactConstants.TAG,