Skip to content

Commit f23fece

Browse files
Almourofacebook-github-bot
authored andcommitted
Fix font variant crash on Android < 4.4 (#29176)
Summary: In RN 0.62 support for `fontVariant` was added on Android. Using that prop crashes the app on Android below KitKat (4.3 and below) To reproduce just add any Text with the `fontVariant` styling prop in the app: ```js <Text style={{fontVariant: ['tabular-nums']}}>This will crash</Text> ``` It will crash any device running Android below KitKat with the error: ![image](https://user-images.githubusercontent.com/4534323/85073452-18206b80-b1bb-11ea-8d7e-96f27fa1a320.png) This is caused by `java.utils.Objects` only being available on Android 4.4+ ## Changelog [Android] [Fixed] - Fix font variant crash on Android < 4.4 Pull Request resolved: #29176 Test Plan: [TextUtils.equals](https://developer.android.com/reference/android/text/TextUtils#equals) was added as soon as API level 1, so no compatibility issue here. Tested on Emulator running Android 4.1, no crash anymore. I've searched for other occurences of `java.utils.Objects` in the project, and this was the only one, so no need to remove other occurences ✅ Reviewed By: JoshuaGross Differential Revision: D22337316 Pulled By: mdvacca fbshipit-source-id: 5507b21b237a725d596d47b5c01e269895b16d4a
1 parent 8320ad3 commit f23fece

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.text.Layout;
1515
import android.text.Spannable;
1616
import android.text.SpannableStringBuilder;
17+
import android.text.TextUtils;
1718
import android.view.Gravity;
1819
import androidx.annotation.Nullable;
1920
import com.facebook.infer.annotation.Assertions;
@@ -34,7 +35,6 @@
3435
import java.util.HashMap;
3536
import java.util.List;
3637
import java.util.Map;
37-
import java.util.Objects;
3838

3939
/**
4040
* {@link ReactShadowNode} abstract class for spannable text nodes.
@@ -512,7 +512,7 @@ public void setFontWeight(@Nullable String fontWeightString) {
512512
public void setFontVariant(@Nullable ReadableArray fontVariantArray) {
513513
String fontFeatureSettings = ReactTypefaceUtils.parseFontVariant(fontVariantArray);
514514

515-
if (!Objects.equals(fontFeatureSettings, mFontFeatureSettings)) {
515+
if (!TextUtils.equals(fontFeatureSettings, mFontFeatureSettings)) {
516516
mFontFeatureSettings = fontFeatureSettings;
517517
markUpdated();
518518
}

0 commit comments

Comments
 (0)