Font.custom(_:size:relativeTo:) adds size to the text style's size instead of scaling it
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 330
- Forks
- 76
- Avg merge
- 3h 6m
- Merged PRs (30d)
- 1
Description
Description
On Android, Font.custom(_:size:relativeTo:) renders custom fonts at roughly double the requested size. The implementation adds the requested size to the system text style's font size, rather than treating the requested size as the base size to be scaled:
// Sources/SkipUI/SkipUI/Text/Font.swift (main)
public static func custom(_ name: String, size: CGFloat, relativeTo textStyle: Font.TextStyle) -> Font {
#if SKIP
let systemFont = system(textStyle)
return Font(fontImpl: {
let absoluteSize = systemFont.fontImpl().fontSize.value + size // <-- adds instead of scales
androidx.compose.ui.text.TextStyle(fontFamily: Self.findNamedFont(name, ctx: LocalContext.current), fontSize: absoluteSize.sp)
})
#else
fatalError()
#endif
}
Expected behavior (SwiftUI semantics)
On iOS, size is the font's base size at the default Dynamic Type setting, and relativeTo: only selects which text style's scaling curve is applied. Font.custom("MyFont", size: 12, relativeTo: .caption2) renders at 12pt by default.
Actual behavior
On Android, the same call renders at caption2's size + 12 ≈ 24sp — about double the intended size. Any app sharing a typography scale between iOS and Android gets visibly larger text on Android.
Suggested fix
Since Compose's sp unit already applies the user's font scale (and per-style curves aren't available in Compose — the same reason ScaledMetric.init(relativeTo:) ignores its text style), the relativeTo: overload could simply use the requested size directly, matching custom(_:size:):
let absoluteSize = size
Environment
- Skip 1.9.4, skip-ui current
main(verified inSources/SkipUI/SkipUI/Text/Font.swift)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Sources/SkipUI/SkipUI/Text/Font.swift at Font.custom(:size:relativeTo:) and compare it with custom(:size:). Verify the Android size calculation against the reported caption2 example and confirm that the relativeTo overload produces the requested base size while Compose still applies user font scaling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100