diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/BasicTextAttributeProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/BasicTextAttributeProvider.kt new file mode 100644 index 00000000000000..969cb6b52dd5c2 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/BasicTextAttributeProvider.kt @@ -0,0 +1,41 @@ +package com.facebook.react.internal.views.text + +import com.facebook.react.uimanager.ReactAccessibilityDelegate + +/** + * Interface for an entity providing basic text attributes of a text node/fragment. "Basic" means + * that they can be provided trivially, without processing the parent element. + */ +interface BasicTextAttributeProvider { + val role: ReactAccessibilityDelegate.Role? + + val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole? + + val isBackgroundColorSet: Boolean + + val backgroundColor: Int + + val isColorSet: Boolean + + val color: Int + + val fontStyle: Int + + val fontWeight: Int + + val fontFamily: String? + + val fontFeatureSettings: String? + + val isUnderlineTextDecorationSet: Boolean + + val isLineThroughTextDecorationSet: Boolean + + val textShadowOffsetDx: Float + + val textShadowOffsetDy: Float + + val textShadowRadius: Float + + val textShadowColor: Int +} 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 f97bdd17ed4e73..c2d65f951e3467 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,14 +1,12 @@ package com.facebook.react.internal.views.text import com.facebook.react.common.assets.ReactFontManager -import com.facebook.react.uimanager.ReactAccessibilityDelegate -import com.facebook.react.uimanager.ReactAccessibilityDelegate.Role import com.facebook.react.views.text.TextTransform /** * Interface for an entity providing effective text attributes of a text node/fragment */ -interface EffectiveTextAttributeProvider { +interface EffectiveTextAttributeProvider : BasicTextAttributeProvider { companion object { const val UNSET = ReactFontManager.TypefaceStyle.UNSET } @@ -22,37 +20,5 @@ interface EffectiveTextAttributeProvider { */ val effectiveFontSize: Int - val role: Role? - - val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole? - - val isBackgroundColorSet: Boolean - - val backgroundColor: Int - - val isColorSet: Boolean - - val color: Int - - val fontStyle: Int - - val fontWeight: Int - - val fontFamily: String? - - val fontFeatureSettings: String? - - val isUnderlineTextDecorationSet: Boolean - - val isLineThroughTextDecorationSet: Boolean - - val textShadowOffsetDx: Float - - val textShadowOffsetDy: Float - - val textShadowRadius: Float - - val textShadowColor: Int - val effectiveLineHeight: 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 ab3c4836122b77..05fd371c7cd5e2 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,5 @@ package com.facebook.react.internal.views.text -import com.facebook.react.uimanager.ReactAccessibilityDelegate import com.facebook.react.views.text.ReactBaseTextShadowNode import com.facebook.react.views.text.TextAttributes import com.facebook.react.views.text.TextTransform @@ -13,58 +12,10 @@ class HierarchicTextAttributeProvider( private val textShadowNode: ReactBaseTextShadowNode, private val parentTextAttributes: TextAttributes?, private val textAttributes: TextAttributes -) : EffectiveTextAttributeProvider { +) : EffectiveTextAttributeProvider, BasicTextAttributeProvider by textShadowNode { override val textTransform: TextTransform get() = textAttributes.textTransform - override val role: ReactAccessibilityDelegate.Role? - get() = textShadowNode.role - - override val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole? - get() = textShadowNode.accessibilityRole - - override val isBackgroundColorSet: Boolean - get() = textShadowNode.isBackgroundColorSet - - override val backgroundColor: Int - get() = textShadowNode.backgroundColor - - override val isColorSet: Boolean - get() = textShadowNode.isColorSet - - override val color: Int - get() = textShadowNode.color - - override val fontStyle: Int - get() = textShadowNode.fontStyle - - override val fontWeight: Int - get() = textShadowNode.fontWeight - - override val fontFamily: String - get() = textShadowNode.fontFamily - - override val fontFeatureSettings: String - get() = textShadowNode.fontFeatureSettings - - override val isUnderlineTextDecorationSet: Boolean - get() = textShadowNode.isUnderlineTextDecorationSet - - override val isLineThroughTextDecorationSet: Boolean - get() = textShadowNode.isLineThroughTextDecorationSet - - override val textShadowOffsetDx: Float - get() = textShadowNode.textShadowOffsetDx - - override val textShadowOffsetDy: Float - get() = textShadowNode.textShadowOffsetDy - - override val textShadowRadius: Float - get() = textShadowNode.textShadowRadius - - override val textShadowColor: Int - get() = textShadowNode.textShadowColor - override val effectiveLetterSpacing: Float get() { val letterSpacing = textAttributes.effectiveLetterSpacing 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 97dcd39eb1a721..acf336577b2fc3 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 @@ -22,6 +22,7 @@ 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; import com.facebook.react.uimanager.IllegalViewOperationException; @@ -51,7 +52,7 @@ *
This also node calculates {@link Spannable} object based on subnodes of the same type, which * can be used in concrete classes to feed native views and compute layout. */ -public abstract class ReactBaseTextShadowNode extends LayoutShadowNode { +public abstract class ReactBaseTextShadowNode extends LayoutShadowNode implements BasicTextAttributeProvider { private static final TextLayoutUtils textLayoutUtils = TextLayoutUtils.INSTANCE; @@ -391,6 +392,7 @@ public void setFontSize(float fontSize) { markUpdated(); } + @Override public int getColor() { return mColor; } @@ -404,10 +406,12 @@ public void setColor(@Nullable Integer color) { markUpdated(); } + @Override public boolean isColorSet() { return mIsColorSet; } + @Override public int getBackgroundColor() { return mBackgroundColor; } @@ -427,10 +431,12 @@ public void setBackgroundColor(@Nullable Integer color) { } } + @Override public boolean isBackgroundColorSet() { return mIsBackgroundColorSet; } + @Override public @Nullable AccessibilityRole getAccessibilityRole() { return mAccessibilityRole; } @@ -443,6 +449,7 @@ public void setAccessibilityRole(@Nullable String accessibilityRole) { } } + @Override public @Nullable Role getRole() { return mRole; } @@ -455,6 +462,7 @@ public void setRole(@Nullable String role) { } } + @Override public String getFontFamily() { return mFontFamily; } @@ -465,6 +473,7 @@ public void setFontFamily(@Nullable String fontFamily) { markUpdated(); } + @Override public int getFontWeight() { return mFontWeight; } @@ -488,10 +497,12 @@ public void setFontVariant(@Nullable ReadableArray fontVariantArray) { } } + @Override public String getFontFeatureSettings() { return mFontFeatureSettings; } + @Override public int getFontStyle() { return mFontStyle; } @@ -526,10 +537,12 @@ public void setTextDecorationLine(@Nullable String textDecorationLineString) { markUpdated(); } + @Override public boolean isUnderlineTextDecorationSet() { return mIsUnderlineTextDecorationSet; } + @Override public boolean isLineThroughTextDecorationSet() { return mIsLineThroughTextDecorationSet; } @@ -571,14 +584,17 @@ public void setTextShadowOffset(ReadableMap offsetMap) { markUpdated(); } + @Override public float getTextShadowOffsetDx() { return mTextShadowOffsetDx; } + @Override public float getTextShadowOffsetDy() { return mTextShadowOffsetDy; } + @Override public float getTextShadowRadius() { return mTextShadowRadius; } @@ -591,6 +607,7 @@ public void setTextShadowRadius(float textShadowRadius) { } } + @Override public int getTextShadowColor() { return mTextShadowColor; }