mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-21 07:45:38 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14e8908d0a |
@@ -40,7 +40,7 @@
|
||||
"dev:ios": "npm --prefix ../.. run build:client && cross-env APP_VARIANT=development expo run:ios",
|
||||
"build:apk": "npm --prefix ../.. run build:apk",
|
||||
"build:apk:arm64": "npm --prefix ../.. run build:apk:arm64",
|
||||
"test:android": "expo prebuild --platform android --no-install && cd android && ./gradlew :paseo-native-trace:testReleaseUnitTest :paseo-hardware-keyboard:testReleaseUnitTest :react-native-enriched-markdown:testReleaseUnitTest --tests '*InlineCodeFormattingTest' --no-daemon --max-workers=2 -Dorg.gradle.parallel=false"
|
||||
"test:android": "expo prebuild --platform android --no-install && cd android && ./gradlew :paseo-native-trace:testReleaseUnitTest :paseo-hardware-keyboard:testReleaseUnitTest :react-native-enriched-markdown:testReleaseUnitTest --tests '*InlineCodeFormattingTest' --tests '*ListBlockquoteMeasurementTest' --no-daemon --max-workers=2 -Dorg.gradle.parallel=false"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/commands": "6.10.4",
|
||||
|
||||
@@ -350,10 +350,18 @@ index b849f78..24c06f3 100644
|
||||
factory: RendererFactory,
|
||||
) {
|
||||
diff --git a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListRenderer.kt b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListRenderer.kt
|
||||
index 2bac5b1..ff2d2c2 100644
|
||||
index 2bac5b1..021debd 100644
|
||||
--- a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListRenderer.kt
|
||||
+++ b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListRenderer.kt
|
||||
@@ -16,7 +16,7 @@ class ListRenderer(
|
||||
@@ -6,6 +6,7 @@ import com.swmansion.enriched.markdown.spans.ListItemSpacingSpan
|
||||
import com.swmansion.enriched.markdown.spans.MarginBottomSpan
|
||||
import com.swmansion.enriched.markdown.styles.ListStyle
|
||||
import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
||||
+import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_LINE_HEIGHT_PRIORITY
|
||||
import com.swmansion.enriched.markdown.utils.text.span.applyLineHeightSkippingImages
|
||||
import com.swmansion.enriched.markdown.utils.text.span.applyMarginTop
|
||||
|
||||
@@ -16,7 +17,7 @@ class ListRenderer(
|
||||
override fun render(
|
||||
node: MarkdownASTNode,
|
||||
builder: SpannableStringBuilder,
|
||||
@@ -362,6 +370,23 @@ index 2bac5b1..ff2d2c2 100644
|
||||
onLinkLongPress: ((String) -> Unit)?,
|
||||
factory: RendererFactory,
|
||||
) {
|
||||
@@ -68,7 +69,15 @@ class ListRenderer(
|
||||
// TODO: LineHeightSpan may also clip superscript/subscript glyphs that extend
|
||||
// outside the normal line bounds. A similar "skip" strategy as for images may
|
||||
// be needed here once super/subscript usage in practice is better understood.
|
||||
- applyLineHeightSkippingImages(builder, start, builder.length, style.lineHeight)
|
||||
+ // Priority flag so the list-wide line height iterates before inner block spacer
|
||||
+ // spans (blockquote padding/margin, heading margin) instead of inflating them.
|
||||
+ applyLineHeightSkippingImages(
|
||||
+ builder,
|
||||
+ start,
|
||||
+ builder.length,
|
||||
+ style.lineHeight,
|
||||
+ SPAN_FLAGS_LINE_HEIGHT_PRIORITY,
|
||||
+ )
|
||||
|
||||
// Item spacing and external bottom margin are only handled by the root-level list
|
||||
if (depth == 0) {
|
||||
diff --git a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt
|
||||
index 354b31a..77b1e14 100644
|
||||
--- a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt
|
||||
@@ -3006,10 +3031,18 @@ index 0000000..11911c8
|
||||
+ }
|
||||
+}
|
||||
diff --git a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt
|
||||
index f4840e4..e36b444 100644
|
||||
index f4840e4..6b7e61f 100644
|
||||
--- a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt
|
||||
+++ b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt
|
||||
@@ -66,9 +66,11 @@ object MeasurementStore {
|
||||
@@ -45,6 +45,7 @@ import com.swmansion.enriched.markdown.utils.common.parseLinkPillContent
|
||||
import com.swmansion.enriched.markdown.utils.common.parseLinkRecognition
|
||||
import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWithPlaceholders
|
||||
import com.swmansion.enriched.markdown.utils.text.span.prepareWidthAwareSpans
|
||||
+import com.swmansion.enriched.markdown.utils.text.view.wrapForInsertionOrderedLayout
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.math.ceil
|
||||
|
||||
@@ -66,9 +67,11 @@ object MeasurementStore {
|
||||
val spannable: CharSequence?,
|
||||
val paintParams: PaintParams,
|
||||
val markdownHash: Int,
|
||||
@@ -3021,7 +3054,7 @@ index f4840e4..e36b444 100644
|
||||
|
||||
// Store font scaling settings per view ID
|
||||
private data class FontScalingSettings(
|
||||
@@ -133,7 +135,10 @@ object MeasurementStore {
|
||||
@@ -133,7 +136,10 @@ object MeasurementStore {
|
||||
YogaMeasureOutput.getHeight(newSize) + PixelUtil.toDIPFromPixel(trailingMarginBottomPx),
|
||||
)
|
||||
}
|
||||
@@ -3033,7 +3066,7 @@ index f4840e4..e36b444 100644
|
||||
return oldSize != newSize
|
||||
}
|
||||
|
||||
@@ -144,7 +149,7 @@ object MeasurementStore {
|
||||
@@ -144,7 +150,7 @@ object MeasurementStore {
|
||||
}
|
||||
|
||||
fun invalidate(id: Int) {
|
||||
@@ -3042,7 +3075,7 @@ index f4840e4..e36b444 100644
|
||||
}
|
||||
|
||||
// Content-box width (px) the measure pass last wrapped at; the display view insets to match (#805).
|
||||
@@ -212,7 +217,7 @@ object MeasurementStore {
|
||||
@@ -212,7 +218,7 @@ object MeasurementStore {
|
||||
val previous = fontScalingSettings[viewId]
|
||||
fontScalingSettings[viewId] = FontScalingSettings(allowFontScaling, maxFontSizeMultiplier)
|
||||
if (previous != null && (previous.allowFontScaling != allowFontScaling || previous.maxFontSizeMultiplier != maxFontSizeMultiplier)) {
|
||||
@@ -3051,7 +3084,7 @@ index f4840e4..e36b444 100644
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +290,43 @@ object MeasurementStore {
|
||||
@@ -285,7 +291,43 @@ object MeasurementStore {
|
||||
|
||||
val fontScale = checkAndUpdateFontScale(context, allowFontScaling, maxFontSizeMultiplier)
|
||||
|
||||
@@ -3096,7 +3129,7 @@ index f4840e4..e36b444 100644
|
||||
if (splitTableSegments) {
|
||||
return measureAndCacheSplit(context, id, width, props, allowFontScaling, fontScale, maxFontSizeMultiplier)
|
||||
}
|
||||
@@ -295,7 +336,7 @@ object MeasurementStore {
|
||||
@@ -295,7 +337,7 @@ object MeasurementStore {
|
||||
|
||||
val currentHash = computePropsHash(props, allowFontScaling, fontScale, maxFontSizeMultiplier)
|
||||
|
||||
@@ -3105,7 +3138,7 @@ index f4840e4..e36b444 100644
|
||||
return measureAndCache(context, safeId, width, props, allowFontScaling, fontScale, maxFontSizeMultiplier)
|
||||
}
|
||||
|
||||
@@ -332,8 +373,11 @@ object MeasurementStore {
|
||||
@@ -332,8 +374,11 @@ object MeasurementStore {
|
||||
val imageRequestHeaders = parseImageRequestHeaders(props.getArrayOrNull("imageRequestHeaders"))
|
||||
val linkPillContent = parseLinkPillContent(props.getArrayOrNull("linkPillContent"))
|
||||
var result = markdown.hashCode()
|
||||
@@ -3119,7 +3152,7 @@ index f4840e4..e36b444 100644
|
||||
result = 31 * result + parseLinkRecognition(props.getMapOrNull("linkRecognition")).hashCode()
|
||||
result = 31 * result + fontScale.toBits()
|
||||
result = 31 * result + allowFontScaling.hashCode()
|
||||
@@ -356,6 +400,7 @@ object MeasurementStore {
|
||||
@@ -356,6 +401,7 @@ object MeasurementStore {
|
||||
if (lastKnownFontScale != 1.0f) {
|
||||
lastKnownFontScale = 1.0f
|
||||
data.clear()
|
||||
@@ -3127,7 +3160,7 @@ index f4840e4..e36b444 100644
|
||||
}
|
||||
return 1.0f
|
||||
}
|
||||
@@ -368,6 +413,7 @@ object MeasurementStore {
|
||||
@@ -368,6 +414,7 @@ object MeasurementStore {
|
||||
if (currentFontScale != lastKnownFontScale) {
|
||||
lastKnownFontScale = currentFontScale
|
||||
data.clear()
|
||||
@@ -3135,6 +3168,52 @@ index f4840e4..e36b444 100644
|
||||
}
|
||||
return currentFontScale
|
||||
}
|
||||
@@ -635,7 +682,7 @@ object MeasurementStore {
|
||||
}
|
||||
}
|
||||
|
||||
- private fun createStaticLayout(
|
||||
+ internal fun createStaticLayout(
|
||||
text: CharSequence,
|
||||
fontSize: Float,
|
||||
widthPx: Int,
|
||||
@@ -643,8 +690,9 @@ object MeasurementStore {
|
||||
): StaticLayout {
|
||||
measurePaint.textSize = fontSize
|
||||
prepareWidthAwareSpans(text, widthPx)
|
||||
+ val measuredText = wrapForInsertionOrderedLayout(text)
|
||||
return StaticLayout.Builder
|
||||
- .obtain(text, 0, text.length, measurePaint, widthPx)
|
||||
+ .obtain(measuredText, 0, measuredText.length, measurePaint, widthPx)
|
||||
.setIncludePad(false)
|
||||
.setLineSpacing(0f, 1f)
|
||||
.apply {
|
||||
@@ -730,10 +778,11 @@ object MeasurementStore {
|
||||
val content = text ?: ""
|
||||
val safeWidth = ceil(maxWidth).toInt().coerceAtLeast(1)
|
||||
prepareWidthAwareSpans(content, safeWidth)
|
||||
+ val measuredText = wrapForInsertionOrderedLayout(content)
|
||||
|
||||
val builder =
|
||||
StaticLayout.Builder
|
||||
- .obtain(content, 0, content.length, paint, safeWidth)
|
||||
+ .obtain(measuredText, 0, measuredText.length, paint, safeWidth)
|
||||
.setIncludePad(false)
|
||||
.setLineSpacing(0f, 1f)
|
||||
|
||||
@@ -836,10 +885,11 @@ object MeasurementStore {
|
||||
val content = text ?: ""
|
||||
val widthPx = ceil(maxWidth).toInt().coerceAtLeast(1)
|
||||
prepareWidthAwareSpans(content, widthPx)
|
||||
+ val measuredText = wrapForInsertionOrderedLayout(content)
|
||||
|
||||
val layout =
|
||||
StaticLayout.Builder
|
||||
- .obtain(content, 0, content.length, paint, widthPx)
|
||||
+ .obtain(measuredText, 0, measuredText.length, paint, widthPx)
|
||||
.setIncludePad(false)
|
||||
.setLineSpacing(0f, 1f)
|
||||
.apply {
|
||||
diff --git a/node_modules/react-native-enriched-markdown/android/src/test/java/com/swmansion/enriched/markdown/MeasurementSizeCacheTest.kt b/node_modules/react-native-enriched-markdown/android/src/test/java/com/swmansion/enriched/markdown/MeasurementSizeCacheTest.kt
|
||||
new file mode 100644
|
||||
index 0000000..b3394c4
|
||||
@@ -3996,3 +4075,290 @@ diff --git a/node_modules/react-native-enriched-markdown/lib/module/web/utils.js
|
||||
+}
|
||||
//# sourceMappingURL=utils.js.map
|
||||
\ No newline at end of file
|
||||
diff --git a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt
|
||||
index 4b2ad01..8742c0c 100644
|
||||
--- a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt
|
||||
+++ b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt
|
||||
@@ -11,6 +11,9 @@ import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.view.ViewCompat
|
||||
import com.swmansion.enriched.markdown.accessibility.AccessibleMarkdownTextView
|
||||
|
||||
+internal fun wrapForInsertionOrderedLayout(source: CharSequence): CharSequence =
|
||||
+ if (source is SpannableStringBuilder) InsertionOrderedSpannable(source) else source
|
||||
+
|
||||
/**
|
||||
* Adopts the renderer's buffer instead of copying it: the default factory's copy is
|
||||
* quadratic in span count. Safe because each segment's buffer is owned by one view.
|
||||
diff --git a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt
|
||||
index 162ebfb..6e40bd8 100644
|
||||
--- a/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt
|
||||
+++ b/node_modules/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt
|
||||
@@ -9,6 +9,7 @@ import android.text.TextPaint
|
||||
import com.swmansion.enriched.markdown.styles.StyleConfig
|
||||
import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWithPlaceholders
|
||||
import com.swmansion.enriched.markdown.utils.text.span.prepareWidthAwareSpans
|
||||
+import com.swmansion.enriched.markdown.utils.text.view.wrapForInsertionOrderedLayout
|
||||
import kotlin.math.ceil
|
||||
|
||||
/**
|
||||
@@ -105,8 +106,9 @@ object SegmentHeightMeasurer {
|
||||
textSize = fontSizePx
|
||||
}
|
||||
prepareWidthAwareSpans(text, widthPx)
|
||||
+ val measuredText = wrapForInsertionOrderedLayout(text)
|
||||
return StaticLayout.Builder
|
||||
- .obtain(text, 0, text.length, paint, widthPx)
|
||||
+ .obtain(measuredText, 0, measuredText.length, paint, widthPx)
|
||||
.setIncludePad(false)
|
||||
.setLineSpacing(0f, 1f)
|
||||
.apply {
|
||||
diff --git a/b/node_modules/react-native-enriched-markdown/android/src/test/java/com/swmansion/enriched/markdown/ListBlockquoteMeasurementTest.kt b/node_modules/react-native-enriched-markdown/android/src/test/java/com/swmansion/enriched/markdown/ListBlockquoteMeasurementTest.kt
|
||||
new file mode 100644
|
||||
index 0000000..6115a30
|
||||
--- /dev/null
|
||||
+++ b/node_modules/react-native-enriched-markdown/android/src/test/java/com/swmansion/enriched/markdown/ListBlockquoteMeasurementTest.kt
|
||||
@@ -0,0 +1,244 @@
|
||||
+package com.swmansion.enriched.markdown
|
||||
+
|
||||
+import android.graphics.Paint
|
||||
+import android.text.Layout
|
||||
+import android.text.SpannableStringBuilder
|
||||
+import android.text.style.LineHeightSpan as AndroidLineHeightSpan
|
||||
+import android.util.TypedValue
|
||||
+import android.view.View.MeasureSpec
|
||||
+import com.facebook.react.bridge.JavaOnlyArray
|
||||
+import com.facebook.react.bridge.JavaOnlyMap
|
||||
+import com.facebook.react.uimanager.DisplayMetricsHolder
|
||||
+import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
||||
+import com.swmansion.enriched.markdown.parser.MarkdownASTNode.NodeType
|
||||
+import com.swmansion.enriched.markdown.renderer.Renderer
|
||||
+import com.swmansion.enriched.markdown.segments.SegmentHeightMeasurer
|
||||
+import com.swmansion.enriched.markdown.spans.LineHeightSpan
|
||||
+import com.swmansion.enriched.markdown.styles.StyleConfig
|
||||
+import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
||||
+import org.junit.Assert.assertEquals
|
||||
+import org.junit.Test
|
||||
+import org.junit.runner.RunWith
|
||||
+import org.robolectric.RobolectricTestRunner
|
||||
+import org.robolectric.RuntimeEnvironment
|
||||
+import org.robolectric.annotation.Config
|
||||
+import org.robolectric.annotation.GraphicsMode
|
||||
+
|
||||
+@RunWith(RobolectricTestRunner::class)
|
||||
+@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
+@Config(manifest = Config.NONE, sdk = [34])
|
||||
+class ListBlockquoteMeasurementTest {
|
||||
+ private fun styleConfig(): StyleConfig {
|
||||
+ val context = RuntimeEnvironment.getApplication()
|
||||
+ DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(context)
|
||||
+ val base =
|
||||
+ JavaOnlyMap.of(
|
||||
+ "fontFamily", "",
|
||||
+ "fontWeight", "normal",
|
||||
+ "fontStyle", "normal",
|
||||
+ "fontSize", 16.0,
|
||||
+ "lineHeight", 22.0,
|
||||
+ "color", -16777216.0,
|
||||
+ "backgroundColor", 0.0,
|
||||
+ "borderColor", 0.0,
|
||||
+ "borderWidth", 3.0,
|
||||
+ "borderRadius", 0.0,
|
||||
+ "padding", 12.0,
|
||||
+ "gapWidth", 8.0,
|
||||
+ "marginTop", 0.0,
|
||||
+ "marginBottom", 12.0,
|
||||
+ "marginLeft", 20.0,
|
||||
+ "itemSpacing", 4.0,
|
||||
+ "bulletColor", -16777216.0,
|
||||
+ "bulletSize", 6.0,
|
||||
+ "markerMinWidth", 0.0,
|
||||
+ "markerColor", -16777216.0,
|
||||
+ "markerFontWeight", "normal",
|
||||
+ "textAlign", "left",
|
||||
+ "underline", false,
|
||||
+ "checkedColor", 0.0,
|
||||
+ "checkmarkColor", 0.0,
|
||||
+ "checkedTextColor", 0.0,
|
||||
+ "checkboxSize", 18.0,
|
||||
+ "checkboxBorderRadius", 2.0,
|
||||
+ "checkedStrikethrough", false,
|
||||
+ "particles", JavaOnlyMap.of("density", 1.0, "speed", 1.0),
|
||||
+ "solid", JavaOnlyMap.of("borderRadius", 0.0),
|
||||
+ "fontScale", 0.7,
|
||||
+ "baselineOffsetScale", 0.3,
|
||||
+ )
|
||||
+ val styles = JavaOnlyMap()
|
||||
+ listOf(
|
||||
+ "paragraph",
|
||||
+ "h1",
|
||||
+ "h2",
|
||||
+ "h3",
|
||||
+ "h4",
|
||||
+ "h5",
|
||||
+ "h6",
|
||||
+ "strong",
|
||||
+ "em",
|
||||
+ "strikethrough",
|
||||
+ "underline",
|
||||
+ "link",
|
||||
+ "code",
|
||||
+ "blockquote",
|
||||
+ "list",
|
||||
+ "codeBlock",
|
||||
+ "thematicBreak",
|
||||
+ "image",
|
||||
+ "inlineImage",
|
||||
+ "video",
|
||||
+ "table",
|
||||
+ "taskList",
|
||||
+ "math",
|
||||
+ "inlineMath",
|
||||
+ "spoiler",
|
||||
+ "superscript",
|
||||
+ "subscript",
|
||||
+ "highlight",
|
||||
+ ).forEach { styles.putMap(it, base) }
|
||||
+ styles.putArray("linkVariants", JavaOnlyArray())
|
||||
+ return StyleConfig(styles, context, allowFontScaling = false, maxFontSizeMultiplier = 1f)
|
||||
+ }
|
||||
+
|
||||
+ private fun measureTextView(
|
||||
+ text: CharSequence,
|
||||
+ fontSizePx: Float,
|
||||
+ widthPx: Int,
|
||||
+ ): EnrichedMarkdownInternalText {
|
||||
+ val context = RuntimeEnvironment.getApplication()
|
||||
+ return EnrichedMarkdownInternalText(context).apply {
|
||||
+ setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSizePx)
|
||||
+ breakStrategy = Layout.BREAK_STRATEGY_HIGH_QUALITY
|
||||
+ applyStyledText(text)
|
||||
+ measure(
|
||||
+ MeasureSpec.makeMeasureSpec(widthPx, MeasureSpec.EXACTLY),
|
||||
+ MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
||||
+ )
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ @Test
|
||||
+ fun listNestedBlockquotesMatchMeasurementAndKeepSpacerHeights() {
|
||||
+ val context = RuntimeEnvironment.getApplication()
|
||||
+ val style = styleConfig()
|
||||
+ val widthPx = 640
|
||||
+ val fontSizePx = style.paragraphStyle.fontSize
|
||||
+
|
||||
+ val ast =
|
||||
+ MarkdownASTNode(
|
||||
+ NodeType.Document,
|
||||
+ children =
|
||||
+ listOf(
|
||||
+ MarkdownASTNode(
|
||||
+ NodeType.OrderedList,
|
||||
+ attributes = mapOf("start" to "1"),
|
||||
+ children =
|
||||
+ listOf(
|
||||
+ MarkdownASTNode(
|
||||
+ NodeType.ListItem,
|
||||
+ children =
|
||||
+ listOf(
|
||||
+ MarkdownASTNode(NodeType.Paragraph, children = listOf(MarkdownASTNode(NodeType.Text, "First item"))),
|
||||
+ MarkdownASTNode(
|
||||
+ NodeType.Blockquote,
|
||||
+ children =
|
||||
+ listOf(
|
||||
+ MarkdownASTNode(NodeType.Paragraph, children = listOf(MarkdownASTNode(NodeType.Text, "First quote"))),
|
||||
+ ),
|
||||
+ ),
|
||||
+ ),
|
||||
+ ),
|
||||
+ MarkdownASTNode(
|
||||
+ NodeType.ListItem,
|
||||
+ children =
|
||||
+ listOf(
|
||||
+ MarkdownASTNode(NodeType.Paragraph, children = listOf(MarkdownASTNode(NodeType.Text, "Second item"))),
|
||||
+ MarkdownASTNode(
|
||||
+ NodeType.Blockquote,
|
||||
+ children =
|
||||
+ listOf(
|
||||
+ MarkdownASTNode(NodeType.Paragraph, children = listOf(MarkdownASTNode(NodeType.Text, "Second quote"))),
|
||||
+ ),
|
||||
+ ),
|
||||
+ ),
|
||||
+ ),
|
||||
+ ),
|
||||
+ ),
|
||||
+ MarkdownASTNode(NodeType.Paragraph, children = listOf(MarkdownASTNode(NodeType.Text, "Trailing paragraph"))),
|
||||
+ ),
|
||||
+ )
|
||||
+
|
||||
+ val renderer = Renderer().apply { configure(style, context) }
|
||||
+ val rendered = renderer.renderDocument(ast)
|
||||
+
|
||||
+ val storeLayout = MeasurementStore.createStaticLayout(rendered, fontSizePx, widthPx, null)
|
||||
+ val segmentLayout =
|
||||
+ SegmentHeightMeasurer.createStaticLayout(rendered, fontSizePx, widthPx, Layout.BREAK_STRATEGY_HIGH_QUALITY)
|
||||
+ val textView = measureTextView(rendered, fontSizePx, widthPx)
|
||||
+
|
||||
+ assertEquals("MeasurementStore and TextView must agree on height", textView.measuredHeight, storeLayout.height)
|
||||
+ assertEquals("SegmentHeightMeasurer and TextView must agree on height", textView.measuredHeight, segmentLayout.height)
|
||||
+
|
||||
+ // Verify blockquote top-padding and bottom-margin spacer lines keep their configured
|
||||
+ // heights instead of being inflated to list.lineHeight (22dp).
|
||||
+ val paddingPx = style.blockquoteStyle.padding.toInt()
|
||||
+ val marginBottomPx = style.blockquoteStyle.marginBottom.toInt()
|
||||
+ val itemSpacingPx = style.listStyle.itemSpacing.toInt()
|
||||
+ val spacerLineHeights =
|
||||
+ (0 until storeLayout.lineCount)
|
||||
+ .filter { line ->
|
||||
+ val start = storeLayout.getLineStart(line)
|
||||
+ val end = storeLayout.getLineEnd(line)
|
||||
+ end - start == 1 && rendered[start] == '\n'
|
||||
+ }.map { line -> storeLayout.getLineBottom(line) - storeLayout.getLineTop(line) }
|
||||
+
|
||||
+ assertEquals(
|
||||
+ listOf(paddingPx, marginBottomPx + itemSpacingPx, paddingPx, marginBottomPx, marginBottomPx),
|
||||
+ spacerLineHeights,
|
||||
+ )
|
||||
+ }
|
||||
+
|
||||
+ @Test
|
||||
+ fun measurementStaticLayoutUsesInsertionOrderLikeTextView() {
|
||||
+ val context = RuntimeEnvironment.getApplication()
|
||||
+ DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(context)
|
||||
+ val widthPx = 400
|
||||
+ val fontSizePx = 16f
|
||||
+
|
||||
+ // Inner priority-0 spacer inserted before outer priority-0 LineHeightSpan:
|
||||
+ // SpannableStringBuilder's unsorted fast path orders by start offset (outer first),
|
||||
+ // while InsertionOrderedSpannable orders by insertion order (inner first, so outer inflates it).
|
||||
+ val builder = SpannableStringBuilder("first\n\nsecond")
|
||||
+ builder.setSpan(
|
||||
+ object : AndroidLineHeightSpan {
|
||||
+ override fun chooseHeight(
|
||||
+ text: CharSequence,
|
||||
+ start: Int,
|
||||
+ end: Int,
|
||||
+ spanstartv: Int,
|
||||
+ v: Int,
|
||||
+ fm: Paint.FontMetricsInt,
|
||||
+ ) {
|
||||
+ fm.top = 0
|
||||
+ fm.ascent = 0
|
||||
+ fm.descent = 12
|
||||
+ fm.bottom = 12
|
||||
+ }
|
||||
+ },
|
||||
+ 6,
|
||||
+ 7,
|
||||
+ SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
||||
+ )
|
||||
+ builder.setSpan(LineHeightSpan(40f), 0, builder.length, SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE)
|
||||
+
|
||||
+ val storeLayout = MeasurementStore.createStaticLayout(builder, fontSizePx, widthPx, null)
|
||||
+ val segmentLayout =
|
||||
+ SegmentHeightMeasurer.createStaticLayout(builder, fontSizePx, widthPx, Layout.BREAK_STRATEGY_HIGH_QUALITY)
|
||||
+ val textView = measureTextView(builder, fontSizePx, widthPx)
|
||||
+
|
||||
+ assertEquals(textView.measuredHeight, storeLayout.height)
|
||||
+ assertEquals(textView.measuredHeight, segmentLayout.height)
|
||||
+ }
|
||||
+}
|
||||
|
||||
Reference in New Issue
Block a user