From 6bc69668802f7b7ce31af47c684068a9bbbab09c Mon Sep 17 00:00:00 2001 From: Jakub Trzebiatowski Date: Wed, 1 Nov 2023 10:38:24 +0100 Subject: [PATCH] Use the `UNSET` constant more consistently --- .../com/facebook/react/common/assets/ReactFontManager.java | 3 ++- .../internal/views/text/EffectiveTextAttributeProvider.kt | 6 +----- .../internal/views/text/HierarchicTextAttributeProvider.kt | 3 ++- .../facebook/react/internal/views/text/TextLayoutUtils.kt | 3 +-- .../com/facebook/react/views/text/CustomStyleSpan.java | 6 ++++-- .../facebook/react/views/text/ReactBaseTextShadowNode.java | 5 +++-- .../com/facebook/react/views/text/ReactTextShadowNode.java | 2 ++ .../com/facebook/react/views/text/ReactTypefaceUtils.java | 7 +++++-- .../react/views/textinput/ReactTextInputShadowNode.java | 2 ++ 9 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.java index 7e7df01bd140ff..30438a3600a6e8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.java @@ -7,6 +7,8 @@ package com.facebook.react.common.assets; +import static com.facebook.react.views.text.TextAttributeProps.UNSET; + import android.content.Context; import android.content.res.AssetManager; import android.graphics.Typeface; @@ -167,7 +169,6 @@ public static class TypefaceStyle { public static final int BOLD = 700; public static final int NORMAL = 400; - public static final int UNSET = -1; private static final int MIN_WEIGHT = 1; private static final int MAX_WEIGHT = 1000; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt index bc95997bd4dcf5..ef2148772e84b9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt @@ -1,16 +1,12 @@ package com.facebook.react.internal.views.text -import com.facebook.react.common.assets.ReactFontManager +import com.facebook.react.views.text.TextAttributeProps.UNSET import com.facebook.react.views.text.TextTransform /** * Interface for an entity providing effective text attributes of a text node/fragment */ interface EffectiveTextAttributeProvider : BasicTextAttributeProvider { - companion object { - const val UNSET = ReactFontManager.TypefaceStyle.UNSET - } - val textTransform: TextTransform val effectiveLetterSpacing: Float diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt index 1076c6e1049845..2753637c454659 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt @@ -1,6 +1,7 @@ package com.facebook.react.internal.views.text import com.facebook.react.views.text.ReactBaseTextShadowNode +import com.facebook.react.views.text.TextAttributeProps.UNSET import com.facebook.react.views.text.TextAttributes import com.facebook.react.views.text.TextTransform @@ -37,7 +38,7 @@ class HierarchicTextAttributeProvider( return if (parentTextAttributes == null || parentTextAttributes.effectiveFontSize != fontSize) { fontSize } else { - EffectiveTextAttributeProvider.UNSET + UNSET } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/TextLayoutUtils.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/TextLayoutUtils.kt index 6859fee7b42a16..0a296f7cc0824a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/TextLayoutUtils.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/TextLayoutUtils.kt @@ -11,18 +11,17 @@ import android.content.Context import android.graphics.Color import android.text.* import android.view.View -import com.facebook.react.common.assets.ReactFontManager import com.facebook.react.uimanager.PixelUtil import com.facebook.react.uimanager.ReactAccessibilityDelegate import com.facebook.react.internal.views.text.fragments.TextFragmentList import com.facebook.react.views.text.* +import com.facebook.react.views.text.TextAttributeProps.UNSET /** * Utility methods for building [Spannable]s */ object TextLayoutUtils { private const val INLINE_VIEW_PLACEHOLDER = "0" - private const val UNSET = ReactFontManager.TypefaceStyle.UNSET fun buildSpannableFromTextFragmentList( context: Context, diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java index 51fd4dd0149c77..fd5250b099a6c3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java @@ -7,6 +7,8 @@ package com.facebook.react.views.text; +import static com.facebook.react.views.text.TextAttributeProps.UNSET; + import android.content.res.AssetManager; import android.graphics.Paint; import android.graphics.Typeface; @@ -61,11 +63,11 @@ public void updateMeasureState(TextPaint paint) { } public int getStyle() { - return mStyle == ReactFontManager.TypefaceStyle.UNSET ? Typeface.NORMAL : mStyle; + return mStyle == UNSET ? Typeface.NORMAL : mStyle; } public int getWeight() { - return mWeight == ReactFontManager.TypefaceStyle.UNSET + return mWeight == UNSET ? ReactFontManager.TypefaceStyle.NORMAL : mWeight; } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java index 3ed806a450a2b9..b2328d6a23a3e2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java @@ -7,6 +7,9 @@ package com.facebook.react.views.text; + +import static com.facebook.react.views.text.TextAttributeProps.UNSET; + import android.graphics.Color; import android.graphics.Typeface; import android.os.Build; @@ -21,7 +24,6 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.common.ReactConstants; -import com.facebook.react.common.assets.ReactFontManager; import com.facebook.react.internal.views.text.BasicTextAttributeProvider; import com.facebook.react.internal.views.text.HierarchicTextAttributeProvider; import com.facebook.react.internal.views.text.TextLayoutUtils; @@ -59,7 +61,6 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode implement // character. // https://en.wikipedia.org/wiki/Bi-directional_text#weak_characters private static final String INLINE_VIEW_PLACEHOLDER = "0"; - public static final int UNSET = ReactFontManager.TypefaceStyle.UNSET; public static final String PROP_SHADOW_OFFSET = "textShadowOffset"; public static final String PROP_SHADOW_OFFSET_WIDTH = "width"; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index d53f18a5aa3289..9bb2de7747ef6c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -7,6 +7,8 @@ package com.facebook.react.views.text; +import static com.facebook.react.views.text.TextAttributeProps.UNSET; + import android.os.Build; import android.text.BoringLayout; import android.text.Layout; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java index 64fe5e36c0eb0d..41ccd8bbbfe39a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java @@ -7,6 +7,8 @@ package com.facebook.react.views.text; +import static com.facebook.react.views.text.TextAttributeProps.UNSET; + import android.content.res.AssetManager; import android.graphics.Typeface; import android.text.TextUtils; @@ -14,6 +16,7 @@ import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.common.assets.ReactFontManager; + import java.util.ArrayList; import java.util.List; @@ -45,7 +48,7 @@ public static int parseFontWeight(@Nullable String fontWeightString) { return 900; } } - return ReactFontManager.TypefaceStyle.UNSET; + return UNSET; } public static int parseFontStyle(@Nullable String fontStyleString) { @@ -57,7 +60,7 @@ public static int parseFontStyle(@Nullable String fontStyleString) { return Typeface.NORMAL; } } - return ReactFontManager.TypefaceStyle.UNSET; + return UNSET; } public static @Nullable String parseFontVariant(@Nullable ReadableArray fontVariantArray) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java index 878da5199174ca..ca4b260a56f828 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java @@ -7,6 +7,8 @@ package com.facebook.react.views.textinput; +import static com.facebook.react.views.text.TextAttributeProps.UNSET; + import android.text.Layout; import android.util.TypedValue; import android.view.ViewGroup;