From 50793033f2201d2950d910507cb07307f955b5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Fri, 20 Dec 2024 16:43:15 +0100 Subject: [PATCH] fix(modal): [android] syncing activity system bars visibility with dialog --- .../react/views/modal/ReactModalHostView.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt index 271e00f425fc..17cc2c3b4e34 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt @@ -21,6 +21,7 @@ import android.view.View import android.view.ViewGroup import android.view.ViewStructure import android.view.Window +import android.view.WindowInsets import android.view.WindowInsetsController import android.view.WindowManager import android.view.accessibility.AccessibilityEvent @@ -365,6 +366,9 @@ public class ReactModalHostView(context: ThemedReactContext) : } } + /** + * Updates the system appearance of the dialog to match the activity that it is being displayed on. + */ private fun updateSystemAppearance() { val currentActivity = getCurrentActivity() ?: return val dialog = checkNotNull(dialog) { "dialog must exist when we call updateProperties" } @@ -375,17 +379,31 @@ public class ReactModalHostView(context: ThemedReactContext) : if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { val insetsController: WindowInsetsController = checkNotNull(activityWindow.insetsController) val activityAppearance: Int = insetsController.systemBarsAppearance + val rootWindowInsets = activityWindow.decorView.rootWindowInsets val activityLightStatusBars = activityAppearance and WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS dialogWindow.insetsController?.setSystemBarsAppearance( activityLightStatusBars, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS) + + syncSystemBarsVisibility(rootWindowInsets, dialogWindow.insetsController, WindowInsets.Type.statusBars()) + syncSystemBarsVisibility(rootWindowInsets, dialogWindow.insetsController, WindowInsets.Type.navigationBars()) } else { dialogWindow.decorView.systemUiVisibility = activityWindow.decorView.systemUiVisibility } } + /** + * Syncs the visibility of the system bars based on their visibility in the root window insets. + * This ensures consistency between the system bars visibility in the activity and the dialog. + */ + private fun syncSystemBarsVisibility(rootWindowInsets: WindowInsets, dialogWindowInsetsController: WindowInsetsController?, type: Int) { + dialogWindowInsetsController?.apply { + if (rootWindowInsets.isVisible(type)) show(type) else hide(type) + } + } + // This listener is called when the user presses KeyEvent.KEYCODE_BACK // An event is then passed to JS which can either close or not close the Modal by setting the // visible property