Skip to content
Merged
Show file tree
Hide file tree
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
appId: swmansion.enriched.markdown.example
tags:
- block
- advanced
- list
- task_list
- text
- android-only
---
- launchApp:
permissions: {}

- waitForAnimationToEnd

- runFlow:
file: '../../../../subflows/move_to_playground.yaml'

- assertVisible:
id: playground-screen

- runFlow:
file: '../../../subflows/set_enriched_text_value.yaml'
env:
VALUE: |
1. Ordered parent
- Bullet child
- Second bullet child
2. Following ordered sibling

- Bullet parent
1. Ordered child
2. Second ordered child
- Following bullet sibling

- scrollUntilVisible:
element:
id: blur-button
direction: UP
visibilityPercentage: 100

- tapOn:
id: blur-button

- scroll

- waitForAnimationToEnd

- runFlow:
file: '../../../subflows/capture_or_assert_screenshot.yaml'
env:
SCREENSHOT_NAME: 'mixed_nested_list_markers_bullet_ordered_display'

- scrollUntilVisible:
element:
id: set-markdown-button
direction: UP
visibilityPercentage: 100

- runFlow:
file: '../../../subflows/set_enriched_text_value.yaml'
env:
VALUE: |
- Bullet parent
- [ ] Unchecked task child
- [x] Checked task child

1. Ordered parent
- [ ] Unchecked task child
- [x] Checked task child

- [ ] Unchecked task parent
- Bullet child
- [x] Checked task parent
- Second bullet child

- scrollUntilVisible:
element:
id: blur-button
direction: UP
visibilityPercentage: 100

- tapOn:
id: blur-button

- scroll

- waitForAnimationToEnd

- runFlow:
file: '../../../subflows/capture_or_assert_screenshot.yaml'
env:
SCREENSHOT_NAME: 'mixed_nested_list_markers_tasks_display'
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ tags:
1. Django
2. FastAPI

- runFlow:
when:
platform: Android
commands:
- scroll
- waitForAnimationToEnd

- runFlow:
file: '../../../subflows/capture_or_assert_screenshot.yaml'
env:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BlockStyleContext {
var listMarkerExtra = 0f
var ancestorMarkerOffset = 0f
var listItemMarkerExtra = 0f
var listItemMarkerWidth: Float? = null
var taskItemCount = 0

private val orderedListItemNumbers = ArrayDeque<Int>()
Expand Down Expand Up @@ -155,6 +156,7 @@ class BlockStyleContext {
listMarkerExtra = 0f
ancestorMarkerOffset = 0f
listItemMarkerExtra = 0f
listItemMarkerWidth = null
taskItemCount = 0
orderedListItemNumbers.clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ListItemRenderer(
isChecked = isChecked,
ancestorMarkerOffset = styleContext.ancestorMarkerOffset,
markerExtraWidth = styleContext.listMarkerExtra,
parentMarkerWidth = styleContext.listItemMarkerWidth,
)
} else {
when (listType) {
Expand All @@ -61,6 +62,7 @@ class ListItemRenderer(
factory.context,
factory.styleCache,
ancestorMarkerOffset = styleContext.ancestorMarkerOffset,
parentMarkerWidth = styleContext.listItemMarkerWidth,
)
}

Expand All @@ -72,20 +74,24 @@ class ListItemRenderer(
factory.styleCache,
markerExtraWidth = styleContext.listMarkerExtra,
ancestorMarkerOffset = styleContext.ancestorMarkerOffset,
parentMarkerWidth = styleContext.listItemMarkerWidth,
).apply {
setItemNumber(styleContext.listItemNumber)
}
}
}
}

// Nested lists inside this item shift by its extra marker width.
// Nested lists inside this item shift by its extra marker width and measure their indent from its column.
val previousMarkerExtra = styleContext.listItemMarkerExtra
styleContext.listItemMarkerExtra = span.markerExtraWidth
val previousMarkerWidth = styleContext.listItemMarkerWidth
styleContext.listItemMarkerWidth = span.baselineMarkerWidth
try {
factory.renderChildren(node, builder, onLinkPress, onLinkLongPress)
} finally {
styleContext.listItemMarkerExtra = previousMarkerExtra
styleContext.listItemMarkerWidth = previousMarkerWidth
}

