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.gradleindex 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.ktindex 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.InputConnectionimport android.view.inputmethod.InputConnectionWrapperimport android.view.inputmethod.InputMethodManagerimport android.widget.EditText+import com.facebook.react.common.assets.ReactFontManagerimport expo.modules.kotlin.AppContextimport expo.modules.kotlin.viewevent.EventDispatcherimport 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.ktindex 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.RectFimport android.graphics.Typefaceimport android.text.TextPaintimport android.text.TextUtils+import com.facebook.react.common.assets.ReactFontManagerimport kotlin.math.ceilimport 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()color = [email protected]}private val em = fontSizeprivate val detailPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {textSize = fontSize * 0.84f- typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL)+ typeface = chipTypeface()color = [email protected]}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