Skip to content

Commit d9b787e

Browse files
coadofacebook-github-bot
authored andcommitted
fix(android): displaying dev menu items in light mode (facebook#54119)
Summary: Fixes displaying dev menu items to also take into account the current theme mode. Previously, in light mode, items were not visible because the text was white on a white background for enabled options. ## Changelog: [ANDROID][FIXED] - fixed displaying dev menu items in light mode. Test Plan: Checked in light and dark mode with all options enabled except for "Open DevTools" being disabled. | Before | After | |:------:|:-----:| |<img alt="before-light" src="https://github.com/user-attachments/assets/5a08cb92-8822-4af3-976d-c20db408bcaa" /> |<img alt="after-light" src="https://github.com/user-attachments/assets/02561c15-b6ec-499a-bf83-99bc0c2a9471" />| | Before | After | |:------:|:-----:| | <img alt="before-dark" src="https://github.com/user-attachments/assets/44b2c59e-2fc2-41cc-a599-136ac455afbb" /> |<img alt="after-dark" src="https://github.com/user-attachments/assets/51e6167b-4d3a-4686-a20e-eca17c3b0e10" />| Reviewed By: sbuggay, cortinico Differential Revision: D84346125 Pulled By: coado
1 parent 802e1a7 commit d9b787e

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import android.content.DialogInterface
1717
import android.content.Intent
1818
import android.content.IntentFilter
1919
import android.content.pm.PackageManager
20+
import android.content.res.ColorStateList
2021
import android.graphics.Typeface
2122
import android.hardware.SensorManager
2223
import android.os.Build
@@ -74,6 +75,8 @@ import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatur
7475
import com.facebook.react.modules.core.RCTNativeAppEventEmitter
7576
import com.facebook.react.modules.debug.interfaces.DeveloperSettings
7677
import com.facebook.react.packagerconnection.RequestHandler
78+
import com.facebook.react.views.common.UiModeUtils
79+
import com.facebook.react.views.text.DefaultStyleValuesUtil
7780
import java.io.File
7881
import java.net.MalformedURLException
7982
import java.net.URL
@@ -547,7 +550,11 @@ public abstract class DevSupportManagerBase(
547550
isEnabled = isEnabled(position)
548551
if (this is TextView) {
549552
setTextColor(
550-
if (isEnabled) android.graphics.Color.WHITE else android.graphics.Color.GRAY
553+
if (isEnabled) {
554+
safeGetDefaultTextColor(context)
555+
} else {
556+
safeGetTextColorSecondary(context)
557+
}
551558
)
552559
}
553560
}
@@ -1011,6 +1018,17 @@ public abstract class DevSupportManagerBase(
10111018
}
10121019
}
10131020

1021+
private fun safeGetDefaultTextColor(context: Context): ColorStateList {
1022+
return DefaultStyleValuesUtil.getDefaultTextColor(context)
1023+
?: if (UiModeUtils.isDarkMode(context)) ColorStateList.valueOf(android.graphics.Color.WHITE)
1024+
else ColorStateList.valueOf(android.graphics.Color.BLACK)
1025+
}
1026+
1027+
private fun safeGetTextColorSecondary(context: Context): ColorStateList {
1028+
return DefaultStyleValuesUtil.getTextColorSecondary(context)
1029+
?: ColorStateList.valueOf(android.graphics.Color.GRAY)
1030+
}
1031+
10141032
override fun openDebugger(panel: String?) {
10151033
devServerHelper.openDebugger(
10161034
currentReactContext,

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/DefaultStyleValuesUtil.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public object DefaultStyleValuesUtil {
4141
public fun getDefaultTextColor(context: Context): ColorStateList? =
4242
getDefaultTextAttribute(context, android.R.attr.textColor)
4343

44+
@JvmStatic
45+
public fun getTextColorSecondary(context: Context): ColorStateList? =
46+
getDefaultTextAttribute(context, android.R.attr.textColorSecondary)
47+
4448
/**
4549
* Utility method that returns the default text highlight color as define by the theme
4650
*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<color name="text_color">#FFFFFF</color>
3+
<color name="text_color_secondary">#888888</color>
4+
</resources>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="android:textColor">@color/text_color</item>
7+
<item name="android:textColorSecondary">@color/text_color_secondary</item>
8+
</style>
9+
10+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="text_color">#000000</color>
4+
<color name="text_color_secondary">#888888</color>
5+
</resources>

packages/rn-tester/android/app/src/main/res/values/styles.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<!-- Base application theme. -->
44
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
55
<!-- Customize your theme here. -->
6+
<item name="android:textColor">@color/text_color</item>
7+
<item name="android:textColorSecondary">@color/text_color_secondary</item>
68
</style>
79

810
</resources>

0 commit comments

Comments
 (0)