if (builder.length == start || builder.substring(start).isBlank()) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract class BaseListSpan(
protected val marginLeft: Float,
protected val gapWidth: Float,
internal val ancestorMarkerOffset: Float = 0f,
internal val parentMarkerWidth: Float? = null,
) : MetricAffectingSpan(),
LeadingMarginSpan {
private var cachedText: CharSequence? = null
Expand All @@ -41,17 +42,25 @@ abstract class BaseListSpan(
/** How far an ordered list widened this item's column past the one short lists reserve. */
internal open val markerExtraWidth: Float = 0f

/** This item's marker column without [markerExtraWidth]; a nested item measures its indent against it. */
internal open val baselineMarkerWidth: Float get() = getMarkerWidth()

override fun updateMeasureState(textPaint: TextPaint) = applyTextStyle(textPaint)

override fun updateDrawState(textPaint: TextPaint) = applyTextStyle(textPaint)

override fun getLeadingMargin(first: Boolean): Int =
if (depth == 0) {
val effectiveGap = gapWidth.coerceAtLeast(DEFAULT_MIN_GAP)
(getMarkerWidth() + effectiveGap).toInt()
} else {
(marginLeft + markerExtraWidth).toInt()
}
override fun getLeadingMargin(first: Boolean): Int {
val effectiveGap = gapWidth.coerceAtLeast(DEFAULT_MIN_GAP)
if (depth == 0) return (getMarkerWidth() + effectiveGap).toInt()

// Subtract truncated absolute indents, each measured from its own item's column, so neither mixed
// columns nor fractional margins accumulate rounding. The widenings are whole pixels and add unchanged.
val markerWidth = baselineMarkerWidth
val parentWidth = parentMarkerWidth ?: markerWidth
val indent = (depth * marginLeft + markerWidth + effectiveGap).toInt()
val parentIndent = ((depth - 1) * marginLeft + parentWidth + effectiveGap).toInt()
return indent - parentIndent + markerExtraWidth.toInt()
}

override fun drawLeadingMargin(
canvas: Canvas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class OrderedListSpan(
styleCache: SpanStyleCache,
override val markerExtraWidth: Float = 0f,
ancestorMarkerOffset: Float = 0f,
parentMarkerWidth: Float? = null,
) : BaseListSpan(
depth = depth,
context = context,
Expand All @@ -33,6 +34,7 @@ class OrderedListSpan(
marginLeft = listStyle.marginLeft,
gapWidth = listStyle.gapWidth,
ancestorMarkerOffset = ancestorMarkerOffset,
parentMarkerWidth = parentMarkerWidth,
) {
companion object {
private val sharedMarkerPaint = TextPaint().apply { isAntiAlias = true }
Expand Down Expand Up @@ -78,6 +80,8 @@ class OrderedListSpan(

override fun getMarkerWidth(): Float = defaultMarkerWidth + markerExtraWidth

override val baselineMarkerWidth: Float get() = defaultMarkerWidth

var itemNumber: Int = 1
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TaskListSpan(
var isChecked: Boolean,
ancestorMarkerOffset: Float = 0f,
override val markerExtraWidth: Float = 0f,
parentMarkerWidth: Float? = null,
) : BaseListSpan(
depth = depth,
context = context,
Expand All @@ -42,6 +43,7 @@ class TaskListSpan(
marginLeft = listStyle.marginLeft,
gapWidth = listStyle.gapWidth,
ancestorMarkerOffset = ancestorMarkerOffset,
parentMarkerWidth = parentMarkerWidth,
) {
companion object {
private val boxPaint =
Expand All @@ -61,14 +63,17 @@ class TaskListSpan(
}

private val checkboxSize = taskStyle.checkboxSize
private val markerColumnWidth = listStyle.effectiveMarkerWidth(checkboxSize) + markerExtraWidth
private val checkboxColumnWidth = listStyle.effectiveMarkerWidth(checkboxSize)
private val markerColumnWidth = checkboxColumnWidth + markerExtraWidth
private val cornerRadius = taskStyle.checkboxBorderRadius
private val rect = RectF()
private val insetRect = RectF()
private val checkPath = Path()

override fun getMarkerWidth(): Float = markerColumnWidth

override val baselineMarkerWidth: Float get() = checkboxColumnWidth

override fun drawMarker(
canvas: Canvas,
paint: Paint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class UnorderedListSpan(
context: Context,
styleCache: SpanStyleCache,
ancestorMarkerOffset: Float = 0f,
parentMarkerWidth: Float? = null,
) : BaseListSpan(
depth = depth,
context = context,
Expand All @@ -28,6 +29,7 @@ class UnorderedListSpan(
marginLeft = listStyle.marginLeft,
gapWidth = listStyle.gapWidth,
ancestorMarkerOffset = ancestorMarkerOffset,
parentMarkerWidth = parentMarkerWidth,
) {
companion object {
private val sharedBulletPaint =
Expand Down
Loading
Loading