Skip to content

Commit 60ecc86

Browse files
committed
fix(mobile): scale native text with system font settings
1 parent a2398c2 commit 60ecc86

80 files changed

Lines changed: 755 additions & 243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/global.css‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
--text-2xl--line-height: 32px;
3838
--text-3xl: 30px;
3939
--text-3xl--line-height: 36px;
40+
--text-4xl: 36px;
41+
--text-4xl--line-height: 40px;
4042
}
4143

4244
/* ─── Custom utilities ──────────────────────────────────────────────── */

‎apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
277277
}
278278

279279
fun setFontSize(fontSize: Float) {
280-
editor.textSize = fontSize
280+
editor.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize)
281281
applyLineHeight()
282282
applyTokenSpans()
283283
editor.applyPlaceholder()

‎apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
472472
textView.keyboardDismissMode = .interactive
473473
textView.alwaysBounceVertical = false
474474
textView.showsVerticalScrollIndicator = true
475-
textView.adjustsFontForContentSizeCategory = true
475+
textView.adjustsFontForContentSizeCategory = false
476476
textView.onPasteImages = { [weak self] urls in
477477
self?.onComposerPasteImages(["uris": urls])
478478
}
@@ -510,7 +510,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
510510
addSubview(textView)
511511

512512
placeholderLabel.numberOfLines = 0
513-
placeholderLabel.adjustsFontForContentSizeCategory = true
513+
placeholderLabel.adjustsFontForContentSizeCategory = false
514514
addSubview(placeholderLabel)
515515
applyTypography()
516516
applyTheme()

‎apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3NativeControlsModule.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package expo.modules.t3nativecontrols
22

33
import android.content.Intent
44
import android.text.format.DateFormat
5+
import android.util.TypedValue
56
import androidx.core.content.FileProvider
67
import expo.modules.kotlin.Promise
78
import expo.modules.kotlin.modules.Module
@@ -21,6 +22,16 @@ class T3NativeControlsModule : Module() {
2122
DateFormat.is24HourFormat(context)
2223
}
2324

