mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
- Fix fontVariant stylistic sets being ignored in New Architecture (#55183)
Summary:
During an upgrade of ReactNative and switching to new arch, we noticed that Android is ignoring *some* fontVariants. Specifically `stylistic-{num}`. Digging further I noticed that there are `stylistic-{num}` mappings added to `fromRawValue` (in `packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h`), but are not included for `toMapBuffer`
## Changelog:
<!-- Help reviewers and the release process by writing your own changelog entry.
Pick one each for the category and type tags:
[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message
For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Android] [Fixed] - fontVariants `stylistic-{num}` not being propagated correctly
Pull Request resolved: https://github.com/facebook/react-native/pull/55183
Test Plan:
- Added a new free font (FiraCode) that has stylistic features.
- Added Text examples for Android showing with and without stylistic features
Before and after in order:
<img width="1080" height="2400" alt="Before" src="https://github.com/user-attachments/assets/3d21a992-f36a-4ffe-a1b2-8da40b3ee399" />
<img width="1080" height="2400" alt="After" src="https://github.com/user-attachments/assets/f4ee208a-3f98-42d9-b8c2-5b122d2db383" />
Reviewed By: cortinico
Differential Revision: D90830140
Pulled By: philIip
fbshipit-source-id: 42dbb98641274c0d4c01c501662b2ae59e21927d
This commit is contained in:
1 parent
97c9202400
commit
9353eb55b8
5 files changed
+75
No files matched your search
@@ -1076,6 +1076,66 @@ inline MapBuffer toMapBuffer(const FontVariant &fontVariant)
|
||||
if ((int)fontVariant & (int)FontVariant::ProportionalNums) {
|
||||
builder.putString(index++, "proportional-nums");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticOne) {
|
||||
builder.putString(index++, "stylistic-one");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticTwo) {
|
||||
builder.putString(index++, "stylistic-two");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticThree) {
|
||||
builder.putString(index++, "stylistic-three");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticFour) {
|
||||
builder.putString(index++, "stylistic-four");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticFive) {
|
||||
builder.putString(index++, "stylistic-five");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticSix) {
|
||||
builder.putString(index++, "stylistic-six");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticSeven) {
|
||||
builder.putString(index++, "stylistic-seven");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticEight) {
|
||||
builder.putString(index++, "stylistic-eight");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticNine) {
|
||||
builder.putString(index++, "stylistic-nine");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticTen) {
|
||||
builder.putString(index++, "stylistic-ten");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticEleven) {
|
||||
builder.putString(index++, "stylistic-eleven");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticTwelve) {
|
||||
builder.putString(index++, "stylistic-twelve");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticThirteen) {
|
||||
builder.putString(index++, "stylistic-thirteen");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticFourteen) {
|
||||
builder.putString(index++, "stylistic-fourteen");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticFifteen) {
|
||||
builder.putString(index++, "stylistic-fifteen");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticSixteen) {
|
||||
builder.putString(index++, "stylistic-sixteen");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticSeventeen) {
|
||||
builder.putString(index++, "stylistic-seventeen");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticEighteen) {
|
||||
builder.putString(index++, "stylistic-eighteen");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticNineteen) {
|
||||
builder.putString(index++, "stylistic-nineteen");
|
||||
}
|
||||
if ((int)fontVariant & (int)FontVariant::StylisticTwenty) {
|
||||
builder.putString(index++, "stylistic-twenty");
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
+1
@@ -119,6 +119,7 @@ internal class RNTesterApplication : Application(), ReactApplication {
|
||||
|
||||
override fun onCreate() {
|
||||
ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik)
|
||||
ReactFontManager.getInstance().addCustomFont(this, "FiraCode", R.font.firacode)
|
||||
super.onCreate()
|
||||
loadReactNative(this)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<font app:fontStyle="normal" app:fontWeight="400" app:font="@font/firacode_regular"/>
|
||||
</font-family>
|
||||
Binary file not shown.
@@ -389,6 +389,16 @@ function FontVariantsExample(props: {}): React.Node {
|
||||
1111{'\n'}
|
||||
2222{'\n'}
|
||||
</RNTesterText>
|
||||
<RNTesterText style={{fontFamily: 'FiraCode'}}>
|
||||
Non-Stylistic & and $
|
||||
</RNTesterText>
|
||||
<RNTesterText
|
||||
style={{
|
||||
fontFamily: 'FiraCode',
|
||||
fontVariant: ['stylistic-three', 'stylistic-four'],
|
||||
}}>
|
||||
Stylistic & and $
|
||||
</RNTesterText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user