Skip to content

Commit

Permalink
Extract a shared FontConstants.UNSET constant
Browse files Browse the repository at this point in the history
  • Loading branch information
cubuspl42 committed Nov 1, 2023
1 parent 4f59241 commit 109d0be
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.facebook.react.internal.fonts

object FontConstants {
/**
* A special value indicating that a font-related property is not set
*/
const val UNSET: Int = -1
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package com.facebook.react.internal.views.text

import com.facebook.react.common.assets.ReactFontManager
import com.facebook.react.internal.fonts.FontConstants
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

/**
* @return The effective font size, or [UNSET] if not set
* @return The effective font size, or [FontConstants.UNSET] if not set
*/
val effectiveFontSize: Int

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.facebook.react.internal.views.text

import com.facebook.react.internal.fonts.FontConstants
import com.facebook.react.views.text.ReactBaseTextShadowNode
import com.facebook.react.views.text.TextAttributes
import com.facebook.react.views.text.TextTransform
Expand Down Expand Up @@ -37,7 +38,7 @@ class HierarchicTextAttributeProvider(
return if (parentTextAttributes == null || parentTextAttributes.effectiveFontSize != fontSize) {
fontSize
} else {
EffectiveTextAttributeProvider.UNSET
FontConstants.UNSET
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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.internal.fonts.FontConstants.UNSET
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.uimanager.ReactAccessibilityDelegate
import com.facebook.react.internal.views.text.fragments.TextFragmentList
Expand All @@ -22,7 +22,6 @@ import com.facebook.react.views.text.*
*/
object TextLayoutUtils {
private const val INLINE_VIEW_PLACEHOLDER = "0"
private const val UNSET = ReactFontManager.TypefaceStyle.UNSET

fun buildSpannableFromTextFragmentList(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.common.assets.ReactFontManager;
import com.facebook.react.internal.fonts.FontConstants;

@Nullsafe(Nullsafe.Mode.LOCAL)
public class CustomStyleSpan extends MetricAffectingSpan implements ReactSpan {
Expand Down Expand Up @@ -61,11 +62,11 @@ public void updateMeasureState(TextPaint paint) {
}

public int getStyle() {
return mStyle == ReactFontManager.TypefaceStyle.UNSET ? Typeface.NORMAL : mStyle;
return mStyle == FontConstants.UNSET ? Typeface.NORMAL : mStyle;
}

public int getWeight() {
return mWeight == ReactFontManager.TypefaceStyle.UNSET
return mWeight == FontConstants.UNSET
? ReactFontManager.TypefaceStyle.NORMAL
: mWeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.facebook.react.views.text;

import static com.facebook.react.internal.fonts.FontConstants.UNSET;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.assets.ReactFontManager;
import com.facebook.react.internal.fonts.FontConstants;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -45,7 +47,7 @@ public static int parseFontWeight(@Nullable String fontWeightString) {
return 900;
}
}
return ReactFontManager.TypefaceStyle.UNSET;
return FontConstants.UNSET;
}

public static int parseFontStyle(@Nullable String fontStyleString) {
Expand All @@ -57,7 +59,7 @@ public static int parseFontStyle(@Nullable String fontStyleString) {
return Typeface.NORMAL;
}
}
return ReactFontManager.TypefaceStyle.UNSET;
return FontConstants.UNSET;
}

public static @Nullable String parseFontVariant(@Nullable ReadableArray fontVariantArray) {
Expand Down

0 comments on commit 109d0be

Please sign in to comment.