Skip to content

Commit b5be57c

Browse files
zoontekfacebook-github-bot
authored andcommitted
Fix RNTester system bars background when edge-to-edge is enforced (facebook#51929)
Summary: This PR fixes RNTester system bars background color to match the app one (not solid black). ## Changelog: - [Internal] [Changed] - Fix RNTester app system bars color when edge-to-edge is enforced Pull Request resolved: facebook#51929 Test Plan: https://github.com/user-attachments/assets/8be0b721-6514-408f-81cd-2106ae7a17c4 Rollback Plan: Reviewed By: javache Differential Revision: D76352950 Pulled By: alanleedev fbshipit-source-id: 474a81564570764a597aa995a0677617263338be
1 parent b0530f0 commit b5be57c

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
package com.facebook.react.uiapp
99

10+
import android.content.res.Configuration
1011
import android.graphics.Color
11-
import android.graphics.drawable.ColorDrawable
1212
import android.os.Bundle
1313
import android.view.View
1414
import android.widget.FrameLayout
15+
import androidx.core.graphics.drawable.toDrawable
1516
import androidx.core.view.ViewCompat
1617
import androidx.core.view.WindowInsetsCompat
1718
import com.facebook.react.FBRNTesterEndToEndHelper
@@ -43,13 +44,28 @@ internal class RNTesterActivity : ReactActivity() {
4344
if (this::initialProps.isInitialized) initialProps else Bundle()
4445
}
4546

47+
// set background color so it will show below transparent system bars on forced edge-to-edge
48+
private fun maybeUpdateBackgroundColor() {
49+
val isDarkMode =
50+
resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK ==
51+
Configuration.UI_MODE_NIGHT_YES
52+
53+
val color =
54+
if (isDarkMode) {
55+
Color.rgb(11, 6, 0)
56+
} else {
57+
Color.rgb(243, 248, 255)
58+
}
59+
60+
window?.setBackgroundDrawable(color.toDrawable())
61+
}
62+
4663
override fun onCreate(savedInstanceState: Bundle?) {
4764
super.onCreate(savedInstanceState)
4865

4966
fullyDrawnReporter.addReporter()
67+
maybeUpdateBackgroundColor()
5068

51-
// set background color so it will show below transparent system bars on forced edge-to-edge
52-
this.window?.setBackgroundDrawable(ColorDrawable(Color.BLACK))
5369
// register insets listener to update margins on the ReactRootView to avoid overlap w/ system
5470
// bars
5571
getReactDelegate()?.getReactRootView()?.let { rootView ->
@@ -69,6 +85,13 @@ internal class RNTesterActivity : ReactActivity() {
6985
}
7086
}
7187

88+
override fun onConfigurationChanged(newConfig: Configuration) {
89+
super.onConfigurationChanged(newConfig)
90+
91+
// update background color on UI mode change
92+
maybeUpdateBackgroundColor()
93+
}
94+
7295
override fun createReactActivityDelegate() = RNTesterActivityDelegate(this, mainComponentName)
7396

7497
override fun getMainComponentName() = "RNTesterApp"

0 commit comments

Comments
 (0)