Skip to content

Commit

Permalink
HierarchicTextAttributeProvider: Delegate most properties to the no…
Browse files Browse the repository at this point in the history
…de itself
  • Loading branch information
cubuspl42 committed Oct 14, 2023
1 parent 8b95108 commit 6cceac3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +52,7 @@
* <p>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;

Expand Down Expand Up @@ -391,6 +392,7 @@ public void setFontSize(float fontSize) {
markUpdated();
}

@Override
public int getColor() {
return mColor;
}
Expand All @@ -404,10 +406,12 @@ public void setColor(@Nullable Integer color) {
markUpdated();
}

@Override
public boolean isColorSet() {
return mIsColorSet;
}

@Override
public int getBackgroundColor() {
return mBackgroundColor;
}
Expand All @@ -427,10 +431,12 @@ public void setBackgroundColor(@Nullable Integer color) {
}
}

@Override
public boolean isBackgroundColorSet() {
return mIsBackgroundColorSet;
}

@Override
public @Nullable AccessibilityRole getAccessibilityRole() {
return mAccessibilityRole;
}
Expand All @@ -443,6 +449,7 @@ public void setAccessibilityRole(@Nullable String accessibilityRole) {
}
}

@Override
public @Nullable Role getRole() {
return mRole;
}
Expand All @@ -455,6 +462,7 @@ public void setRole(@Nullable String role) {
}
}

@Override
public String getFontFamily() {
return mFontFamily;
}
Expand All @@ -465,6 +473,7 @@ public void setFontFamily(@Nullable String fontFamily) {
markUpdated();
}

@Override
public int getFontWeight() {
return mFontWeight;
}
Expand All @@ -488,10 +497,12 @@ public void setFontVariant(@Nullable ReadableArray fontVariantArray) {
}
}

@Override
public String getFontFeatureSettings() {
return mFontFeatureSettings;
}

@Override
public int getFontStyle() {
return mFontStyle;
}
Expand Down Expand Up @@ -526,10 +537,12 @@ public void setTextDecorationLine(@Nullable String textDecorationLineString) {
markUpdated();
}

@Override
public boolean isUnderlineTextDecorationSet() {
return mIsUnderlineTextDecorationSet;
}

@Override
public boolean isLineThroughTextDecorationSet() {
return mIsLineThroughTextDecorationSet;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -591,6 +607,7 @@ public void setTextShadowRadius(float textShadowRadius) {
}
}

@Override
public int getTextShadowColor() {
return mTextShadowColor;
}
Expand Down

0 comments on commit 6cceac3

Please sign in to comment.