-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Add Android support for fontVariant prop #27006
Add Android support for fontVariant prop #27006
Conversation
Android Lollipop and above support the Paint.setFontFeatureSettings() method, so use that to support the fontVariant TextView prop.
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.
Looks good to me, just some minor comments to improve nullability annotations.
@@ -38,6 +43,36 @@ public static int parseFontStyle(@Nullable String fontStyleString) { | |||
return fontStyle; | |||
} | |||
|
|||
public static String parseFontVariant(ReadableArray fontVariantArray) { |
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.
@Nullable String
and @Nullable ReadableArray
@@ -483,6 +491,16 @@ public void setFontWeight(@Nullable String fontWeightString) { | |||
} | |||
} | |||
|
|||
@ReactProp(name = ViewProps.FONT_VARIANT) | |||
public void setFontVariant(ReadableArray fontVariantArray) { |
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.
@Nullable ReadableArray
public void setFontVariant(ReadableArray fontVariantArray) { | ||
String fontFeatureSettings = ReactTypefaceUtils.parseFontVariant(fontVariantArray); | ||
|
||
if (!Objects.equals(fontFeatureSettings, mFontFeatureSettings)) { |
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.
I'm not familiar with Object.equals
, does it compare all values for an array?
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.
This isn't comparing the ReadableArray
, but the String
returned from ReactTypefaceUtils.parseFontVariant()
call with this.mFontFeatureSettings
.
TBH, I stumbled upon this via a Stackoverflow post when looking for a shorter way to write this check so it was new to me as well ;)
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.
I might be wrong here, but looks like java.util.Objects
and it's static methods was introduced in API level 19 (https://developer.android.com/reference/java/util/Objects). So I think it can possibly crash on Android 4 devices with NoClassDefFoundError: java.util.Objects
, when Object.equals
is called. We're investigating the similar crash in react-native-camera here: react-native-camera/react-native-camera#2528.
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.
I can replace this with https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/java/util/Objects.java#L57 if required
@@ -155,6 +162,14 @@ private float getFloatProp(String name, float defaultvalue) { | |||
} | |||
} | |||
|
|||
private ReadableArray getArrayProp(String name) { |
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.
@Nullable ReadableArray
@@ -280,6 +295,10 @@ public void setFontFamily(@Nullable String fontFamily) { | |||
mFontFamily = fontFamily; | |||
} | |||
|
|||
public void setFontVariant(ReadableArray fontVariant) { |
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.
@Nullable ReadableArray
private final @Nullable String mFontFamily; | ||
|
||
public CustomStyleSpan( | ||
int fontStyle, | ||
int fontWeight, | ||
String fontFeatureSettings, |
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.
@Nullable String
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.
@mdvacca has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
Thanks for working on this @mcuelenaere!
The code looks good to me, I'm landing it!
As a follow up, can you help updating the documentation? https://facebook.github.io/react-native/docs/text-style-props#fontvariant
Thank you!
This pull request was successfully merged by @mcuelenaere in c2c4b43. When will my fix make it into a release? | Upcoming Releases |
fontVariant support for Android was added with facebook/react-native#27006
|
…< 26 Summary: This diff fixes a crash when using TextInput.FontVariant prop in Android API level < 26 Changelog: Fix TextInput.FontVariant prop in Android API level < 26 (related to PR #27006) Reviewed By: JoshuaGross Differential Revision: D18331807 fbshipit-source-id: 5eac4d9e38eb099fae1287d128f3f8c249b0b8bc
…< 26 Summary: This diff fixes a crash when using TextInput.FontVariant prop in Android API level < 26 Changelog: Fix TextInput.FontVariant prop in Android API level < 26 (related to PR facebook#27006) Reviewed By: JoshuaGross Differential Revision: D18331807 fbshipit-source-id: 5eac4d9e38eb099fae1287d128f3f8c249b0b8bc
fontVariant support for Android was added with facebook/react-native#27006
…< 26 Summary: This diff fixes a crash when using TextInput.FontVariant prop in Android API level < 26 Changelog: Fix TextInput.FontVariant prop in Android API level < 26 (related to PR facebook#27006) Reviewed By: JoshuaGross Differential Revision: D18331807 fbshipit-source-id: 5eac4d9e38eb099fae1287d128f3f8c249b0b8bc
…< 26 Summary: This diff fixes a crash when using TextInput.FontVariant prop in Android API level < 26 Changelog: Fix TextInput.FontVariant prop in Android API level < 26 (related to PR facebook#27006) Reviewed By: JoshuaGross Differential Revision: D18331807 fbshipit-source-id: 5eac4d9e38eb099fae1287d128f3f8c249b0b8bc
…< 26 Summary: This diff fixes a crash when using TextInput.FontVariant prop in Android API level < 26 Changelog: Fix TextInput.FontVariant prop in Android API level < 26 (related to PR facebook#27006) Reviewed By: JoshuaGross Differential Revision: D18331807 fbshipit-source-id: 5eac4d9e38eb099fae1287d128f3f8c249b0b8bc
fontVariant support for Android was added with facebook/react-native#27006
fontVariant support for Android was added with facebook/react-native#27006
Summary
Android was missing support for the
fontVariant
prop in TextViews, this PR adds that.Changelog
[Android] [Added] - Add Android support for fontVariant prop
Test Plan
Since I can't get RNTester to work locally (it crashes when loading
libyoga.so
onNo implementation found for long com.facebook.yoga.YogaNative.jni_YGConfigNew()
), I'll post some screenshots below of our app showing the difference.We are using a slightly different version of this commit, since we're still on 0.60, but the gist remains the same when rebased on master.
Before:
After: