Repository navigation
fix(android): don't copy cached typeface when cloning a Font - #8
Merged
Merged
Conversation
FontBase.cloneOrDirty() used Object.assign to copy the source font into the clone, which also copied the Android cached `_typeface`. Clones returned by withFontWeight/withFontFamily/withFontStyle/withFontSize/... then kept returning the stale typeface from getAndroidTypeface(), so the new property was ignored once the source font had been used. Reset `_typeface` for clones too, not only for dirtied fonts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
FontBase.cloneOrDirty()clones withObject.assign(clone, this), which also copies the Android cached_typefaceset byFont.getAndroidTypeface(). Only the non-clone (dirty) branch cleared it.So
withFontWeight/withFontFamily/withFontStyle/withFontSize/withFontScale/withFontVariationSettingsreturned a clone with the new property but the old cached typeface, andgetAndroidTypeface()kept returning it (it only recreates when!this._typeface).Seen in oss-weather:
@nativescript-community/ui-canvasPaint.setFontWeight()callsfont.withFontWeight(weight). Once the paint had drawn, weight changes were ignored (bold text rendered regular).Fix
Reset
_typefaceon the returned font in both branches, so clones rebuild their typeface from their own properties.iOS needs no change:
Fontthere has no per-instance cache;getUIFont()goes through the globaluiFontCachekeyed by the font descriptor.Tests
Added
packages/core/ui/styling/font.spec.ts:with*clone has a null_typeface; source font keeps its ownforceClone = false) still marks dirty and clears_typefaceThe first test fails without the fix (
expected { cached: true } to be null).Note: run locally with vitest and a temporary config (same test settings and
~alias) because@nx/viteisn't installed in that checkout; the standardnx testconfig was not run.Follow-up
Once released, oss-weather can drop
app/helpers/fontClone.tsand thefixFontCloneTypeface()call inapp/main.ts.🤖 Generated with Claude Code