Skip to content

Commit a3f7aaa

Browse files
Barney Mossmeta-codesync[bot]
authored andcommitted
Fix live editor popup text color in dark mode
Differential Revision: D110472860 fbshipit-source-id: 4bbca6b6a410d787aed766dfc0175142d6654181
1 parent a160b3b commit a3f7aaa

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

vito/tools/liveeditor/src/main/java/com/facebook/fresco/vito/tools/liveeditor/ImageSourceUiUtil.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class ImageSourceUiUtil(private val context: Context) {
100100
as TextView
101101
return textView.apply {
102102
text = spannable
103+
setTextColor(LiveEditorUiUtils.dialogTextColor(context))
103104
setOnClickListener { copyToClipboard(context, info.first, info.second) }
104105
}
105106
}

vito/tools/liveeditor/src/main/java/com/facebook/fresco/vito/tools/liveeditor/LiveEditorUiUtils.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package com.facebook.fresco.vito.tools.liveeditor
99

1010
import android.annotation.SuppressLint
1111
import android.content.Context
12+
import android.content.res.Configuration
1213
import android.graphics.Color
1314
import android.graphics.Typeface
1415
import android.util.TypedValue
@@ -20,6 +21,7 @@ import android.widget.LinearLayout
2021
import android.widget.ScrollView
2122
import android.widget.Spinner
2223
import android.widget.TextView
24+
import androidx.annotation.ColorInt
2325
import com.facebook.drawee.backends.pipeline.info.ImageOrigin
2426
import com.facebook.fresco.vito.core.impl.FrescoDrawable2Impl
2527
import com.facebook.fresco.vito.core.impl.KFrescoVitoDrawable
@@ -96,6 +98,7 @@ class LiveEditorUiUtils(
9698
text = title
9799
textSize = 18f
98100
setTypeface(typeface, android.graphics.Typeface.BOLD)
101+
setTextColor(dialogTextColor(context))
99102
val titleHorizontalPad = 12.dpToPx(context)
100103
val titleBottomPad = 6.dpToPx(context)
101104
setPadding(titleHorizontalPad, 0, titleHorizontalPad, titleBottomPad)
@@ -118,6 +121,7 @@ class LiveEditorUiUtils(
118121
TextView(context).apply {
119122
@SuppressLint("SetTextI18n")
120123
text = "No image options available"
124+
setTextColor(dialogTextColor(context))
121125
}
122126
)
123127
}
@@ -187,6 +191,7 @@ class LiveEditorUiUtils(
187191
text = "$emoji $label ${ImageSourceUiUtil.COPY_GLYPH}"
188192
textSize = 16f
189193
setTypeface(typeface, Typeface.BOLD)
194+
setTextColor(dialogTextColor(context))
190195
val pad = 12.dpToPx(context)
191196
setPadding(pad, 0, pad, pad)
192197
setOnClickListener { ImageSourceUiUtil.copyToClipboard(context, "Cache source", label) }
@@ -212,7 +217,12 @@ class LiveEditorUiUtils(
212217

213218
// Render all info
214219
if (info.isEmpty()) {
215-
addView(TextView(context).apply { text = "Source is Empty" })
220+
addView(
221+
TextView(context).apply {
222+
text = "Source is Empty"
223+
setTextColor(dialogTextColor(context))
224+
}
225+
)
216226
}
217227
info.forEach { infoItem ->
218228
val view = ImageSourceUiUtil(context).createImageInfoView(infoItem, this)
@@ -344,6 +354,24 @@ class LiveEditorUiUtils(
344354
}
345355

346356
companion object {
357+
// Debug tool overlay text colors — chosen to contrast the DIALOG_BACKGROUND_* colors in
358+
// LiveEditorOnScreenButtonController. Kept as literals because the live editor renders
359+
// into a raw overlay Context that does not carry a Material/AppCompat theme, so system
360+
// text-color attributes cannot be relied on.
361+
@SuppressLint("HexColorValueUsage")
362+
@ColorInt
363+
private const val DIALOG_TEXT_NIGHT = 0xFFF0F2F5.toInt()
364+
@SuppressLint("HexColorValueUsage")
365+
@ColorInt
366+
private const val DIALOG_TEXT_DAY = 0xFF1E1E2E.toInt()
367+
368+
@ColorInt
369+
internal fun dialogTextColor(context: Context): Int {
370+
val nightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
371+
return if (nightMode == Configuration.UI_MODE_NIGHT_YES) DIALOG_TEXT_NIGHT
372+
else DIALOG_TEXT_DAY
373+
}
374+
347375
/**
348376
* Returns a human-readable label for the image origin string.
349377
*

0 commit comments

Comments
 (0)