mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix(android): displaying dev menu items in light mode (#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. Pull Request resolved: https://github.com/facebook/react-native/pull/54119 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 fbshipit-source-id: e082d1985fdcafe8620cbd02a78a1b122fb08e53
This commit is contained in:
committed by
meta-codesync[bot]
parent
802e1a7726
commit
269b0bd877
@@ -6050,6 +6050,7 @@ public final class com/facebook/react/views/text/DefaultStyleValuesUtil {
|
||||
public static final fun getDefaultTextColor (Landroid/content/Context;)Landroid/content/res/ColorStateList;
|
||||
public static final fun getDefaultTextColorHighlight (Landroid/content/Context;)I
|
||||
public static final fun getDefaultTextColorHint (Landroid/content/Context;)Landroid/content/res/ColorStateList;
|
||||
public static final fun getTextColorSecondary (Landroid/content/Context;)Landroid/content/res/ColorStateList;
|
||||
}
|
||||
|
||||
public abstract class com/facebook/react/views/text/ReactBaseTextShadowNode : com/facebook/react/uimanager/LayoutShadowNode {
|
||||
|
||||
+19
-1
@@ -17,6 +17,7 @@ import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Typeface
|
||||
import android.hardware.SensorManager
|
||||
import android.os.Build
|
||||
@@ -74,6 +75,8 @@ import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatur
|
||||
import com.facebook.react.modules.core.RCTNativeAppEventEmitter
|
||||
import com.facebook.react.modules.debug.interfaces.DeveloperSettings
|
||||
import com.facebook.react.packagerconnection.RequestHandler
|
||||
import com.facebook.react.views.common.UiModeUtils
|
||||
import com.facebook.react.views.text.DefaultStyleValuesUtil
|
||||
import java.io.File
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
@@ -547,7 +550,11 @@ public abstract class DevSupportManagerBase(
|
||||
isEnabled = isEnabled(position)
|
||||
if (this is TextView) {
|
||||
setTextColor(
|
||||
if (isEnabled) android.graphics.Color.WHITE else android.graphics.Color.GRAY
|
||||
if (isEnabled) {
|
||||
safeGetDefaultTextColor(context)
|
||||
} else {
|
||||
safeGetTextColorSecondary(context)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1011,6 +1018,17 @@ public abstract class DevSupportManagerBase(
|
||||
}
|
||||
}
|
||||
|
||||
private fun safeGetDefaultTextColor(context: Context): ColorStateList {
|
||||
return DefaultStyleValuesUtil.getDefaultTextColor(context)
|
||||
?: if (UiModeUtils.isDarkMode(context)) ColorStateList.valueOf(android.graphics.Color.WHITE)
|
||||
else ColorStateList.valueOf(android.graphics.Color.BLACK)
|
||||
}
|
||||
|
||||
private fun safeGetTextColorSecondary(context: Context): ColorStateList {
|
||||
return DefaultStyleValuesUtil.getTextColorSecondary(context)
|
||||
?: ColorStateList.valueOf(android.graphics.Color.GRAY)
|
||||
}
|
||||
|
||||
override fun openDebugger(panel: String?) {
|
||||
devServerHelper.openDebugger(
|
||||
currentReactContext,
|
||||
|
||||
+4
@@ -41,6 +41,10 @@ public object DefaultStyleValuesUtil {
|
||||
public fun getDefaultTextColor(context: Context): ColorStateList? =
|
||||
getDefaultTextAttribute(context, android.R.attr.textColor)
|
||||
|
||||
@JvmStatic
|
||||
public fun getTextColorSecondary(context: Context): ColorStateList? =
|
||||
getDefaultTextAttribute(context, android.R.attr.textColorSecondary)
|
||||
|
||||
/**
|
||||
* Utility method that returns the default text highlight color as define by the theme
|
||||
*
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<resources>
|
||||
<color name="text_color">#FFFFFF</color>
|
||||
<color name="text_color_secondary">#888888</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,10 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:textColor">@color/text_color</item>
|
||||
<item name="android:textColorSecondary">@color/text_color_secondary</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="text_color">#000000</color>
|
||||
<color name="text_color_secondary">#888888</color>
|
||||
</resources>
|
||||
@@ -3,6 +3,8 @@
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:textColor">@color/text_color</item>
|
||||
<item name="android:textColorSecondary">@color/text_color_secondary</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user