Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.facebook.react.common.ReactConstants
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.uimanager.ReactAccessibilityDelegate
import com.facebook.react.views.text.fragments.TextFragmentList
import com.facebook.react.views.text.fragments.TextFragment

/** Utility methods for building [Spannable]s */
internal object TextLayoutUtils {
Expand All @@ -27,26 +28,53 @@ internal object TextLayoutUtils {
sb: SpannableStringBuilder,
ops: MutableList<SetSpanOperation>,
) {

for (i in 0 until textFragmentList.count) {
val fragment = textFragmentList.getFragment(i)
val start = sb.length

// ReactRawText
val textAttributes = fragment.textAttributeProps

addText(sb, fragment.string, textAttributes)

val end = sb.length
val reactTag = if (fragment.hasReactTag()) fragment.reactTag else View.NO_ID
if (fragment.hasIsAttachment() && fragment.isAttachment) {
val width = PixelUtil.toPixelFromSP(fragment.width)
val height = PixelUtil.toPixelFromSP(fragment.height)
addApplicableFragmentSpans(
context = context,
fragment = fragment,
sb = sb,
ops = ops,
)
}
}

addInlineViewPlaceholderSpan(ops, sb, reactTag, width, height)
} else if (end >= start) {
addApplicableTextAttributeSpans(ops, textAttributes, reactTag, context, start, end)
}
private fun addApplicableFragmentSpans(
context: Context,
fragment: TextFragment,
sb: SpannableStringBuilder,
ops: MutableList<SetSpanOperation>,
) {
val start = sb.length

// ReactRawText
val textAttributes = fragment.textAttributeProps

addText(sb, fragment.string, textAttributes)

val end = sb.length
val reactTag = if (fragment.hasReactTag()) fragment.reactTag else View.NO_ID
if (fragment.hasIsAttachment() && fragment.isAttachment) {
val width = PixelUtil.toPixelFromSP(fragment.width)
val height = PixelUtil.toPixelFromSP(fragment.height)

addInlineViewPlaceholderSpan(
ops = ops,
sb = sb,
reactTag = reactTag,
width = width,
height = height,
)
} else if (end >= start) {
addApplicableTextAttributeSpans(
ops = ops,
textAttributeProvider = textAttributes,
reactTag = reactTag,
context = context,
start = start,
end = end,
)
}
}

Expand Down Expand Up @@ -83,27 +111,82 @@ internal object TextLayoutUtils {
start: Int,
end: Int
) {
addColorSpanIfApplicable(ops, textAttributeProvider, start, end)

addBackgroundColorSpanIfApplicable(ops, textAttributeProvider, start, end)

addLinkSpanIfApplicable(ops, textAttributeProvider, reactTag, start, end)

addLetterSpacingSpanIfApplicable(ops, textAttributeProvider, start, end)

addFontSizeSpanIfApplicable(ops, textAttributeProvider, start, end)

addCustomStyleSpanIfApplicable(ops, textAttributeProvider, context, start, end)

addUnderlineSpanIfApplicable(ops, textAttributeProvider, start, end)

addStrikethroughSpanIfApplicable(ops, textAttributeProvider, start, end)

addShadowStyleSpanIfApplicable(ops, textAttributeProvider, start, end)

addLineHeightSpanIfApplicable(ops, textAttributeProvider, start, end)

addReactTagSpan(ops, start, end, reactTag)
addColorSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addBackgroundColorSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addLinkSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider, reactTag,
start = start,
end = end,
)

addLetterSpacingSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addFontSizeSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addCustomStyleSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider, context,
start = start,
end = end,
)

addUnderlineSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addStrikethroughSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addShadowStyleSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addLineHeightSpanIfApplicable(
ops = ops,
textAttributeProvider = textAttributeProvider,
start = start,
end = end,
)

addReactTagSpan(
ops = ops,
start = start,
end = end,
reactTag = reactTag,
)
}

@JvmStatic
Expand Down