Skip to content

Fix Font.custom(_:size:relativeTo:) sizing on Android - #511

Open
gurmeherchawla wants to merge 1 commit into
skiptools:mainfrom
Clockworks-Solutions:fix/custom-font
Open

Fix Font.custom(_:size:relativeTo:) sizing on Android#511
gurmeherchawla wants to merge 1 commit into
skiptools:mainfrom
Clockworks-Solutions:fix/custom-font

Conversation

@gurmeherchawla

Copy link
Copy Markdown

Summary

Font.custom(_:size:relativeTo:) was computing the Android font size incorrectly. The previous implementation added the base text style's system font size on top of the caller-supplied size:

let systemFont = system(textStyle)
let absoluteSize = systemFont.fontImpl().fontSize.value + size
androidx.compose.ui.text.TextStyle(fontSize: absoluteSize.sp)

This produced fonts that were too large (e.g. a .caption-relative custom font of 14pt would actually render at ~26sp), and the relativeTo style was being used as an additive offset rather than just a scaling reference.

Fix

Use size directly in sp units and drop the additive offset:

androidx.compose.ui.text.TextStyle(fontSize: size.sp)

size is the absolute point size at the default Dynamic Type level per the SwiftUI docs. Using sp ensures it scales proportionally with Android's font size accessibility setting — the closest equivalent to iOS Dynamic Type scaling.

This also aligns the behavior of Font.custom(_:size:relativeTo:) with the already-correct Font.custom(_:size:) implementation.

Testing

Personally tested on a real Android device with multiple Dynamic Type levels. Custom fonts now render at the expected size and scale correctly with accessibility font size changes.


Fix authored with assistance from Claude Code (Anthropic). The fix and behavior have been personally reviewed and tested by the contributor.

@cla-bot cla-bot Bot added the cla-signed label Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant