Skip to content
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

Conversation

mcuelenaere
Copy link
Contributor

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 on No 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:
Screenshot_20191025-130325__01

After:
Screenshot_20191025-130444__01

Android Lollipop and above support the Paint.setFontFeatureSettings() method, so use that to support the fontVariant TextView prop.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 25, 2019
@react-native-bot react-native-bot added Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature. labels Oct 25, 2019
Copy link
Contributor

@janicduplessis janicduplessis left a 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) {
Copy link
Contributor

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) {
Copy link
Contributor

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)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

https://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#equals(java.lang.Object,%20java.lang.Object)

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 ;)

Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -155,6 +162,14 @@ private float getFloatProp(String name, float defaultvalue) {
}
}

private ReadableArray getArrayProp(String name) {
Copy link
Contributor

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) {
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

@Nullable String

@janicduplessis
Copy link
Contributor

Cc @mdvacca @JoshuaGross

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@mdvacca mdvacca left a 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!

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @mcuelenaere in c2c4b43.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Oct 29, 2019
mcuelenaere added a commit to mcuelenaere/react-native-website that referenced this pull request Oct 29, 2019
@mcuelenaere
Copy link
Contributor Author

As a follow up, can you help updating the documentation? https://facebook.github.io/react-native/docs/text-style-props#fontvariant
Thank you!

facebook/react-native-website#1443

facebook-github-bot pushed a commit that referenced this pull request Nov 5, 2019
…< 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
mcuelenaere pushed a commit to getdelta/react-native that referenced this pull request Nov 18, 2019
…< 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
rachelnabors pushed a commit to facebook/react-native-website that referenced this pull request Nov 18, 2019
svenlombaert pushed a commit to getdelta/react-native that referenced this pull request Jan 7, 2020
…< 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
svenlombaert pushed a commit to getdelta/react-native that referenced this pull request Jan 7, 2020
…< 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
svenlombaert pushed a commit to getdelta/react-native that referenced this pull request Jan 7, 2020
…< 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
espipj pushed a commit to espipj/react-native-website that referenced this pull request Feb 8, 2020
JackWillie added a commit to JackWillie/react-native-website that referenced this pull request Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants