Skip to content

Commit 6e4b14d

Browse files
authored
fix: match StatusBar and edge-to-edge interop according to latest spec (#1185)
## 📜 Description Don't update `backgroundColor`/`translucent` props of `StatusBar` if `edge-to-edge` mode is enabled in RN core. ## 💡 Motivation and Context According to latest spec we shouldn't update `backgroundColor`/`translucent` props of `StatusBar` if `edge-to-edge` mode is enabled: <img width="829" height="427" alt="image" src="https://github.com/user-attachments/assets/ec3ed681-d32a-42af-85cb-34d4fcebef7d" /> <img width="837" height="424" alt="image" src="https://github.com/user-attachments/assets/739d7bc6-cdd5-4f82-b658-373272ddae9c" /> In this PR I check directly if `edge-to-edge` mode is enabled **only** in RN core to keep a backward compatibility with old code and 3rd party libs interop. Closes #1181 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### Android - added `isEdgeToEdgeEnabled` helper function in gradle; - expose `IS_EDGE_TO_EDGE_ENABLED` flag in `BuildConfig`; - don't modify `StatusBar` props such as `backgroundColor`/`translucent` if `edge-to-edge` is enabled in RN core; ## 🤔 How Has This Been Tested? Tested on Pixel 9 Pro (API 35, emulator) + E2E tests. ## 📸 Screenshots (if appropriate): |Before|After| |-------|-----| |<img width="562" height="1187" alt="Image" src="https://github.com/user-attachments/assets/f8ce4e05-5a58-4151-96b5-a8efe6a5a97e" />|<img width="562" height="1149" alt="Image" src="https://github.com/user-attachments/assets/acaaff6a-d5a3-40ec-bcf4-85cf82d94189" />| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 7f460b3 commit 6e4b14d

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def isNewArchitectureEnabled() {
2626
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
2727
}
2828

29+
def isEdgeToEdgeEnabled() {
30+
return project.hasProperty("edgeToEdgeEnabled") && project.edgeToEdgeEnabled == "true"
31+
}
32+
2933
def reactNativeArchitectures() {
3034
def value = project.getProperties().get("reactNativeArchitectures")
3135
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
@@ -55,6 +59,7 @@ android {
5559
versionCode 1
5660
versionName "1.0"
5761
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
62+
buildConfigField "boolean", "IS_EDGE_TO_EDGE_ENABLED", isEdgeToEdgeEnabled().toString()
5863
ndk {
5964
abiFilters (*reactNativeArchitectures())
6065
}

android/src/main/java/com/reactnativekeyboardcontroller/modules/statusbar/StatusBarManagerCompatModuleImpl.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.core.view.WindowInsetsCompat
99
import androidx.core.view.WindowInsetsControllerCompat
1010
import com.facebook.react.bridge.ReactApplicationContext
1111
import com.facebook.react.bridge.UiThreadUtil
12+
import com.reactnativekeyboardcontroller.BuildConfig
1213
import com.reactnativekeyboardcontroller.log.Logger
1314
import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup
1415
import com.reactnativekeyboardcontroller.views.EdgeToEdgeViewRegistry
@@ -38,6 +39,7 @@ class StatusBarManagerCompatModuleImpl(
3839
}
3940

4041
@SuppressLint("ObsoleteSdkInt")
42+
@Suppress("detekt:ReturnCount")
4143
fun setColor(
4244
color: Int,
4345
animated: Boolean,
@@ -47,6 +49,11 @@ class StatusBarManagerCompatModuleImpl(
4749
return original.setColor(color.toDouble(), animated)
4850
}
4951

52+
if (BuildConfig.IS_EDGE_TO_EDGE_ENABLED) {
53+
Logger.w(TAG, "StatusBarModule: Ignored status bar change, current activity is edge-to-edge.")
54+
return
55+
}
56+
5057
val activity = mReactContext.currentActivity
5158
if (activity == null) {
5259
Logger.w(
@@ -79,6 +86,11 @@ class StatusBarManagerCompatModuleImpl(
7986
return original.setTranslucent(translucent)
8087
}
8188

89+
if (BuildConfig.IS_EDGE_TO_EDGE_ENABLED) {
90+
Logger.w(TAG, "StatusBarModule: Ignored status bar change, current activity is edge-to-edge.")
91+
return
92+
}
93+
8294
UiThreadUtil.runOnUiThread {
8395
view()?.forceStatusBarTranslucent(translucent)
8496
}

0 commit comments

Comments
 (0)