Skip to content

fix(🔤): apply TextStyle fontVariations on native - #4338

Merged
wcandillon merged 2 commits into
wcandillon:mainfrom
LESANF:fix/text-style-font-variations
Oct 27, 2026
Merged

wcandillon merged 2 commits into
wcandillon:mainfrom
LESANF:fix/text-style-font-variations

Conversation

@LESANF

@LESANF LESANF commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Before / after

wght 100 → 1000 → 100, same code on both sides: 3.8.0 on the left never changes, this PR on the right follows the axis.

wght-sweep

One row per variation, 3.8.0 on the left, this PR on the right.

compare

Problem

fontVariations on a text style has no effect on iOS and Android: a variable font always renders its default instance. Requesting wght 100 or 1000, wdth 25 or 151, or opsz 8 or 144 gives the same glyphs and the same width. The same code works on web.

Roboto Flex at 34 pt on an iPhone 15 Pro (iOS 26.5), width from getLongestLine():

fontVariations 3.8.0 this PR
none 264.36 264.36
wght 100 264.36 259.85
wght 1000 264.36 298.25
wdth 25 264.36 233.54
wdth 151 264.36 309.61
opsz 8 264.36 275.87
opsz 144 264.36 207.20

No issue reports it; I searched the tracker for fontVariations, "variable font" and "font variation".

Root cause

fontVariations is part of SkTextStyle (src/skia/types/Paragraph/TextStyle.ts) and the web implementation passes it to CanvasKit (src/skia/web/JsiSkTextStyle.ts), but the native parser in cpp/api/JsiSkTextStyle.h has no branch for it. It reads fontFeatures and moves on to fontSize, so the axes never reach skparagraph.

Solution

Parse fontVariations next to fontFeatures:

std::vector<SkFontArguments::VariationPosition::Coordinate> coords;
// for each { axis, value }, skipping tags that aren't 4 characters:
coords.push_back({SkSetFourByteTag(axis[0], axis[1], axis[2], axis[3]),
                  static_cast<float>(value)});
SkFontArguments args;
args.setVariationDesignPosition(
    {coords.data(), static_cast<int>(coords.size())});
retVal.setFontArguments(args);

TextStyle::setFontArguments copies the coordinates, so the local vector can go out of scope. cpp/api is shared by iOS and Android. No public API change.

Tests

ParagraphMethods.spec.tsx, "should apply fontVariations", lays out "Hello" with Roboto Flex and checks that wght 100 is narrower, wght 1000 wider and wdth 25 narrower than the default instance. The font is a 4.7 KB subset of Roboto Flex (SIL OFL, no reserved font name) with only the "Hello" glyphs and the wght and wdth axes, added as src/skia/__tests__/assets/RobotoFlex-Hello.ttf.

The test passes in Jest on main too, since CanvasKit already applies the variations. On a device it fails on main, where all four widths are equal, and passes with this PR. The Android e2e job runs this spec (it only skips Paragraphs); the iOS job skips every Paragraph spec.

Verification

On 39d14f7 with this branch:

  • yarn lint · yarn tsc · cpplint (the CI flags): clean
  • yarn test: 117 suites, 894 tests passed (15 suites skipped)
  • yarn test-cpp · yarn build: passed
  • yarn test:web: 41 passed
  • e2e/ParagraphMethods.spec.tsx on a Galaxy Z Fold6 (Android 16) against the example app: 10 passed. With JsiSkTextStyle.h back to main, the new test fails (wght 100 measures 55.125, the same as the default).
  • iOS: I haven't run the e2e suite. The widths above come from a Release build of an Expo SDK 58 app (React Native 0.88) with this change applied to 3.8.0 as a patch.

The lint, build, web and device runs were done with this branch and the plusLighter/plusDarker fix (#4337) applied together. The two touch different files.

Not covered

On iOS the system font from FontMgr.System().matchFamilyStyle(".AppleSystemUIFont", …) still ignores variations with this PR, while the same SF file loaded with Typeface.MakeFromData honors them. I haven't found the cause, so it isn't part of this PR.

Related

2.x has the same gap (its JsiSkTextStyle.h doesn't read fontVariations either); I can open a backport if you want one.

Base

39d14f7

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@wcandillon wcandillon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nice thank you :)

…license

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wcandillon
wcandillon merged commit 04c489f into wcandillon:main Oct 27, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants