mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:

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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8320ad37f2
commit
f23feced42
+2
-2
@@ -14,6 +14,7 @@ import android.os.Build;
|
||||
import android.text.Layout;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
@@ -34,7 +35,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* {@link ReactShadowNode} abstract class for spannable text nodes.
|
||||
@@ -512,7 +512,7 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
|
||||
public void setFontVariant(@Nullable ReadableArray fontVariantArray) {
|
||||
String fontFeatureSettings = ReactTypefaceUtils.parseFontVariant(fontVariantArray);
|
||||
|
||||
if (!Objects.equals(fontFeatureSettings, mFontFeatureSettings)) {
|
||||
if (!TextUtils.equals(fontFeatureSettings, mFontFeatureSettings)) {
|
||||
mFontFeatureSettings = fontFeatureSettings;
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user