@expo+ui+57.0.22.patch 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. diff --git a/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/TextView.kt b/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/TextView.kt
  2. index 66905c6..8828e7f 100644
  3. --- a/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/TextView.kt
  4. +++ b/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/TextView.kt
  5. @@ -133,7 +133,12 @@ enum class TextLineBreakType(val value: String) : Enumerable {
  6. }
  7. }
  8. -fun resolveFontFamily(name: String?, context: Context): FontFamily? {
  9. +fun resolveFontFamily(
  10. + name: String?,
  11. + context: Context,
  12. + weight: FontWeight? = null,
  13. + italic: Boolean = false
  14. +): FontFamily? {
  15. if (name == null) return null
  16. return when (name) {
  17. "default" -> FontFamily.Default
  18. @@ -142,7 +147,11 @@ fun resolveFontFamily(name: String?, context: Context): FontFamily? {
  19. "monospace" -> FontFamily.Monospace
  20. "cursive" -> FontFamily.Cursive
  21. else -> {
  22. - val typeface = ReactFontManager.getInstance().getTypeface(name, Typeface.NORMAL, context.assets)
  23. + // A custom family registered as an XML font family (one file per
  24. + // weight) resolves to the face for this weight; with only
  25. + // Typeface.NORMAL it is always the regular face and `fontWeight` is lost.
  26. + val typeface = ReactFontManager.getInstance()
  27. + .getTypeface(name, weight?.weight ?: FontWeight.Normal.weight, italic, context.assets)
  28. FontFamily(typeface)
  29. }
  30. }
  31. @@ -268,7 +277,14 @@ private fun AnnotatedString.Builder.appendSpans(spans: List<TextSpanRecord>, con
  32. fontSize = span.fontSize?.sp ?: androidx.compose.ui.unit.TextUnit.Unspecified,
  33. fontWeight = span.fontWeight?.toComposeFontWeight(),
  34. fontStyle = span.fontStyle?.toComposeFontStyle(),
  35. - fontFamily = context?.let { resolveFontFamily(span.fontFamily, it) },
  36. + fontFamily = context?.let {
  37. + resolveFontFamily(
  38. + span.fontFamily,
  39. + it,
  40. + span.fontWeight?.toComposeFontWeight(),
  41. + span.fontStyle?.toComposeFontStyle() == FontStyle.Italic
  42. + )
  43. + },
  44. textDecoration = span.textDecoration?.toComposeTextDecoration(),
  45. letterSpacing = span.letterSpacing?.sp ?: androidx.compose.ui.unit.TextUnit.Unspecified,
  46. background = colorToComposeColorOrNull(span.background) ?: androidx.compose.ui.graphics.Color.Unspecified,
  47. @@ -298,7 +314,14 @@ fun FunctionalComposableScope.TextContent(props: TextProps) {
  48. fontSize = props.fontSize?.sp ?: androidx.compose.ui.unit.TextUnit.Unspecified,
  49. fontWeight = props.fontWeight?.toComposeFontWeight(),
  50. fontStyle = props.fontStyle?.toComposeFontStyle(),
  51. - fontFamily = appContext.reactContext?.let { resolveFontFamily(props.fontFamily, it) },
  52. + fontFamily = appContext.reactContext?.let {
  53. + resolveFontFamily(
  54. + props.fontFamily,
  55. + it,
  56. + props.fontWeight?.toComposeFontWeight(),
  57. + props.fontStyle?.toComposeFontStyle() == FontStyle.Italic
  58. + )
  59. + },
  60. textDecoration = props.textDecoration?.toComposeTextDecoration(),
  61. letterSpacing = props.letterSpacing?.sp ?: androidx.compose.ui.unit.TextUnit.Unspecified,
  62. lineHeight = props.lineHeight?.sp ?: androidx.compose.ui.unit.TextUnit.Unspecified,
  63. diff --git a/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/textfield/TextFieldShared.kt b/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/textfield/TextFieldShared.kt
  64. index b7808d7..716ebb8 100644
  65. --- a/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/textfield/TextFieldShared.kt
  66. +++ b/node_modules/@expo/ui/android/src/main/java/expo/modules/ui/textfield/TextFieldShared.kt
  67. @@ -124,7 +124,7 @@ internal fun TextFieldTextStyleRecord?.toTextStyle(context: Context?): TextStyle
  68. color = colorToComposeColorOrNull(color) ?: androidx.compose.ui.graphics.Color.Unspecified,
  69. fontSize = fontSize?.sp ?: TextUnit.Unspecified,
  70. fontWeight = fontWeight?.toComposeFontWeight(),
  71. - fontFamily = context?.let { resolveFontFamily(fontFamily, it) },
  72. + fontFamily = context?.let { resolveFontFamily(fontFamily, it, fontWeight?.toComposeFontWeight()) },
  73. letterSpacing = letterSpacing?.sp ?: TextUnit.Unspecified,
  74. lineHeight = lineHeight?.sp ?: TextUnit.Unspecified,
  75. textAlign = textAlign?.toComposeTextAlign() ?: TextAlign.Unspecified