Skip to content
TypeScript

fix(mobile): Android composer renders DM Sans (#30230)

Julius Marminge23bdb9ef1cc3
diff --git a/apps/mobile/modules/t3-composer-editor/android/build.gradle b/apps/mobile/modules/t3-composer-editor/android/build.gradle
index 9425c8f7de3..fbb0d2d3767 100644
--- a/apps/mobile/modules/t3-composer-editor/android/build.gradle
+++ b/apps/mobile/modules/t3-composer-editor/android/build.gradle
@@ -20,6 +20,7 @@ android {
dependencies {
implementation project(':expo-modules-core')
+ implementation 'com.facebook.react:react-android'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.16.1'
}
diff --git a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt
index 0fab5b17da8..4d2a5e3a744 100644
--- a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt
+++ b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt
@@ -30,6 +30,7 @@ import android.view.inputmethod.InputConnection
import android.view.inputmethod.InputConnectionWrapper
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
+import com.facebook.react.common.assets.ReactFontManager
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.viewevent.EventDispatcher
import expo.modules.kotlin.views.ExpoView
@@ -276,8 +277,9 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
editor.typeface = if (fontFamily.contains("Mono", ignoreCase = true)) {
Typeface.MONOSPACE
} else {
- Typeface.DEFAULT
+ ReactFontManager.getInstance().getTypeface(fontFamily, Typeface.NORMAL, context.assets)
}
+ applyLineHeight()
editor.applyPlaceholder()
}
diff --git a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ContextChip.kt b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ContextChip.kt
index b181c663df5..05aa101655f 100644
--- a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ContextChip.kt
+++ b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ContextChip.kt
@@ -9,6 +9,7 @@ import android.graphics.RectF
import android.graphics.Typeface
import android.text.TextPaint
import android.text.TextUtils
+import com.facebook.react.common.assets.ReactFontManager
import kotlin.math.ceil
import kotlin.math.min
@@ -29,14 +30,14 @@ class T3ContextChip(
private val paint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
textSize = fontSize
- typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL)
+ typeface = chipTypeface()
}
private val em = fontSize
private val detailPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
textSize = fontSize * 0.84f
- typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL)
+ typeface = chipTypeface()
}
private val detailText = if (content.detail.isEmpty()) "" else " ${content.detail}"
@@ -86,6 +87,18 @@ class T3ContextChip(
}
companion object {
+ private const val CHIP_FONT_FAMILY = "DMSans-Medium"
+
+ // Matches the iOS chips; builds without the bundled font keep the platform medium.
+ private fun chipTypeface(): Typeface {
+ val fonts = ReactFontManager.getInstance()
+ return if (CHIP_FONT_FAMILY in fonts.customFontFamilies) {
+ fonts.getTypeface(CHIP_FONT_FAMILY, Typeface.NORMAL, null)
+ } else {
+ Typeface.create("sans-serif-medium", Typeface.NORMAL)
+ }
+ }
+
fun color(
value: String,
fallback: Int