Text `lineHeight` is honoured on web but not on React Native — multi-line text lays out ~5% taller on iOS
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 45/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- ios, react-native
- 領域
- frontend, mobile-dev
研究方向
Start with the minimal reproduction described in the issue and compare the React Native iOS text-layout path with the web canvas result for authored line heights of 40 and 60. Trace the text-layout source responsible for applying lineHeight, then verify that 11 lines use the authored pitch and that arithmetic positioning by line index matches the web runtime.
由索引模型根據 Issue 內容生成。
描述
Summary
A Text with an explicitly authored lineHeight of 40 (font size 32) lays out at 40px per line in @rive-app/canvas, and at 42px per line in @rive-app/react-native on iOS — from the same .riv file, same text style, same font asset.
The authored value is read and applied on RN — a second test at lineHeight 60 confirms it changes the layout — but the applied pitch is larger than authored. The divergence at 40 is a clean 1.0500 ratio, measured, not estimated.
This breaks any layout that positions content by arithmetic on line height — for us, an odometer-style digit register that translates an 11-line strip to bring one digit into a clipping window.
Environment
| RN runtime | @rive-app/react-native 0.4.19 (Nitro) |
react-native-nitro-modules 0.35.10 |
|
| RiveRuntime 6.21.1 | |
| Web runtime | @rive-app/canvas 2.39.2 |
| Device | iOS Simulator, iPhone 17 Pro |
| Editor | Rive Desktop, beta 0.8.5581 |
Authored values
On the TextStylePaint (property keys as reported by the editor's MCP surface):
| property | key | value |
|---|---|---|
fontsize |
274 | 32.0 |
lineheight |
370 | 40.0 |
letterspacing |
390 | 0.96 |
fontassetid |
279 | an embedded font asset (not a system font; iscustomfont = false) |
On the Text node: sizingvalue = autoWidth, paragraphspacing = 0, verticaltrim = none, fitfrombaseline = true.
The text content is 11 lines: one blank line followed by 0–9. Its container is a fixed 20 x 440 box — 440 = 11 x 40, i.e. sized on the assumption that the authored line height is respected.
Expected
11 lines at lineHeight 40 occupy 440px on every runtime.
Actual
- Web: 440px. Correct.
- RN / iOS: ~462px, i.e. 42px per line.
Evidence
The strip is translated by -((d + 1) * 40) to bring digit d into a 40px clipping window. If the true pitch is 42 rather than 40, each digit lands low by (d + 1) * 40 * 0.05 — an error that grows linearly with the digit value.
Measured glyph tops from a device screenshot (xcrun simctl io … screenshot, luma threshold, 3x scale), same numeric value in two registers, one with a workaround applied and one without:
value 1907, digits 1 / 9 / 0 / 7
unmodified (control) glyph tops 796, 835, 790, 830 spread 45px
workaround applied glyph tops 790, 792, 790, 796 spread 6px
web reference spread equivalent to ~15px at the same scale
(natural round-vs-flat glyph variation; this is the floor)
The control's 45px spread matches the linear-error prediction; the workaround's 6px sits below the glyph-shape floor measured on the known-good web render.
Solving for the pitch ratio from the digit-4-vs-digit-0 gap (24px at 3x = 8 layout units, against a predicted 160(k−1)):
160(k − 1) = 8 -> k = 1.0500 -> rendered pitch = 42.00px
The same model predicts every value we rendered:
| value | predicted per-digit error (units) | observed |
|---|---|---|
| 404 | 4:10, 0:2, 4:10 | 0 appears raised, 4s flush |
| 7890 | 7:16, 8:18, 9:20, 0:2 | 7/8/9 badly low, 0 fine |
| 2607 | 2:6, 6:14, 0:2, 7:16 | 6 and 7 low, 2 and 0 near-flush |
| 1005 | 1:4, 0:2, 0:2, 5:12 | "100" flush, 5 low |
Second data point — lineHeight IS honoured, just not at the authored value
We re-ran with the authored lineHeight changed from 40 to 60 on a single strip, leaving the others untouched as controls, and rendered a value whose leading wheel shows digit 1.
Predicted displacement of that digit for each candidate mechanism (the strip is translated by -(d+1) * 40, so the error is (d+1) * (P - 40)):
| candidate | rendered pitch P | digit-1 displacement |
|---|---|---|
lineHeight ignored, font advance used |
42 | +4 units — digit stays centred in the 40-unit window |
additive, L + 2 |
62 | +44 units — digit leaves the window |
multiplicative, L x 1.05 |
63 | +46 units — digit leaves the window |
Observed: the digit was scrolled fully out of the window — only the edge of a neighbouring glyph remained visible, while the untouched control wheels stayed flush.
That rules out the font-fallback explanation. lineHeight is read and applied; the applied value is simply larger than authored — approximately 42 for an authored 40, and approximately 62–63 for an authored 60.
We could not separate additive (+2) from multiplicative (x1.05): they differ by ~6px at 3x, and at lineHeight 60 the glyph is already outside the clipping window, so there is no in-window measurement that distinguishes them. Both are consistent with every observation. We expect this is immediately obvious from your text-layout source.
Minimal repro
- A
Textwith 11 lines, font size 32,lineHeight40, inside a fixed 20 x 440 container. - Render the same
.rivin@rive-app/canvasand in@rive-app/react-native0.4.19 on iOS. - Measure the vertical distance between the first and last line's baselines. Web gives 400 (10 x 40); RN gives ~420.
Alternatively, translate the strip by -40 * n and observe that the n-th line is not centred in a 40px window on RN, with the offset growing with n.
Workaround (for anyone hitting this)
Force the renderer to fit the text into a known box rather than relying on the authored line height:
sizingvalue autoWidth -> fixed
width -> <container width>
height -> <lines * intended lineHeight>
overflowvalue visible -> fit
With overflow: fit, both runtimes scale the block into the fixed height, so the per-line pitch becomes correct by construction. On RN the glyphs render ~5% smaller as a result, which was an acceptable trade for us. Verified: web unchanged, RN corrected to within glyph-shape noise.
Why it matters beyond our case
lineHeight being platform-dependent silently breaks any design that does arithmetic on it — digit reels, tickers, virtualised lists, anything positioned by line index. There is no error and no warning; the content renders, just in the wrong place, and the error is proportional so small cases look fine and large ones look broken. It took us a full session to localise because every automated check we had asserts view-model values rather than rendered geometry.
- 主要語言
- TypeScript
- 星號
- 785
- 分支
- 81
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rive-app/rive-react-native 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
rive-app/rive-react-native#433 ·
-
難度 2/5 1-3 小時 新手友好度 74/100
rive-app/rive-react-native#431 · 2 則留言 ·
-
難度 4/5 3-5 天 新手友好度 35/100
rive-app/rive-react-native#448 · 2 則留言 · 1 個 reaction ·
-
[Android] Rive events dispatched off the UI thread can deadlock with Reanimated under Fabric (ANR)可能已有人在做 @Togetic 於 38 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 68/100
rive-app/rive-react-native#444 ·
-
難度 4/5 3-5 天 新手友好度 48/100
rive-app/rive-react-native#440 ·
查看 rive-app/rive-react-native 的全部 Issue
相似的 Issue
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:other issue-rating: 🦞 diamond lobster no-stale P2
難度 2/5 1-3 小時 新手友好度 72/100
openclaw/openclaw#168089 · 2 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
✨ enhancement needs-discussion
難度 1/5 1 小時以內 新手友好度 85/100
-
[Bug]: [MCP/CLI] Bare loopback IP addresses (127.0.0.1:port) and hosts with ports fail to navigate due to erroneous scheme inference可能已有人在做 @alok-108 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
microsoft/playwright#43263 ·
維護者通常 1 天內回覆
-
area:studio type:security
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
enhancement good first issue Stellar Wave trivial
難度 2/5 1-3 小時 新手友好度 85/100
StellarCanary/ProtocolCanary-Action#331 ·
維護者通常 1 天內回覆