Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -380,6 +381,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" }
Expand All @@ -390,17 +394,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)
}
}

/**
* Sets the testID on the DialogRootViewGroup. Since the accessibility events are not triggered on
* the on the ReactModalHostView, the testID is forwarded to the DialogRootViewGroup to set the
Expand Down