Skip to content

Commit 670c7e1

Browse files
paufauCopilot
andauthored
Android: do not modify status bar icons color by default (#42)
* Android: Do not modify icons color by default * Android: Do not modify icons color by default * Android: Inherit status bar from root activity window * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Android: remove redundant null safety --------- Co-authored-by: Copilot <[email protected]>
1 parent f460fe0 commit 670c7e1

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

android/src/main/java/com/multiplemodals/RNTModalView.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.multiplemodals
22

3+
import android.app.Activity
34
import android.content.Context
45
import android.content.DialogInterface
56
import android.view.KeyEvent
@@ -23,6 +24,8 @@ import com.facebook.yoga.annotations.DoNotStrip
2324
class RNTModalView(context: Context): ViewGroup(context), LifecycleEventListener {
2425
companion object {
2526
const val REACT_CLASS: String = "RNTModalView"
27+
const val DEFAULT_STATUS_BAR_ICONS_STYLE = "default"
28+
const val STATUS_BAR_DARK_ICONS_STYLE = "dark-content"
2629

2730
@JvmStatic
2831
@DoNotStrip
@@ -54,7 +57,7 @@ class RNTModalView(context: Context): ViewGroup(context), LifecycleEventListener
5457
private var wasShown = false
5558
internal var isShadowViewSizeSet = false
5659
internal var statusBarTranslucent: Boolean = false
57-
internal var statusBarIconsStyle: String = "default"
60+
internal var statusBarIconsStyle: String = DEFAULT_STATUS_BAR_ICONS_STYLE
5861
internal var animationType: String = "none"
5962

6063
init {
@@ -89,7 +92,14 @@ class RNTModalView(context: Context): ViewGroup(context), LifecycleEventListener
8992
modalDialog?.apply {
9093
attachBackHandler(this)
9194
setStatusBarTranslucency(statusBarTranslucent)
92-
setStatusBarDarkIcons(statusBarIconsStyle == "dark-content")
95+
if (statusBarIconsStyle == DEFAULT_STATUS_BAR_ICONS_STYLE) {
96+
val inheritFromActivity = reactContext.currentActivity
97+
if (inheritFromActivity != null) {
98+
inheritStatusBarFromWindow(inheritFromActivity.window)
99+
}
100+
} else {
101+
setStatusBarDarkIcons(statusBarIconsStyle == STATUS_BAR_DARK_ICONS_STYLE)
102+
}
93103
addContent(modalView)
94104
show()
95105
}

android/src/main/java/com/multiplemodals/library/ModalDialog.kt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.multiplemodals.library
22

33
import android.app.Dialog
4+
import android.os.Build
45
import android.os.Bundle
56
import android.view.View
7+
import android.view.Window
68
import android.view.WindowManager.LayoutParams
79
import androidx.core.view.ViewCompat
10+
import androidx.core.view.WindowInsetsCompat
11+
import androidx.core.view.WindowInsetsControllerCompat
812
import com.facebook.react.uimanager.ThemedReactContext
913
import com.multiplemodals.extensions.setStatusBarDarkIcons
1014

@@ -61,4 +65,41 @@ class ModalDialog(reactContext: ThemedReactContext, themeId: Int) : Dialog(react
6165
setStatusBarDarkIcons(isDark)
6266
}
6367
}
64-
}
68+
69+
fun inheritStatusBarFromWindow(inheritFromWindow: Window) {
70+
window?.apply {
71+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
72+
val activityWindowInsetsController =
73+
WindowInsetsControllerCompat(inheritFromWindow, inheritFromWindow.decorView)
74+
val dialogWindowInsetsController =
75+
WindowInsetsControllerCompat(this, decorView)
76+
77+
dialogWindowInsetsController.isAppearanceLightStatusBars =
78+
activityWindowInsetsController.isAppearanceLightStatusBars
79+
80+
inheritFromWindow.decorView.rootWindowInsets?.let { insets ->
81+
val activityRootWindowInsets = WindowInsetsCompat.toWindowInsetsCompat(insets)
82+
syncSystemBarsVisibility(activityRootWindowInsets, dialogWindowInsetsController)
83+
}
84+
} else {
85+
decorView.systemUiVisibility = inheritFromWindow.decorView.systemUiVisibility
86+
}
87+
}
88+
}
89+
90+
private fun syncSystemBarsVisibility(
91+
activityRootWindowInsets: WindowInsetsCompat,
92+
dialogWindowInsetsController: WindowInsetsControllerCompat,
93+
types: List<Int> =
94+
listOf(WindowInsetsCompat.Type.statusBars(), WindowInsetsCompat.Type.navigationBars()),
95+
) {
96+
types.forEach { type ->
97+
val isVisible = activityRootWindowInsets.isVisible(type)
98+
if (isVisible) {
99+
dialogWindowInsetsController.show(type)
100+
} else {
101+
dialogWindowInsetsController.hide(type)
102+
}
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)