@onekeyfe/react-native-native-list 6.7.0-alpha.466 → 6.8.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +312 -379
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +15 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +60 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +5 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +75 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +25 -19
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -0
- package/docs/ROW_TEMPLATES.md +11 -4
- package/docs/SPEC.md +296 -20
- package/docs/STYLE_SPEC.md +12 -0
- package/ios/NativeListActivityDetailsView.swift +13 -5
- package/ios/NativeListMediaPlaceholderView.swift +189 -0
- package/ios/NativeListMediaPreviewSlot.swift +122 -61
- package/ios/NativeListMediaTileRenderer.swift +13 -13
- package/ios/NativeListResolvedText.swift +15 -4
- package/ios/NativeListTextLabel.swift +106 -0
- package/ios/RNCNativeListView.swift +129 -32
- package/ios/tests/NativeListActivityPresentationTests.swift +270 -0
- package/ios/tests/NativeListLifecycleTests.swift +369 -40
- package/ios/tests/NativeListMediaVisibilityTests.swift +41 -7
- package/lib/module/NativeList.js +17 -4
- package/lib/module/NativeList.web.js +3 -1
- package/lib/module/validation.js +53 -4
- package/lib/module/web/NativeListGeneratedIcons.js +1 -0
- package/lib/module/web/NativeListWebEngine.js +13 -11
- package/lib/module/web/templates/ActivityRowRenderer.js +29 -23
- package/lib/module/web/templates/DataRowRenderer.js +54 -1
- package/lib/module/web/templates/IdentityRowRenderer.js +3 -1
- package/lib/module/web/templates/MediaTileRowRenderer.js +84 -15
- package/lib/typescript/src/models.d.ts +18 -1
- package/package.json +1 -1
- package/scripts/generate-icons.test.mjs +1 -0
- package/scripts/native-list-icons.json +1 -1
- package/src/NativeList.tsx +25 -4
- package/src/NativeList.web.tsx +1 -1
- package/src/models.ts +18 -0
- package/src/validation.ts +96 -1
- package/src/web/NativeListGeneratedIcons.ts +1 -0
- package/src/web/NativeListWebEngine.ts +16 -11
- package/src/web/templates/ActivityRowRenderer.ts +42 -32
- package/src/web/templates/DataRowRenderer.ts +76 -1
- package/src/web/templates/IdentityRowRenderer.ts +3 -3
- package/src/web/templates/MediaTileRowRenderer.ts +90 -15
|
@@ -3,9 +3,16 @@ package com.margelo.nitro.nativelist
|
|
|
3
3
|
import android.graphics.Canvas
|
|
4
4
|
import android.graphics.DashPathEffect
|
|
5
5
|
import android.graphics.Paint
|
|
6
|
+
import android.graphics.Path
|
|
7
|
+
import android.graphics.Rect
|
|
6
8
|
import android.graphics.RectF
|
|
9
|
+
import android.graphics.Region
|
|
10
|
+
import android.graphics.RegionIterator
|
|
11
|
+
import android.text.Layout
|
|
7
12
|
import android.view.MotionEvent
|
|
8
13
|
import android.widget.TextView
|
|
14
|
+
import kotlin.math.ceil
|
|
15
|
+
import kotlin.math.floor
|
|
9
16
|
|
|
10
17
|
internal open class NativeListTextView(context: android.content.Context) : TextView(context) {
|
|
11
18
|
var helpBindingGeneration = 0
|
|
@@ -33,9 +40,73 @@ internal open class NativeListTextView(context: android.content.Context) : TextV
|
|
|
33
40
|
)
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Character offset the touchable text starts at. `null` keeps the view's own
|
|
45
|
+
* hit testing, its whole bounds. With an offset only the drawn text from
|
|
46
|
+
* there on takes touches, plus a small horizontal slop, so text before the
|
|
47
|
+
* offset and the unused width of a stretched view fall through to the row
|
|
48
|
+
* behind it: `0` covers all of the text, the text length leaves nothing to
|
|
49
|
+
* touch.
|
|
50
|
+
*/
|
|
51
|
+
var touchableTextStart: Int? = null
|
|
52
|
+
|
|
53
|
+
val touchableTextRegions: List<NativeListTouchRegion>
|
|
54
|
+
get() {
|
|
55
|
+
val textStart = touchableTextStart ?: return emptyList()
|
|
56
|
+
val textLayout = layout ?: return emptyList()
|
|
57
|
+
// Lines past the line cap are laid out but never drawn.
|
|
58
|
+
val count = minOf(textLayout.lineCount, maxLines.takeIf { it > 0 } ?: Int.MAX_VALUE)
|
|
59
|
+
if (count == 0) return emptyList()
|
|
60
|
+
val originX = totalPaddingLeft.toFloat()
|
|
61
|
+
val originY = totalPaddingTop + opticalOffsetY
|
|
62
|
+
val lines = (0 until count).map { line ->
|
|
63
|
+
val lineStart = textLayout.getLineStart(line)
|
|
64
|
+
val lineEnd = textLayout.getLineEnd(line)
|
|
65
|
+
// An ellipsis hides the rest of its line. Once it hides the touchable
|
|
66
|
+
// text as well it also stands for plain text, so nothing is left to touch.
|
|
67
|
+
val visibleEnd =
|
|
68
|
+
if (textLayout.getEllipsisCount(line) > 0) lineStart + textLayout.getEllipsisStart(line) else lineEnd
|
|
69
|
+
val touchableStart = maxOf(textStart, lineStart)
|
|
70
|
+
NativeListTextLine(
|
|
71
|
+
// The outer lines also take the view's own vertical padding.
|
|
72
|
+
top = if (line == 0) 0f else originY + textLayout.getLineTop(line),
|
|
73
|
+
bottom = if (line == count - 1) height.toFloat() else originY + textLayout.getLineBottom(line),
|
|
74
|
+
touchable =
|
|
75
|
+
if (touchableStart < visibleEnd) textRuns(textLayout, line, touchableStart, lineEnd, originX)
|
|
76
|
+
else emptyList(),
|
|
77
|
+
plain = textRuns(textLayout, line, lineStart, minOf(textStart, lineEnd), originX),
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
return nativeListTouchableTextRegions(lines, TOUCH_SLOP_DP * resources.displayMetrics.density)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Horizontal extents the layout gives characters `[from, to)` of [line]: the
|
|
85
|
+
* layout's own selection, so mixed-direction text yields one run per
|
|
86
|
+
* direction run instead of one box around all of them.
|
|
87
|
+
*/
|
|
88
|
+
private fun textRuns(textLayout: Layout, line: Int, from: Int, to: Int, originX: Float): List<NativeListTextRun> {
|
|
89
|
+
if (from >= to) return emptyList()
|
|
90
|
+
val selection = Path()
|
|
91
|
+
textLayout.getSelectionPath(from, to, selection)
|
|
92
|
+
// A selection that reaches the line end also covers the blank up to the
|
|
93
|
+
// layout edge and starts the next line; only this line's text counts.
|
|
94
|
+
val lineBounds = Region(
|
|
95
|
+
floor(textLayout.getLineLeft(line)).toInt(), textLayout.getLineTop(line),
|
|
96
|
+
ceil(textLayout.getLineRight(line)).toInt(), textLayout.getLineBottom(line),
|
|
97
|
+
)
|
|
98
|
+
val runs = mutableListOf<NativeListTextRun>()
|
|
99
|
+
val iterator = RegionIterator(Region().apply { setPath(selection, lineBounds) })
|
|
100
|
+
val run = Rect()
|
|
101
|
+
while (iterator.next(run)) runs += NativeListTextRun(originX + run.left, originX + run.right)
|
|
102
|
+
return runs
|
|
103
|
+
}
|
|
104
|
+
|
|
36
105
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
|
37
106
|
if (primaryHelpOnly && event.actionMasked == MotionEvent.ACTION_DOWN &&
|
|
38
107
|
helpAnchorBounds?.contains(event.x, event.y) != true) return false
|
|
108
|
+
if (touchableTextStart != null && event.actionMasked == MotionEvent.ACTION_DOWN &&
|
|
109
|
+
touchableTextRegions.none { it.contains(event.x, event.y) }) return false
|
|
39
110
|
if (guardsHelpTouches) {
|
|
40
111
|
if (event.actionMasked == MotionEvent.ACTION_DOWN) helpDownGeneration = helpBindingGeneration
|
|
41
112
|
if (event.actionMasked == MotionEvent.ACTION_UP && helpDownGeneration != helpBindingGeneration) {
|
|
@@ -76,4 +147,8 @@ internal open class NativeListTextView(context: android.content.Context) : TextV
|
|
|
76
147
|
drawHelpUnderline(canvas)
|
|
77
148
|
canvas.restoreToCount(checkpoint)
|
|
78
149
|
}
|
|
150
|
+
|
|
151
|
+
private companion object {
|
|
152
|
+
const val TOUCH_SLOP_DP = 8f
|
|
153
|
+
}
|
|
79
154
|
}
|
|
@@ -1963,7 +1963,10 @@ class NativeListView(
|
|
|
1963
1963
|
private var footerView: NativeListRowHost = NativeListRendererRegistry.create(reactContext, NativeListRendererKey.ACTION.ordinal, fonts)
|
|
1964
1964
|
private var footerRendererKey = NativeListRendererKey.ACTION
|
|
1965
1965
|
private val sectionIndexView = NativeListSectionIndexView(context, fonts)
|
|
1966
|
-
|
|
1966
|
+
// RN touch targeting still visits invisible native children with retained bounds.
|
|
1967
|
+
private val sectionIndexPreview = object : TextView(context), ReactPointerEventsView {
|
|
1968
|
+
override val pointerEvents: PointerEvents = PointerEvents.NONE
|
|
1969
|
+
}
|
|
1967
1970
|
private var config: NativeListConfig? = null
|
|
1968
1971
|
private var usesSelectorSourceScale = false
|
|
1969
1972
|
private val stickyHeaderView = NativeListRendererRegistry.create(reactContext, NativeListRendererKey.SECTION_HEADER.ordinal, fonts)
|
|
@@ -2177,14 +2180,6 @@ class NativeListView(
|
|
|
2177
2180
|
stickyHeaderHost.visibility = GONE
|
|
2178
2181
|
stickyHeaderHost.addView(stickyHeaderView, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
|
2179
2182
|
contentContainer.addView(stickyHeaderHost, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP))
|
|
2180
|
-
contentContainer.addView(
|
|
2181
|
-
sectionIndexView,
|
|
2182
|
-
FrameLayout.LayoutParams(
|
|
2183
|
-
sectionIndexDp(SECTION_INDEX_RAIL_WIDTH_DP),
|
|
2184
|
-
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
2185
|
-
Gravity.END,
|
|
2186
|
-
),
|
|
2187
|
-
)
|
|
2188
2183
|
sectionIndexPreview.apply {
|
|
2189
2184
|
gravity = Gravity.CENTER
|
|
2190
2185
|
textSize = 30f
|
|
@@ -2194,16 +2189,13 @@ class NativeListView(
|
|
|
2194
2189
|
alpha = 0f
|
|
2195
2190
|
importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO
|
|
2196
2191
|
}
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
marginEnd = sectionIndexDp(SECTION_INDEX_PREVIEW_END_MARGIN_DP)
|
|
2205
|
-
},
|
|
2206
|
-
)
|
|
2192
|
+
sectionIndexPreview.layoutParams = FrameLayout.LayoutParams(
|
|
2193
|
+
sectionIndexDp(SECTION_INDEX_PREVIEW_WIDTH_DP),
|
|
2194
|
+
sectionIndexDp(SECTION_INDEX_PREVIEW_HEIGHT_DP),
|
|
2195
|
+
Gravity.CENTER_VERTICAL or Gravity.END,
|
|
2196
|
+
).apply {
|
|
2197
|
+
marginEnd = sectionIndexDp(SECTION_INDEX_PREVIEW_END_MARGIN_DP)
|
|
2198
|
+
}
|
|
2207
2199
|
addView(contentContainer, LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f))
|
|
2208
2200
|
footerView.visibility = GONE
|
|
2209
2201
|
addView(footerView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))
|
|
@@ -3704,6 +3696,18 @@ class NativeListView(
|
|
|
3704
3696
|
}
|
|
3705
3697
|
|
|
3706
3698
|
private fun updateSectionIndexAttachment() {
|
|
3699
|
+
if (sectionIndexEntries.isEmpty()) {
|
|
3700
|
+
stopSectionIndexAttachmentTracking()
|
|
3701
|
+
sectionIndexAttachmentHandler.removeCallbacks(sectionIndexListAttachmentRunnable)
|
|
3702
|
+
sectionIndexListAttachmentScheduled = false
|
|
3703
|
+
(sectionIndexView.parent as? ViewGroup)?.let { previous ->
|
|
3704
|
+
previous.removeView(sectionIndexView)
|
|
3705
|
+
previous.endViewTransition(sectionIndexView)
|
|
3706
|
+
}
|
|
3707
|
+
contentContainer.removeView(sectionIndexPreview)
|
|
3708
|
+
return
|
|
3709
|
+
}
|
|
3710
|
+
if (sectionIndexPreview.parent == null) contentContainer.addView(sectionIndexPreview)
|
|
3707
3711
|
val windowHost = rootView as? FrameLayout
|
|
3708
3712
|
val canUseWindowHost = config?.sectionIndexCenteredInWindow == true &&
|
|
3709
3713
|
sectionIndexEntries.isNotEmpty() &&
|
|
@@ -3757,6 +3761,7 @@ class NativeListView(
|
|
|
3757
3761
|
}
|
|
3758
3762
|
|
|
3759
3763
|
private fun scheduleSectionIndexAttachmentToList() {
|
|
3764
|
+
if (sectionIndexEntries.isEmpty()) return
|
|
3760
3765
|
if (sectionIndexView.parent === contentContainer) return
|
|
3761
3766
|
if (sectionIndexListAttachmentScheduled) return
|
|
3762
3767
|
sectionIndexListAttachmentScheduled = true
|
|
@@ -3764,6 +3769,7 @@ class NativeListView(
|
|
|
3764
3769
|
}
|
|
3765
3770
|
|
|
3766
3771
|
private fun attachSectionIndexToList() {
|
|
3772
|
+
if (sectionIndexEntries.isEmpty()) return
|
|
3767
3773
|
if (sectionIndexView.parent === contentContainer) return
|
|
3768
3774
|
(sectionIndexView.parent as? ViewGroup)?.let { previous ->
|
|
3769
3775
|
previous.removeView(sectionIndexView)
|
package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
package com.margelo.nitro.nativelist
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertTrue
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
class NativeListDescriptionTouchPolicyTest {
|
|
9
|
+
private fun hit(regions: List<NativeListTouchRegion>, x: Float, y: Float) = regions.any { it.contains(x, y) }
|
|
10
|
+
|
|
11
|
+
private fun run(left: Float, right: Float) = NativeListTextRun(left, right)
|
|
12
|
+
|
|
13
|
+
private fun regions(vararg lines: NativeListTextLine) = nativeListTouchableTextRegions(lines.toList(), slop = 8f)
|
|
14
|
+
|
|
15
|
+
// The description view spans the identity column, so a tap anywhere on its
|
|
16
|
+
// line used to open the description action. Only the text opens it now; the
|
|
17
|
+
// blank rest of the line belongs to the row press (OK-67219).
|
|
18
|
+
@Test
|
|
19
|
+
fun onlyTheDrawnTextTakesTouches() {
|
|
20
|
+
val text = regions(NativeListTextLine(top = 0f, bottom = 20f, touchable = listOf(run(0f, 60f))))
|
|
21
|
+
|
|
22
|
+
assertTrue(hit(text, 30f, 10f))
|
|
23
|
+
// The slop reaches into the blank on both sides of the text.
|
|
24
|
+
assertTrue(hit(text, 66f, 10f))
|
|
25
|
+
assertTrue(hit(text, -6f, 10f))
|
|
26
|
+
assertFalse(hit(text, 120f, 10f))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The caller states where the action text starts; the text before it, a
|
|
30
|
+
// time for one, is not part of the action.
|
|
31
|
+
@Test
|
|
32
|
+
fun textBeforeTheStartIsNotPartOfTheAction() {
|
|
33
|
+
val ltr = regions(
|
|
34
|
+
NativeListTextLine(top = 0f, bottom = 20f, touchable = listOf(run(50f, 160f)), plain = listOf(run(0f, 50f))),
|
|
35
|
+
)
|
|
36
|
+
assertFalse(hit(ltr, 20f, 10f))
|
|
37
|
+
assertTrue(hit(ltr, 100f, 10f))
|
|
38
|
+
|
|
39
|
+
// Right to left the plain text sits on the right of the touchable text.
|
|
40
|
+
val rtl = regions(
|
|
41
|
+
NativeListTextLine(top = 0f, bottom = 20f, touchable = listOf(run(40f, 150f)), plain = listOf(run(150f, 200f))),
|
|
42
|
+
)
|
|
43
|
+
assertTrue(hit(rtl, 100f, 10f))
|
|
44
|
+
assertFalse(hit(rtl, 180f, 10f))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The slop is for blank space. It must not reach into plain text beside the
|
|
48
|
+
// touchable text, or a prefix narrower than the slop, like the "i" of
|
|
49
|
+
// "iRouter", would open the action it is not part of.
|
|
50
|
+
@Test
|
|
51
|
+
fun theSlopStopsAtPlainTextBesideTheTouchableText() {
|
|
52
|
+
val short = regions(
|
|
53
|
+
NativeListTextLine(top = 0f, bottom = 20f, touchable = listOf(run(3f, 46f)), plain = listOf(run(0f, 3f))),
|
|
54
|
+
)
|
|
55
|
+
assertFalse(hit(short, 1.5f, 10f))
|
|
56
|
+
assertFalse(hit(short, -4f, 10f))
|
|
57
|
+
assertTrue(hit(short, 4f, 10f))
|
|
58
|
+
assertTrue(hit(short, 52f, 10f))
|
|
59
|
+
assertEquals(3f, short.single().left)
|
|
60
|
+
assertEquals(54f, short.single().right)
|
|
61
|
+
|
|
62
|
+
// Neighbouring runs read back from pixel regions may be a pixel apart.
|
|
63
|
+
val apart = regions(
|
|
64
|
+
NativeListTextLine(top = 0f, bottom = 20f, touchable = listOf(run(4f, 46f)), plain = listOf(run(0f, 3f))),
|
|
65
|
+
)
|
|
66
|
+
assertEquals(3f, apart.single().left)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Mixed-direction text can split one logical suffix into several visual
|
|
70
|
+
// runs with plain text between them: "ABC אבג XYZ" from the last Hebrew
|
|
71
|
+
// letter on draws that letter left of the two plain ones. Each run is its
|
|
72
|
+
// own region, and the plain text between them takes no touches.
|
|
73
|
+
@Test
|
|
74
|
+
fun aSuffixSplitByMixedDirectionTextIsSeveralRuns() {
|
|
75
|
+
val mixed = regions(
|
|
76
|
+
NativeListTextLine(
|
|
77
|
+
top = 0f, bottom = 20f,
|
|
78
|
+
touchable = listOf(run(32f, 38f), run(55f, 86f)),
|
|
79
|
+
plain = listOf(run(0f, 32f), run(38f, 55f)),
|
|
80
|
+
),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
assertEquals(2, mixed.size)
|
|
84
|
+
assertFalse(hit(mixed, 16f, 10f))
|
|
85
|
+
assertTrue(hit(mixed, 35f, 10f))
|
|
86
|
+
assertFalse(hit(mixed, 46f, 10f))
|
|
87
|
+
assertTrue(hit(mixed, 70f, 10f))
|
|
88
|
+
// Only the outer edge of the last run faces blank space.
|
|
89
|
+
assertTrue(hit(mixed, 92f, 10f))
|
|
90
|
+
assertEquals(32f, mixed[0].left)
|
|
91
|
+
assertEquals(38f, mixed[0].right)
|
|
92
|
+
assertEquals(55f, mixed[1].left)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A narrow row wraps the description. The time stays outside the action on
|
|
96
|
+
// its line, while the address is hit on both lines, also at the x the time
|
|
97
|
+
// occupies one line above.
|
|
98
|
+
@Test
|
|
99
|
+
fun aWrappedDescriptionKeepsTheTimeOutsideTheAction() {
|
|
100
|
+
val wrapped = regions(
|
|
101
|
+
NativeListTextLine(top = 0f, bottom = 20f, touchable = listOf(run(55f, 110f)), plain = listOf(run(0f, 55f))),
|
|
102
|
+
NativeListTextLine(top = 20f, bottom = 40f, touchable = listOf(run(0f, 100f))),
|
|
103
|
+
)
|
|
104
|
+
assertFalse(hit(wrapped, 20f, 10f))
|
|
105
|
+
assertTrue(hit(wrapped, 80f, 10f))
|
|
106
|
+
assertTrue(hit(wrapped, 20f, 30f))
|
|
107
|
+
assertFalse(hit(wrapped, 130f, 30f))
|
|
108
|
+
|
|
109
|
+
// The whole time sits on the first line: that line takes no touches at all.
|
|
110
|
+
val timeOnItsOwnLine = regions(
|
|
111
|
+
NativeListTextLine(top = 0f, bottom = 20f, touchable = emptyList(), plain = listOf(run(0f, 55f))),
|
|
112
|
+
NativeListTextLine(top = 20f, bottom = 40f, touchable = listOf(run(0f, 100f))),
|
|
113
|
+
)
|
|
114
|
+
assertFalse(hit(timeOnItsOwnLine, 20f, 10f))
|
|
115
|
+
// Nor does the address line reach up into it.
|
|
116
|
+
assertFalse(hit(timeOnItsOwnLine, 20f, 19f))
|
|
117
|
+
assertTrue(hit(timeOnItsOwnLine, 20f, 30f))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// A start at the end of the text leaves nothing to touch.
|
|
121
|
+
@Test
|
|
122
|
+
fun aLineWithoutTouchableTextLeavesNoRegion() {
|
|
123
|
+
val none = regions(NativeListTextLine(top = 0f, bottom = 20f, touchable = emptyList(), plain = listOf(run(0f, 55f))))
|
|
124
|
+
|
|
125
|
+
assertTrue(none.isEmpty())
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// `descriptionActionStart` is a UTF-16 offset into the caller's string. It is
|
|
129
|
+
// kept within the text, and follows the line breaks a one-line view folds.
|
|
130
|
+
@Test
|
|
131
|
+
fun theCallersStartIsMappedOntoTheDisplayedText() {
|
|
132
|
+
val label = "Router • V2"
|
|
133
|
+
assertEquals(0, nativeListDisplayOffset(label, 0, foldsLineBreaks = false))
|
|
134
|
+
assertEquals(8, nativeListDisplayOffset("08:48 • $label", 8, foldsLineBreaks = false))
|
|
135
|
+
assertEquals(0, nativeListDisplayOffset(label, -3, foldsLineBreaks = false))
|
|
136
|
+
assertEquals(label.length, nativeListDisplayOffset(label, 99, foldsLineBreaks = false))
|
|
137
|
+
// Any safe integer arrives over JSON. One past Int range still clamps to
|
|
138
|
+
// the end; narrowed to Int first it would wrap to 0, the whole text.
|
|
139
|
+
assertEquals(label.length, nativeListDisplayOffset(label, 4_294_967_296L, foldsLineBreaks = false))
|
|
140
|
+
assertEquals(label.length, nativeListDisplayOffset(label, Long.MAX_VALUE, foldsLineBreaks = true))
|
|
141
|
+
|
|
142
|
+
// The emoji takes two UTF-16 units, as in the JavaScript string.
|
|
143
|
+
val emojiPrefix = "🕘 08:48 • "
|
|
144
|
+
assertEquals(11, emojiPrefix.length)
|
|
145
|
+
assertEquals(label, "$emojiPrefix$label".substring(nativeListDisplayOffset("$emojiPrefix$label", 11, foldsLineBreaks = false)))
|
|
146
|
+
|
|
147
|
+
val broken = "08:48\r\n• Router"
|
|
148
|
+
assertEquals("08:48 • Router", nativeListFoldLineBreaks(broken))
|
|
149
|
+
assertEquals(8, nativeListDisplayOffset(broken, 9, foldsLineBreaks = true))
|
|
150
|
+
assertEquals(9, nativeListDisplayOffset(broken, 9, foldsLineBreaks = false))
|
|
151
|
+
assertEquals(14, nativeListDisplayOffset(broken, 99, foldsLineBreaks = true))
|
|
152
|
+
}
|
|
153
|
+
}
|
package/docs/ROW_TEMPLATES.md
CHANGED
|
@@ -181,7 +181,10 @@ separately from source implementation in STYLE_SPEC §9.
|
|
|
181
181
|
- **Native rich amounts:** optional `amounts` replaces the legacy two strings,
|
|
182
182
|
with at most 32 unique keyed entries. Each entry supports a leading visual,
|
|
183
183
|
tone, primary/secondary text and subscript segments. The title supports at
|
|
184
|
-
most four keyed badges. `descriptionActionKey` emits a description action
|
|
184
|
+
most four keyed badges. `descriptionActionKey` emits a description action on
|
|
185
|
+
the description text from `descriptionActionStart` on (a UTF-16 offset the
|
|
186
|
+
caller supplies; default `0`, the whole text). The text before it and the
|
|
187
|
+
rest of the line stay with the row press.
|
|
185
188
|
`presentation: 'table'` allocates identity (including the leading visual and
|
|
186
189
|
its gap), amounts and optional fee in a stable `1:1:0.6` ratio after column
|
|
187
190
|
gaps. Without fee, identity and amounts have equal widths. Amount content
|
|
@@ -254,7 +257,9 @@ stacked (phone) table (wide)
|
|
|
254
257
|
view. Container, padding, image, `leadingGap` and `index` styles keep the
|
|
255
258
|
legacy text layout.
|
|
256
259
|
- *Web:* `secondaryLeadingText` precedes the primary text on the same line,
|
|
257
|
-
badges follow it, and secondary text is directly below.
|
|
260
|
+
badges follow it, and secondary text is directly below. An optional
|
|
261
|
+
`webLeadingBadge` on a column is a passive label at the start of that line,
|
|
262
|
+
truncated at half of the column width; iOS and Android ignore it.
|
|
258
263
|
- Table layout uses the column view on every platform (Android unstyled:
|
|
259
264
|
the fixed legacy column geometry above).
|
|
260
265
|
- **Style isolation:** primary and secondary text use independent style targets in
|
|
@@ -291,8 +296,10 @@ stacked (phone) table (wide)
|
|
|
291
296
|
supplies one or two distinct `image`/`video` candidates. It takes precedence
|
|
292
297
|
over `image`; explicit `imageState: empty | error` still suppresses loading.
|
|
293
298
|
A video candidate uses a muted paused native player, with no playback/controls or
|
|
294
|
-
touch target. Detail playback remains caller-owned.
|
|
295
|
-
|
|
299
|
+
touch target. Detail playback remains caller-owned. While loading the slot
|
|
300
|
+
shows a synchronized sheen placeholder; failure advances once to the next
|
|
301
|
+
candidate, then shows the hatched failed placeholder (SPEC: Media loading
|
|
302
|
+
and failure placeholders). The same
|
|
296
303
|
media box and caption diagram apply; this adds no new layout region.
|
|
297
304
|
Web keeps the existing `image` field and does not execute media probing.
|
|
298
305
|
- **Native lifetime:** request identity includes row key, full source, fit,
|