-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alter font loading code to support fallback fonts in fontFamily
#31
Conversation
ec024e0
to
767848d
Compare
e9af024
to
e69c6d9
Compare
@@ -192,14 +192,50 @@ - (NSParagraphStyle *)effectiveParagraphStyle | |||
|
|||
- (UIFont *)effectiveFont | |||
{ | |||
// FIXME: RCTFont has thread-safety issues and must be rewritten. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confidence inspiring
String[] fontFamilyNames = fontFamilyName != null ? fontFamilyName.split(",") : null; | ||
if (fontFamilyNames != null) { | ||
for (int i = 0; i < fontFamilyNames.length; i++) { | ||
fontFamilyNames[i] = fontFamilyNames[i].trim(); | ||
} | ||
} | ||
if (fontFamilyNames != null && fontFamilyNames.length > 1) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
return createAssetTypefaceWithFallbacks(fontFamilyNames, style, assetManager); | ||
} else { | ||
fontFamilyName = fontFamilyNames[0]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few checks happening here:
- First we really carefully try to see whether a comma-separated list was passed to
fontFamilyName
- If it was, we split it and trim whitespace off each entry (to allow folks to put spaces around commas)
- Finally, iff that list has more than one thing and we're on a high enough version of Android, we use the fallback font creation code. If we're on an older version of Android, we just ignore the fallbacks and proceed wit the original logic.
fontFamily
private boolean getIsReduceMotionEnabledValue() { | ||
float defaultAnimationScale = Float.parseFloat(Settings.Global.TRANSITION_ANIMATION_SCALE); | ||
float animationScale = Settings.Global.getFloat(mContentResolver, defaultAnimationScale); | ||
return animationScale == 0f; | ||
String value = | ||
Settings.Global.getString(mContentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE); | ||
|
||
return value != null && value.equals("0.0"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are unrelated to the PR but they're necessary to get RN to compile locally
This is some pre-work to improving how non-latin scripts render. On the web, one can declare fallback fonts easily:
And that'll attempt to use those fonts, in that order, falling back to the next font whenever a character can't be rendered by the given font.
React Native doesn't support this, and issues asking for support have been closed as stale by a bot. This adds some sliiiightly jank code to support it. I originally wanted to do something like this:
But I settled for this to minimize the diff size compared to upstream:
The native code now just splits
fontFamily
names by commas and uses that to construct fallback-filled UIFont/Typeface instances.