@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
|
@@ -60,6 +60,276 @@ final class NativeListActivityPresentationTests: XCTestCase {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
// The description label spans the identity column, so a tap anywhere on its
|
|
64
|
+
// line used to open the description action. Only the action text opens it
|
|
65
|
+
// now; the blank rest of the line belongs to the row press (OK-67219). Where
|
|
66
|
+
// that text starts is the caller's `descriptionActionStart`, never something
|
|
67
|
+
// read out of the string.
|
|
68
|
+
func testDescriptionActionTakesTouchesOnItsTextOnly() throws {
|
|
69
|
+
let details = NativeListActivityDetailsView()
|
|
70
|
+
// Wide enough that the label keeps blank space beside its text even when
|
|
71
|
+
// the amounts take their full half of the row.
|
|
72
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: 600, height: 300))
|
|
73
|
+
details.translatesAutoresizingMaskIntoConstraints = false
|
|
74
|
+
container.addSubview(details)
|
|
75
|
+
NSLayoutConstraint.activate([
|
|
76
|
+
details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
77
|
+
details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
78
|
+
details.topAnchor.constraint(equalTo: container.topAnchor),
|
|
79
|
+
])
|
|
80
|
+
func bind(description: String, actionKey: String?, actionStart: Int? = nil) throws -> NativeListTextLabel {
|
|
81
|
+
var data: [String: Any] = [
|
|
82
|
+
"type": "activity", "key": "tx", "title": "Swap", "description": description,
|
|
83
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
84
|
+
"amounts": [["key": "send", "text": "-1"]],
|
|
85
|
+
]
|
|
86
|
+
if let actionKey { data["descriptionActionKey"] = actionKey }
|
|
87
|
+
if let actionStart { data["descriptionActionStart"] = actionStart }
|
|
88
|
+
details.bind(try NativeListItem(data: data), theme: nil, fonts: NativeListFontFamilies())
|
|
89
|
+
container.layoutIfNeeded()
|
|
90
|
+
func find(_ view: UIView) -> NativeListTextLabel? {
|
|
91
|
+
if let label = view as? NativeListTextLabel, label.text == description { return label }
|
|
92
|
+
return view.subviews.lazy.compactMap(find).first
|
|
93
|
+
}
|
|
94
|
+
return try XCTUnwrap(find(details))
|
|
95
|
+
}
|
|
96
|
+
func hit(_ label: NativeListTextLabel, x: CGFloat) -> Bool {
|
|
97
|
+
label.point(inside: CGPoint(x: x, y: label.bounds.midY), with: nil)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Without a start the whole text is the action, also a label holding the
|
|
101
|
+
// separator a time prefix would use.
|
|
102
|
+
let label = try bind(description: "Router • V2", actionKey: "address-info")
|
|
103
|
+
let labelText = try XCTUnwrap(label.touchableTextRegions.first)
|
|
104
|
+
XCTAssertEqual(label.touchableTextStart, 0)
|
|
105
|
+
XCTAssertEqual(label.touchableTextRegions.count, 1)
|
|
106
|
+
XCTAssertGreaterThan(label.bounds.width, labelText.maxX + 40)
|
|
107
|
+
XCTAssertTrue(hit(label, x: 4))
|
|
108
|
+
XCTAssertTrue(hit(label, x: labelText.maxX - 12))
|
|
109
|
+
XCTAssertFalse(hit(label, x: label.bounds.maxX - 4))
|
|
110
|
+
|
|
111
|
+
// With a start only the text from there on is the action: the time is
|
|
112
|
+
// not, the complete label behind it is.
|
|
113
|
+
let prefix = "08:48 • "
|
|
114
|
+
let timed = try bind(
|
|
115
|
+
description: prefix + "Router • V2", actionKey: "address-info",
|
|
116
|
+
actionStart: (prefix as NSString).length)
|
|
117
|
+
let timedText = try XCTUnwrap(timed.touchableTextRegions.first)
|
|
118
|
+
XCTAssertEqual(timed.touchableTextRegions.count, 1)
|
|
119
|
+
XCTAssertGreaterThan(timed.bounds.width, timedText.maxX + 40)
|
|
120
|
+
// The same label, less the slop on the side where the time is.
|
|
121
|
+
XCTAssertEqual(timedText.width, labelText.width - 8, accuracy: 1)
|
|
122
|
+
XCTAssertFalse(hit(timed, x: 4))
|
|
123
|
+
XCTAssertFalse(hit(timed, x: timedText.minX - 2))
|
|
124
|
+
XCTAssertTrue(hit(timed, x: timedText.minX + 2))
|
|
125
|
+
XCTAssertTrue(hit(timed, x: timedText.maxX - 12))
|
|
126
|
+
XCTAssertFalse(hit(timed, x: timed.bounds.maxX - 4))
|
|
127
|
+
|
|
128
|
+
// The start counts UTF-16 units: the emoji takes two.
|
|
129
|
+
let emojiPrefix = "🕘 08:48 • "
|
|
130
|
+
XCTAssertEqual((emojiPrefix as NSString).length, 11)
|
|
131
|
+
let emoji = try bind(
|
|
132
|
+
description: emojiPrefix + "Router • V2", actionKey: "address-info", actionStart: 11)
|
|
133
|
+
let emojiText = try XCTUnwrap(emoji.touchableTextRegions.first)
|
|
134
|
+
XCTAssertEqual(emojiText.width, labelText.width - 8, accuracy: 1)
|
|
135
|
+
XCTAssertFalse(hit(emoji, x: 4))
|
|
136
|
+
XCTAssertFalse(hit(emoji, x: emojiText.minX - 2))
|
|
137
|
+
XCTAssertTrue(hit(emoji, x: emojiText.minX + 2))
|
|
138
|
+
XCTAssertTrue(hit(emoji, x: emojiText.maxX - 12))
|
|
139
|
+
|
|
140
|
+
// A start at the end of the text, or clamped to it, leaves nothing to tap.
|
|
141
|
+
// 4294967296 is a safe integer past 32 bits; it must clamp, not wrap to 0.
|
|
142
|
+
for start in [(prefix as NSString).length, 99, 4_294_967_296] {
|
|
143
|
+
let ended = try bind(description: prefix, actionKey: "address-info", actionStart: start)
|
|
144
|
+
XCTAssertTrue(ended.touchableTextRegions.isEmpty)
|
|
145
|
+
XCTAssertFalse(ended.isUserInteractionEnabled)
|
|
146
|
+
XCTAssertFalse(hit(ended, x: 4))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The reused view keeps no state: a rebind without a start covers the
|
|
150
|
+
// whole text again, one without the action restores the label's own hit
|
|
151
|
+
// testing even when a start is still supplied, and so does recycling.
|
|
152
|
+
let rebound = try bind(description: "Router • V2", actionKey: "address-info")
|
|
153
|
+
XCTAssertEqual(rebound.touchableTextStart, 0)
|
|
154
|
+
XCTAssertTrue(rebound.isUserInteractionEnabled)
|
|
155
|
+
XCTAssertTrue(hit(rebound, x: 4))
|
|
156
|
+
let plain = try bind(description: "Router • V2", actionKey: nil, actionStart: 3)
|
|
157
|
+
XCTAssertNil(plain.touchableTextStart)
|
|
158
|
+
XCTAssertFalse(plain.isUserInteractionEnabled)
|
|
159
|
+
XCTAssertTrue(hit(plain, x: plain.bounds.maxX - 4))
|
|
160
|
+
let recycled = try bind(
|
|
161
|
+
description: prefix + "Router", actionKey: "address-info",
|
|
162
|
+
actionStart: (prefix as NSString).length)
|
|
163
|
+
XCTAssertEqual(recycled.touchableTextStart, (prefix as NSString).length)
|
|
164
|
+
details.recycle()
|
|
165
|
+
XCTAssertNil(recycled.touchableTextStart)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// A narrow column wraps "time • address". The time stays outside the action
|
|
169
|
+
// on its line, while the address is hit on both lines, also at the x the
|
|
170
|
+
// time occupies one line above. The label is sized directly so the wrap does
|
|
171
|
+
// not depend on how the row shares its width.
|
|
172
|
+
func testWrappedDescriptionKeepsTheTimeOutsideTheAction() throws {
|
|
173
|
+
let description = "08:48 • Uniswap Router"
|
|
174
|
+
let label = NativeListTextLabel()
|
|
175
|
+
NativeListResolvedText(
|
|
176
|
+
description, style: nil, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
177
|
+
fonts: NativeListFontFamilies()
|
|
178
|
+
).bind(label)
|
|
179
|
+
label.frame = CGRect(x: 0, y: 0, width: 142, height: 40)
|
|
180
|
+
label.touchableTextStart = ("08:48 • " as NSString).length
|
|
181
|
+
func hit(_ x: CGFloat, _ y: CGFloat) -> Bool {
|
|
182
|
+
label.point(inside: CGPoint(x: x, y: y), with: nil)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let lines = label.touchableTextRegions
|
|
186
|
+
XCTAssertEqual(lines.count, 2)
|
|
187
|
+
guard lines.count == 2 else { return }
|
|
188
|
+
XCTAssertFalse(hit(4, lines[0].midY))
|
|
189
|
+
XCTAssertTrue(hit(lines[0].maxX - 12, lines[0].midY))
|
|
190
|
+
XCTAssertTrue(hit(4, lines[1].midY))
|
|
191
|
+
XCTAssertFalse(hit(label.bounds.maxX - 2, lines[1].midY))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The first line holds only the time, so it takes no touches, and the slop
|
|
195
|
+
// of the address line below it must not reach up into the time.
|
|
196
|
+
func testAddressStartingOnTheSecondLineLeavesTheTimeLineAlone() throws {
|
|
197
|
+
let prefix = "08:48 • "
|
|
198
|
+
let address = "UniswapUniversalRouter"
|
|
199
|
+
func text(_ value: String) -> NativeListResolvedText {
|
|
200
|
+
NativeListResolvedText(
|
|
201
|
+
value, style: nil, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
202
|
+
fonts: NativeListFontFamilies())
|
|
203
|
+
}
|
|
204
|
+
let label = NativeListTextLabel()
|
|
205
|
+
text(prefix + address).bind(label)
|
|
206
|
+
// Wide enough for the address alone, too narrow for the time beside it.
|
|
207
|
+
label.frame = CGRect(x: 0, y: 0, width: text(address).measureWidth() + 4, height: 40)
|
|
208
|
+
label.touchableTextStart = (prefix as NSString).length
|
|
209
|
+
func hit(y: CGFloat) -> Bool { label.point(inside: CGPoint(x: 4, y: y), with: nil) }
|
|
210
|
+
|
|
211
|
+
let line = try XCTUnwrap(label.touchableTextRegions.first)
|
|
212
|
+
XCTAssertEqual(label.touchableTextRegions.count, 1)
|
|
213
|
+
XCTAssertEqual(line.minY, 20, accuracy: 0.5)
|
|
214
|
+
XCTAssertFalse(hit(y: 10))
|
|
215
|
+
XCTAssertFalse(hit(y: line.minY - 2))
|
|
216
|
+
XCTAssertTrue(hit(y: line.minY + 2))
|
|
217
|
+
// The last line of the layout still takes its slop below the text.
|
|
218
|
+
XCTAssertTrue(hit(y: label.bounds.maxY + 4))
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private func descriptionText(_ value: String, style: [String: Any]? = nil) -> NativeListResolvedText {
|
|
222
|
+
NativeListResolvedText(
|
|
223
|
+
value, style: style, size: 14, color: .label, lineHeight: 20, lines: 1,
|
|
224
|
+
fonts: NativeListFontFamilies())
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/// Width the description font gives `value` on its own.
|
|
228
|
+
private func descriptionWidth(_ value: String) -> CGFloat {
|
|
229
|
+
descriptionText(value).attributed(direction: .leftToRight).size().width
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private func descriptionLabel(
|
|
233
|
+
_ value: String, start: Int, width: CGFloat = 300, style: [String: Any]? = nil
|
|
234
|
+
) -> NativeListTextLabel {
|
|
235
|
+
let label = NativeListTextLabel()
|
|
236
|
+
descriptionText(value, style: style).bind(label)
|
|
237
|
+
label.frame = CGRect(x: 0, y: 0, width: width, height: 20)
|
|
238
|
+
label.touchableTextStart = start
|
|
239
|
+
return label
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private func hit(_ label: NativeListTextLabel, x: CGFloat) -> Bool {
|
|
243
|
+
label.point(inside: CGPoint(x: x, y: label.bounds.midY), with: nil)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// The slop is for blank space. It stops at plain text beside the action
|
|
247
|
+
// text, or a prefix narrower than the slop, like the "i" of "iRouter", would
|
|
248
|
+
// open an action it is not part of.
|
|
249
|
+
func testSlopStopsAtPlainTextBesideTheActionText() throws {
|
|
250
|
+
let short = descriptionLabel("iRouter", start: 1)
|
|
251
|
+
let i = descriptionWidth("i")
|
|
252
|
+
XCTAssertLessThan(i, 8)
|
|
253
|
+
let region = try XCTUnwrap(short.touchableTextRegions.first)
|
|
254
|
+
XCTAssertEqual(short.touchableTextRegions.count, 1)
|
|
255
|
+
XCTAssertEqual(region.minX, i, accuracy: 0.5)
|
|
256
|
+
XCTAssertFalse(hit(short, x: i / 2))
|
|
257
|
+
XCTAssertFalse(hit(short, x: -3))
|
|
258
|
+
XCTAssertTrue(hit(short, x: i + 2))
|
|
259
|
+
// Into the blank after the text the slop still reaches.
|
|
260
|
+
XCTAssertTrue(hit(short, x: descriptionWidth("iRouter") + 6))
|
|
261
|
+
XCTAssertFalse(hit(short, x: descriptionWidth("iRouter") + 10))
|
|
262
|
+
// And into the blank before a line that starts with the action text.
|
|
263
|
+
XCTAssertTrue(hit(descriptionLabel("Router", start: 0), x: -6))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Mixed-direction text can split one logical suffix into several visual
|
|
267
|
+
// runs. From offset 6 of "ABC אבג XYZ" the suffix is the last Hebrew letter
|
|
268
|
+
// and " XYZ"; the Hebrew run is drawn right to left, so that letter sits
|
|
269
|
+
// left of the two plain ones. Each run is its own region and the plain text
|
|
270
|
+
// between them takes no touches.
|
|
271
|
+
func testMixedDirectionSuffixFollowsTheLaidOutRuns() {
|
|
272
|
+
let label = descriptionLabel("ABC \u{05D0}\u{05D1}\u{05D2} XYZ", start: 6)
|
|
273
|
+
let abc = descriptionWidth("ABC ")
|
|
274
|
+
let last = descriptionWidth("\u{05D2}")
|
|
275
|
+
let plain = descriptionWidth("\u{05D1}\u{05D0}")
|
|
276
|
+
let xyz = descriptionWidth(" XYZ")
|
|
277
|
+
let regions = label.touchableTextRegions.sorted { $0.minX < $1.minX }
|
|
278
|
+
XCTAssertEqual(regions.count, 2)
|
|
279
|
+
guard regions.count == 2 else { return }
|
|
280
|
+
XCTAssertEqual(regions[0].minX, abc, accuracy: 1)
|
|
281
|
+
XCTAssertEqual(regions[0].maxX, abc + last, accuracy: 1)
|
|
282
|
+
XCTAssertEqual(regions[1].minX, abc + last + plain, accuracy: 1)
|
|
283
|
+
XCTAssertFalse(hit(label, x: abc / 2))
|
|
284
|
+
XCTAssertTrue(hit(label, x: abc + last / 2))
|
|
285
|
+
XCTAssertFalse(hit(label, x: abc + last + plain / 2))
|
|
286
|
+
XCTAssertTrue(hit(label, x: abc + last + plain + xyz / 2))
|
|
287
|
+
// Only the outer edge of the last run faces blank space.
|
|
288
|
+
XCTAssertTrue(hit(label, x: abc + last + plain + xyz + 5))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// A one-line description that does not fit ends in an ellipsis. Action text
|
|
292
|
+
// it only shortens stays touchable up to and including the ellipsis. Once it
|
|
293
|
+
// hides the action text altogether the ellipsis also stands for plain text,
|
|
294
|
+
// and nothing is left to touch.
|
|
295
|
+
func testTruncationCanHideTheActionText() throws {
|
|
296
|
+
let cut = descriptionLabel(
|
|
297
|
+
"08:48 • UniswapUniversalRouterWithAVeryLongName", start: 8, width: 150,
|
|
298
|
+
style: ["lines": 1])
|
|
299
|
+
let region = try XCTUnwrap(cut.touchableTextRegions.first)
|
|
300
|
+
XCTAssertEqual(cut.touchableTextRegions.count, 1)
|
|
301
|
+
XCTAssertEqual(region.minX, descriptionWidth("08:48 • "), accuracy: 1)
|
|
302
|
+
XCTAssertFalse(hit(cut, x: 20))
|
|
303
|
+
XCTAssertTrue(hit(cut, x: 100))
|
|
304
|
+
XCTAssertTrue(hit(cut, x: 145))
|
|
305
|
+
|
|
306
|
+
let prefix = "A very long plain prefix that fills the row • "
|
|
307
|
+
let hidden = descriptionLabel(
|
|
308
|
+
prefix + "Router", start: (prefix as NSString).length, width: 150, style: ["lines": 1])
|
|
309
|
+
XCTAssertTrue(hidden.touchableTextRegions.isEmpty)
|
|
310
|
+
XCTAssertFalse(hit(hidden, x: 145))
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// A one-line description folds each line break into one space, so the
|
|
314
|
+
// caller's offset is mapped onto the displayed text and kept inside it.
|
|
315
|
+
func testDescriptionActionStartFollowsTheDisplayedText() {
|
|
316
|
+
let source = "08:48\r\n• Router"
|
|
317
|
+
func text(_ style: [String: Any]?) -> NativeListResolvedText {
|
|
318
|
+
NativeListResolvedText(
|
|
319
|
+
source, style: style, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
320
|
+
fonts: NativeListFontFamilies())
|
|
321
|
+
}
|
|
322
|
+
let oneLine = text(["lines": 1])
|
|
323
|
+
XCTAssertEqual(oneLine.text, "08:48 • Router")
|
|
324
|
+
XCTAssertEqual(oneLine.displayOffset(9, in: source), 8)
|
|
325
|
+
XCTAssertEqual(oneLine.displayOffset(-3, in: source), 0)
|
|
326
|
+
XCTAssertEqual(oneLine.displayOffset(99, in: source), 14)
|
|
327
|
+
let wrapping = text(nil)
|
|
328
|
+
XCTAssertEqual(wrapping.text, source)
|
|
329
|
+
XCTAssertEqual(wrapping.displayOffset(9, in: source), 9)
|
|
330
|
+
XCTAssertEqual(wrapping.displayOffset(99, in: source), 15)
|
|
331
|
+
}
|
|
332
|
+
|
|
63
333
|
func testSmallNumberRunsPreserveBaselineAcrossAmountsFiatAndFee() throws {
|
|
64
334
|
func segments(_ prefix: String, _ suffix: String) -> [[String: Any]] {
|
|
65
335
|
[["text": prefix], ["text": "5", "style": "subscript"], ["text": suffix]]
|