25+
Function("scaledFontSize") { size: Double ->
26+
val context = appContext.reactContext ?: error("The app is not active.")
27+
val metrics = context.resources.displayMetrics
28+
TypedValue.applyDimension(
29+
TypedValue.COMPLEX_UNIT_SP,
30+
size.toFloat(),
31+
metrics
32+
) / metrics.density
33+
}
34+
2435
AsyncFunction("openFile") { uri: String, mimeType: String, promise: Promise ->
2536
check(filePreviewPromise == null) { "A document viewer is already open." }
2637
val activity = appContext.currentActivity ?: error("The app is not active.")

‎apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class T3NativeControlsModule: Module {
2323
ViewName("SegmentedControl")
2424
Events("onSelectionChange")
2525
Prop("labels") { (view: T3SegmentedControlView, value: [String]) in view.labels = value }
26+
Prop("fontSize") { (view: T3SegmentedControlView, value: Double) in view.fontSize = CGFloat(value) }
2627
Prop("selectedIndex") { (view: T3SegmentedControlView, value: Int) in view.selectedIndex = value }
2728
Prop("trackColor") { (view: T3SegmentedControlView, value: UIColor) in view.trackColor = value }
2829
Prop("selectedColor") { (view: T3SegmentedControlView, value: UIColor) in view.selectedColor = value }

‎apps/mobile/modules/t3-native-controls/ios/T3SegmentedControlView.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class T3SegmentedControlView: ExpoView {
1414
updateSelection()
1515
}
1616
}
17+
var fontSize: CGFloat = 13 { didSet { if fontSize != oldValue { updateColors() } } }
1718
var selectedIndex = -1 { didSet { updateSelection() } }
1819
var trackColor: UIColor = .secondarySystemBackground { didSet { if trackColor != oldValue { control.backgroundColor = trackColor } } }
1920
var selectedColor: UIColor = .secondarySystemFill { didSet { if selectedColor != oldValue { control.selectedSegmentTintColor = selectedColor } } }
@@ -30,6 +31,7 @@ final class T3SegmentedControlView: ExpoView {
3031
super.init(appContext: appContext)
3132
addSubview(control)
3233
control.addTarget(self, action: #selector(selectionChanged), for: .valueChanged)
34+
updateColors()
3335
}
3436

3537
override func layoutSubviews() {
@@ -51,8 +53,8 @@ final class T3SegmentedControlView: ExpoView {
5153
}
5254

5355
private func updateColors() {
54-
control.setTitleTextAttributes([.foregroundColor: mutedColor], for: .normal)
55-
control.setTitleTextAttributes([.foregroundColor: textColor], for: .selected)
56+
control.setTitleTextAttributes([.foregroundColor: mutedColor, .font: UIFont.systemFont(ofSize: fontSize, weight: .medium)], for: .normal)
57+
control.setTitleTextAttributes([.foregroundColor: textColor, .font: UIFont.systemFont(ofSize: fontSize, weight: .semibold)], for: .selected)
5658
}
5759

5860
@objc private func selectionChanged() {

‎apps/mobile/modules/t3-review-diff/android/src/main/java/expo/modules/t3reviewdiff/ReviewDiffCanvasDrawing.kt‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ internal class ReviewDiffCanvasDrawing(context: Context) {
4343
uiPaint.typeface = Typeface.DEFAULT_BOLD
4444
}
4545

46+
fun commentTextMetrics(style: DiffStyle): Paint.FontMetrics {
47+
configureUiPaint(
48+
paint = textPaint,
49+
color = theme.mutedText,
50+
size = style.fileHeaderSubtextFontSizePx,
51+
weight = style.fileHeaderSubtextFontWeight,
52+
)
53+
return textPaint.fontMetrics
54+
}
55+
56+
fun commentTitleBaseline(metrics: Paint.FontMetrics): Float =
57+
max(22f * density, 8f * density - metrics.ascent)
58+
59+
fun commentBodyBaseline(metrics: Paint.FontMetrics): Float =
60+
commentTitleBaseline(metrics) +
61+
max(36f * density, metrics.descent - metrics.ascent + 12f * density)
62+
63+
fun commentRowHeight(style: DiffStyle, collapsed: Boolean): Int {
64+
val metrics = commentTextMetrics(style)
65+
return ceil(
66+
if (collapsed) {
67+
max(44f * density, commentTitleBaseline(metrics) + metrics.descent + 18f * density)
68+
} else {
69+
max(124f * density, commentBodyBaseline(metrics) + metrics.descent + 24f * density)
70+
},
71+
).toInt()
72+
}
73+
4674
fun fileHeaderChevronRect(top: Int, bottom: Int, style: DiffStyle): RectF {
4775
val centerY = (top + bottom) / 2f
4876
val left = style.fileHeaderHorizontalPaddingPx

‎apps/mobile/modules/t3-review-diff/android/src/main/java/expo/modules/t3reviewdiff/T3ReviewDiffView.kt‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ internal data class DiffStyle(
678678
fallback.fileHeaderHorizontalPaddingPx,
679679
density,
680680
),
681-
codeFontSizePx = json.floatSp("codeFontSize", fallback.codeFontSizePx, density),
681+
codeFontSizePx = json.floatDp("codeFontSize", fallback.codeFontSizePx, density),
682682
codeFontWeight = json.optString("codeFontWeight", fallback.codeFontWeight),
683-
lineNumberFontSizePx = json.floatSp(
683+
lineNumberFontSizePx = json.floatDp(
684684
"lineNumberFontSize",
685685
fallback.lineNumberFontSizePx,
686686
density,
@@ -689,9 +689,9 @@ internal data class DiffStyle(
689689
"lineNumberFontWeight",
690690
fallback.lineNumberFontWeight,
691691
),
692-
hunkFontSizePx = json.floatSp("hunkFontSize", fallback.hunkFontSizePx, density),
692+
hunkFontSizePx = json.floatDp("hunkFontSize", fallback.hunkFontSizePx, density),
693693
hunkFontWeight = json.optString("hunkFontWeight", fallback.hunkFontWeight),
694-
fileHeaderFontSizePx = json.floatSp(
694+
fileHeaderFontSizePx = json.floatDp(
695695
"fileHeaderFontSize",
696696
fallback.fileHeaderFontSizePx,
697697
density,
@@ -700,7 +700,7 @@ internal data class DiffStyle(
700700
"fileHeaderFontWeight",
701701
fallback.fileHeaderFontWeight,
702702
),
703-
fileHeaderMetaFontSizePx = json.floatSp(
703+
fileHeaderMetaFontSizePx = json.floatDp(
704704
"fileHeaderMetaFontSize",
705705
fallback.fileHeaderMetaFontSizePx,
706706
density,
@@ -709,7 +709,7 @@ internal data class DiffStyle(
709709
"fileHeaderMetaFontWeight",
710710
fallback.fileHeaderMetaFontWeight,
711711
),
712-
fileHeaderSubtextFontSizePx = json.floatSp(
712+
fileHeaderSubtextFontSizePx = json.floatDp(
713713
"fileHeaderSubtextFontSize",
714714
fallback.fileHeaderSubtextFontSizePx,
715715
density,
@@ -977,11 +977,7 @@ private class DiffCanvasView(context: Context) : View(context) {
977977
private fun rowHeight(row: DiffRow): Int = when (row.kind) {
978978
"file" -> style.fileHeaderHeightPx.toInt()
979979
"notice" -> max((style.rowHeightPx * 2f).toInt(), (44 * density).toInt())
980-
"comment" -> if (collapsedCommentIds.contains(row.id)) {
981-
(44 * density).toInt()
982-
} else {
983-
(124 * density).toInt()
984-
}
980+
"comment" -> drawing.commentRowHeight(style, collapsedCommentIds.contains(row.id))
985981
"line" -> codeWrap.rowHeight(row, style.rowHeightPx.toInt())
986982
else -> style.rowHeightPx.toInt()
987983
}.coerceAtLeast(1)
@@ -1108,6 +1104,10 @@ private class DiffCanvasView(context: Context) : View(context) {
11081104
val pathX = iconRect.right + 10f * density
11091105
val pathWidth = max(24f * density, countsX - pathX - 12f * density)
11101106
val centerY = (top + bottom) / 2f
1107+
val pathHeight = max(
1108+
20f * density,
1109+
ceil(boldTextPaint.fontMetrics.descent - boldTextPaint.fontMetrics.ascent),
1110+
)
11111111
val displayPath = if (
11121112
!row.previousPath.isNullOrEmpty() && row.previousPath != row.filePath
11131113
) {
@@ -1117,7 +1117,7 @@ private class DiffCanvasView(context: Context) : View(context) {
11171117
}
11181118
return FileHeaderPathLayout(
11191119
displayPath = displayPath,
1120-
rect = RectF(pathX, centerY - 10f * density, pathX + pathWidth, centerY + 10f * density),
1120+
rect = RectF(pathX, centerY - pathHeight / 2f, pathX + pathWidth, centerY + pathHeight / 2f),
11211121
)
11221122
}
11231123

@@ -1223,11 +1223,17 @@ private class DiffCanvasView(context: Context) : View(context) {
12231223
borderPaint.style = Paint.Style.FILL
12241224

12251225
val collapsed = collapsedCommentIds.contains(row.id)
1226+
val metrics = drawing.commentTextMetrics(style)
1227+
val titleBaseline = drawing.commentTitleBaseline(metrics)
1228+
val chevronTop = max(
1229+
11f * density,
1230+
titleBaseline + (metrics.ascent + metrics.descent) / 2f - 8f * density
1231+
)
12261232
val chevronRect = RectF(
12271233
cardRect.left + 10f * density,
1228-
cardRect.top + 11f * density,
1234+
cardRect.top + chevronTop,
12291235
cardRect.left + 26f * density,
1230-
cardRect.top + 27f * density,
1236+
cardRect.top + chevronTop + 16f * density,
12311237
)
12321238
drawing.drawDisclosureChevron(canvas, chevronRect, theme.mutedText, collapsed)
12331239
drawing.configureUiPaint(
@@ -1240,7 +1246,7 @@ private class DiffCanvasView(context: Context) : View(context) {
12401246
canvas.drawText(
12411247
ellipsize(title, textPaint, cardRect.right - chevronRect.right - 20f * density),
12421248
chevronRect.right + 10f * density,
1243-
cardRect.top + 22f * density,
1249+
cardRect.top + titleBaseline,
12441250
textPaint,
12451251
)
12461252
if (!collapsed) {
@@ -1253,7 +1259,7 @@ private class DiffCanvasView(context: Context) : View(context) {
12531259
cardRect.right - bodyX - 18f * density
12541260
),
12551261
bodyX,
1256-
cardRect.top + 58f * density,
1262+
cardRect.top + drawing.commentBodyBaseline(metrics),
12571263
textPaint,
12581264
)
12591265
}
@@ -1541,9 +1547,6 @@ private fun JSONObject.optNullableInt(key: String): Int? =
15411547
private fun JSONObject.floatDp(key: String, fallbackPx: Float, density: Float): Float =
15421548
if (has(key)) optDouble(key).toFloat() * density else fallbackPx
15431549

1544-
private fun JSONObject.floatSp(key: String, fallbackPx: Float, density: Float): Float =
1545-
if (has(key)) optDouble(key).toFloat() * density else fallbackPx
1546-
15471550
@Suppress("ReturnCount")
15481551
private fun rowIndexAtOffset(y: Int, rowOffsets: IntArray, rowCount: Int): Int {
15491552
if (rowCount == 0) return 0

‎apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,11 +1034,22 @@ private struct ReviewDiffGeometryConfiguration: Equatable {
10341034
let collapsedFileIds: Set<String>
10351035
let collapsedCommentIds: Set<String>
10361036

1037+
var commentLineHeight: CGFloat {
1038+
ceil(UIFont.systemFont(ofSize: style.fileHeaderSubtextFontSize, weight: style.fileHeaderSubtextFontWeight).lineHeight)
1039+
}
1040+
1041+
var commentTitleHeight: CGFloat { commentLineHeight + 4 }
1042+
var commentBodyTop: CGFloat { max(42, commentTitleHeight + 20) }
1043+
10371044
func height(for row: ReviewDiffNativeRow) -> CGFloat {
10381045
if row.kind == "file" { return style.fileHeaderHeight }
10391046
if collapsedFileIds.contains(row.resolvedFileId) { return 0 }
10401047
if row.kind == "notice" { return max(style.rowHeight * 2, 44) }
1041-
if row.kind == "comment" { return collapsedCommentIds.contains(row.id) ? 44 : 124 }
1048+
if row.kind == "comment" {
1049+
return collapsedCommentIds.contains(row.id)
1050+
? max(44, commentTitleHeight + 24)
1051+
: max(124, 24 + commentBodyTop + 3 * (commentLineHeight + 2))
1052+
}
10421053
return style.rowHeight
10431054
}
10441055
}
@@ -2150,15 +2161,16 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
21502161
let countsGap = min(style.fileHeaderCountGap, 4)
21512162
let countsWidth = deleteWidth + countsGap + addWidth
21522163
let countsX = interactiveRects.checkbox.minX - 10 - countsWidth
2164+
let countsHeight = max(18, ceil(fileHeaderMetaFont.lineHeight))
21532165
drawSingleLineText(
21542166
deleteText,
2155-
rect: CGRect(x: countsX, y: centerY - 9, width: deleteWidth, height: 18),
2167+
rect: CGRect(x: countsX, y: centerY - countsHeight / 2, width: deleteWidth, height: countsHeight),
21562168
color: theme.deleteText,
21572169
font: fileHeaderMetaFont
21582170
)
21592171
drawSingleLineText(
21602172
addText,
2161-
rect: CGRect(x: countsX + deleteWidth + countsGap, y: centerY - 9, width: addWidth, height: 18),
2173+
rect: CGRect(x: countsX + deleteWidth + countsGap, y: centerY - countsHeight / 2, width: addWidth, height: countsHeight),
21622174
color: theme.addText,
21632175
font: fileHeaderMetaFont
21642176
)
@@ -2227,7 +2239,8 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
22272239
cardPath.lineWidth = 1
22282240
cardPath.stroke()
22292241

2230-
let chevronRect = CGRect(x: cardRect.minX + 10, y: cardRect.minY + 11, width: 16, height: 16)
2242+
let titleHeight = geometryConfiguration.commentTitleHeight
2243+
let chevronRect = CGRect(x: cardRect.minX + 10, y: cardRect.minY + max(11, titleHeight / 2), width: 16, height: 16)
22312244
drawDisclosureChevron(rect: chevronRect, color: theme.mutedText, collapsed: isCollapsed)
22322245

22332246
let title = "Comment on \(row.commentRangeLabel ?? "line")"
@@ -2237,7 +2250,7 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
22372250
x: chevronRect.maxX + 10,
22382251
y: cardRect.minY + 8,
22392252
width: max(24, cardRect.width - chevronRect.maxX - 28),
2240-
height: fileHeaderSubtextFont.lineHeight + 4
2253+
height: titleHeight
22412254
),
22422255
color: theme.mutedText,
22432256
font: fileHeaderSubtextFont
@@ -2252,9 +2265,9 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
22522265
body.isEmpty ? "Comment" : body,
22532266
rect: CGRect(
22542267
x: cardRect.minX + 18,
2255-
y: cardRect.minY + 42,
2268+
y: cardRect.minY + geometryConfiguration.commentBodyTop,
22562269
width: max(24, cardRect.width - 36),
2257-
height: max(20, cardRect.height - 56)
2270+
height: max(20, cardRect.height - geometryConfiguration.commentBodyTop - 14)
22582271
),
22592272
color: theme.text,
22602273
font: fileHeaderSubtextFont,
@@ -2287,7 +2300,12 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
22872300

22882301
return ReviewDiffFileHeaderPathLayout(
22892302
displayPath: displayPath,
2290-
rect: CGRect(x: pathX, y: centerY - 10, width: pathWidth, height: 20)
2303+
rect: CGRect(
2304+
x: pathX,
2305+
y: centerY - max(20, ceil(fileHeaderFont.lineHeight)) / 2,
2306+
width: pathWidth,
2307+
height: max(20, ceil(fileHeaderFont.lineHeight))
2308+
)
22912309
)
22922310
}
22932311

@@ -2704,7 +2722,7 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
27042722
maximumLineCount: Int
27052723
) {
27062724
let paragraphStyle = NSMutableParagraphStyle()
2707-
paragraphStyle.lineBreakMode = .byTruncatingTail
2725+
paragraphStyle.lineBreakMode = .byWordWrapping
27082726
paragraphStyle.lineSpacing = 2
27092727

27102728
let attributes: [NSAttributedString.Key: Any] = [
@@ -2715,8 +2733,10 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
27152733
]
27162734
let maxHeight = CGFloat(maximumLineCount) * (font.lineHeight + paragraphStyle.lineSpacing)
27172735
(text as NSString).draw(
2718-
in: CGRect(x: rect.minX, y: rect.minY, width: rect.width, height: min(rect.height, maxHeight)),
2719-
withAttributes: attributes
2736+
with: CGRect(x: rect.minX, y: rect.minY, width: rect.width, height: min(rect.height, maxHeight)),
2737+
options: [.usesLineFragmentOrigin, .truncatesLastVisibleLine],
2738+
attributes: attributes,
2739+
context: nil
27202740
)
27212741
}
27222742

‎apps/mobile/modules/t3-source-text/ios/T3SourceTextShadowNode.mm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
baseTextAttributes.allowFontScaling = baseProps.allowFontScaling;
2323

2424
Float fontSizeMultiplier = 1.0;
25-
if (baseTextAttributes.allowFontScaling) {
25+
if (baseProps.allowFontScaling) {
2626
fontSizeMultiplier = layoutContext.fontSizeMultiplier;
2727
}
2828

0 commit comments

Comments
 (0)