@onekeyfe/react-native-native-list 3.0.157-alpha.258 → 3.0.157-alpha.273
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 +17 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +55 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListScrollAlignment.kt +29 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListScrollPositionTracker.kt +30 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +127 -22
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListScrollAlignmentTest.kt +62 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListScrollPositionTrackerTest.kt +16 -0
- package/docs/SPEC.md +85 -17
- package/docs/STYLE_SPEC.md +4 -2
- package/ios/NativeListActivityDetailsView.swift +77 -15
- package/ios/NativeListMediaPreviewSlot.swift +63 -3
- package/ios/NativeListResolvedText.swift +8 -0
- package/ios/NativeListScrollGeometry.swift +27 -0
- package/ios/RNCNativeListView.swift +39 -21
- package/ios/tests/NativeListActivityPresentationTests.swift +54 -0
- package/ios/tests/NativeListLifecycleTests.swift +28 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +67 -0
- package/lib/module/models.js +1 -1
- package/lib/module/scrolling.js +3 -1
- package/lib/module/validation.js +2 -2
- package/lib/typescript/src/models.d.ts +1 -1
- package/package.json +3 -3
- package/src/models.ts +1 -0
- package/src/scrolling.ts +4 -1
- package/src/validation.ts +1 -6
package/docs/SPEC.md
CHANGED
|
@@ -390,9 +390,10 @@ only. Existing Web rendering and caller behavior are unchanged.
|
|
|
390
390
|
Replacing the JS callback takes effect on the next event; disabling emits no event.
|
|
391
391
|
Configuration updates reset hysteresis before recomputing current position.
|
|
392
392
|
- iOS uses contentOffset + contentInset, excluding overscroll below zero. Android
|
|
393
|
-
accumulates consumed child scroll distance and
|
|
394
|
-
|
|
395
|
-
|
|
393
|
+
accumulates consumed child scroll distance and, after every layout pass or
|
|
394
|
+
zero-delta scroll, re-derives it from the measured extents above the first laid-out
|
|
395
|
+
item (see Android ancestor scroll distance). Parent-pager header contributions are
|
|
396
|
+
tracked separately.
|
|
396
397
|
- `layout.gridColumns` accepts integers 2 through 7 on native. Native parsers
|
|
397
398
|
clamp malformed external JSON to 1 through 7 as before; public JS validation
|
|
398
399
|
rejects invalid requested counts. Grid geometry remains container-owned.
|
|
@@ -433,14 +434,22 @@ changing probe order or the terminal result contract; native runtime regression
|
|
|
433
434
|
acceptance is still required. A tile owns at most one native player. On iOS,
|
|
434
435
|
eligibility requires intersection with the window and every clipping/scroll
|
|
435
436
|
ancestor viewport; native scroll, bounds, layer transform/position and visibility
|
|
436
|
-
observations release retained offscreen pager pages.
|
|
437
|
-
|
|
438
|
-
|
|
437
|
+
observations release retained offscreen pager pages. A player lives only until
|
|
438
|
+
its first rendered frame is copied (Android TextureView bitmap, iOS
|
|
439
|
+
AVPlayerItemVideoOutput pixel buffer); the tile then shows that still frame with the
|
|
440
|
+
same fit and letterbox and releases the player and its viewport observers. If no frame
|
|
441
|
+
can be copied after a few frames, the paused player stays attached. Detach,
|
|
442
|
+
background, invisibility and recycle release a player still awaiting its first frame;
|
|
443
|
+
reattachment rebuilds its retained source while remaining paused. The still frame is
|
|
444
|
+
kept across detach and same-identity rebinding and dropped on recycle or identity
|
|
445
|
+
change. Android observes native global scroll/layout and
|
|
439
446
|
pre-draw geometry (including property animations), checking ancestor alpha and
|
|
440
447
|
getGlobalVisibleRect before allocating a player. These observers do not schedule
|
|
441
448
|
frames or emit JavaScript events.
|
|
442
|
-
|
|
443
|
-
visible tiles; there is no numeric cap that
|
|
449
|
+
Live player count is bounded by intersecting native video tiles that have not yet
|
|
450
|
+
captured a frame, including partially visible tiles; there is no numeric cap that
|
|
451
|
+
blanks visible iPad cells. Per-draw (Android) and ancestor-layer KVO (iOS) viewport
|
|
452
|
+
observation exists only while a tile awaits its first frame. iOS requests
|
|
444
453
|
one second of forward buffer; AVFoundation treats this as an advisory preference,
|
|
445
454
|
not a hard byte limit. Android uses a 250–1000 ms forward buffer, zero back buffer
|
|
446
455
|
and a 2 MiB target allocator; Media3 may exceed a target by allocation granularity.
|
|
@@ -479,14 +488,20 @@ Slots scroll with the native list. `fixedFooter` remains a separate fixed native
|
|
|
479
488
|
row descriptor. `scrollToEnd` aligns the final scrolling slot bottom with the
|
|
480
489
|
viewport end, including footer/empty/header-only slots taller than the viewport. Callers using `listEmpty` MUST omit `snapshot.emptyState`, whose
|
|
481
490
|
existing native descriptor becomes a data item. Horizontal content padding applies
|
|
482
|
-
to slots as well as data rows
|
|
491
|
+
to slots as well as data rows: every platform places a slot root exactly
|
|
492
|
+
`contentPaddingHorizontal ?? contentPadding` logical units from each edge, the same
|
|
493
|
+
width React lays it out at. Android's narrow-screen row scale and section-index gutter
|
|
494
|
+
apply to data rows only. Slot React trees own their internal layout and
|
|
483
495
|
business actions; NativeList owns their scroll placement and lifecycle.
|
|
484
496
|
|
|
485
497
|
The wrapper mounts exactly three non-collapsible slot roots and reports measured
|
|
486
498
|
heights through `containerSlotHeightsJson` in header/empty/footer order. Native
|
|
487
499
|
validates three finite, non-negative heights. Slot updates MUST NOT alter data-row
|
|
488
500
|
keys or public row indices. No per-scroll-frame JS position updates are used.
|
|
489
|
-
iOS mounts slot
|
|
501
|
+
iOS mounts each slot root inside a list-owned host view in UICollectionView and
|
|
502
|
+
reserves native layout space. The host owns the slot's vertical position and clips to
|
|
503
|
+
the reported height, so React frame updates cannot move a slot out of place and a slot
|
|
504
|
+
whose height has not been reported yet (or has just grown) never draws over rows.
|
|
490
505
|
Android uses ConcatAdapter with three single-item slot adapters around the existing
|
|
491
506
|
data adapter; adapter binding indices stay local while layout-manager positions
|
|
492
507
|
are explicitly translated. Slots span all grid columns, do not select/reorder,
|
|
@@ -558,7 +573,10 @@ source `description`; footer actions retain their existing source/keys and
|
|
|
558
573
|
disabled behavior. All actions use the current host binding epoch.
|
|
559
574
|
|
|
560
575
|
Rich rows measure the declared line/visual metrics; there is no six-line native
|
|
561
|
-
truncation.
|
|
576
|
+
truncation. iOS automatic height mirrors the rendered stacks: `lineGap` between the
|
|
577
|
+
visible title/description/status lines, the description measured at the identity
|
|
578
|
+
column's actual width (stacked or table, including the fee column), fee height and the
|
|
579
|
+
footer-action button height. Android sizes the row to its content. The existing height override contract still applies. RTL follows
|
|
562
580
|
semantic leading/trailing anchors. Clearing rich fields returns to the legacy
|
|
563
581
|
renderer, and removing amount lines recycles their visual slots. Web rendering
|
|
564
582
|
remains unchanged; rich fields are native-only until a separate Web migration.
|
|
@@ -581,12 +599,17 @@ same logical Home threshold as iOS normalized content scrolling, without a JS
|
|
|
581
599
|
scroll-frame event. Changes to the listener or public callbacks do not replace
|
|
582
600
|
native resource ownership.
|
|
583
601
|
|
|
584
|
-
Child distance uses actual onScrolled dy
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
602
|
+
Child distance uses actual onScrolled dy while scrolling continuously. Programmatic
|
|
603
|
+
jumps (scrollToIndex/Key/End/Offset), anchor restores and inserts or height changes
|
|
604
|
+
above the viewport report no dy, so every layout pass and zero-delta scroll re-derives
|
|
605
|
+
the distance as the extent of all grid lines before the first laid-out item plus its
|
|
606
|
+
offset from the padded top. Extents are those actually laid out (recorded per row key,
|
|
607
|
+
including rows a jump lays out and leaves offscreen, pruned to the current rows); a row
|
|
608
|
+
that was never laid out uses its explicit height, else the mean laid-out row extent.
|
|
609
|
+
Slots use their reported heights. The result is exact once every item above the
|
|
610
|
+
viewport has been laid out and an estimate only across never-laid-out rows; it does not
|
|
611
|
+
use RecyclerView's average-height scrollbar estimate. Runtime acceptance for distant
|
|
612
|
+
jumps remains pending.
|
|
590
613
|
|
|
591
614
|
|
|
592
615
|
### Container follow-up verification
|
|
@@ -596,3 +619,48 @@ tall empty slot with viewport padding, animated decorated-bottom correction,
|
|
|
596
619
|
and short footer. These validate geometry, not actual RecyclerView animation or
|
|
597
620
|
Fabric lifecycle. Native simulator acceptance remains required. The iOS fallback
|
|
598
621
|
retains one refresh action per drag and leaves haptic feedback to its caller.
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
## Explicit scroll alignment (OK-64041)
|
|
625
|
+
|
|
626
|
+
Status: implemented on Web, Android and iOS. This change ports the 3.0.154
|
|
627
|
+
maintenance fix to the current main protocol and layout. The maintenance
|
|
628
|
+
application recordings below do not establish runtime acceptance of this port.
|
|
629
|
+
|
|
630
|
+
Keys identify outer rows; a wallet group member is not a separate scroll key.
|
|
631
|
+
Explicit `viewPosition`/start/center/end alignment MUST use the signed difference
|
|
632
|
+
`viewportLength - itemLength`, then apply `viewOffset` and the existing content
|
|
633
|
+
bounds. This applies to both axes. Positive `viewOffset` leaves space before the
|
|
634
|
+
aligned target. An oversized row cannot be fully visible; center aligns its
|
|
635
|
+
center and end aligns its trailing edge. `nearest` MUST retain its existing
|
|
636
|
+
oversized-row behavior, defaults and request normalization.
|
|
637
|
+
|
|
638
|
+
Android MUST pass the alignment mode through visible, deferred and smooth
|
|
639
|
+
scrolling. For an unmounted explicit nonanimated target, the provisional leading
|
|
640
|
+
edge stays inside the viewport until the existing deferred pass measures the
|
|
641
|
+
real item. Existing container-slot row-position translation remains in force;
|
|
642
|
+
this change adds no retries or bridge API. iOS uses UICollectionView layout
|
|
643
|
+
attributes for mounted and unmounted targets and keeps its adjusted-inset-aware
|
|
644
|
+
content clamp. Web uses the TypeScript calculation. Imperative requests run once
|
|
645
|
+
at the current geometry; consumers own repositioning after layout changes and
|
|
646
|
+
cancellation when the user takes control.
|
|
647
|
+
|
|
648
|
+
Focused TypeScript, Kotlin/JUnit and SwiftPM/XCTest regressions exercise the
|
|
649
|
+
shipping calculations: oversized, short and equal rows, signed offsets, nearest,
|
|
650
|
+
content bounds and Android provisional boundaries. SwiftPM runs the Foundation
|
|
651
|
+
helper on macOS; it does not instantiate UIKit. Geometry tests do not prove
|
|
652
|
+
RecyclerView mounting, deferred callback timing or consumer cancellation.
|
|
653
|
+
|
|
654
|
+
Historical maintenance-base acceptance recorded in PR #138 includes full-app
|
|
655
|
+
Electron/Web 36/36 cases each, Android 27/27 visible-target cases and iOS 15/15
|
|
656
|
+
primary cases. Parent/middle/last targets changed from 0/3 visible to 3/3 on both
|
|
657
|
+
native platforms. Those results use NativeList 3.0.154 plus the patch. Current
|
|
658
|
+
main combined-package runtime acceptance and native horizontal runtime remain
|
|
659
|
+
pending; pixel-perfect wallet-member centering is not claimed.
|
|
660
|
+
|
|
661
|
+
Port verification (2026-10-08): all 236 tests in seven NativeList suites,
|
|
662
|
+
package typecheck, focused TypeScript lint and repository test-integrity pass.
|
|
663
|
+
The consumer Gradle project compiles the actual NativeListView and passes all
|
|
664
|
+
seven Kotlin alignment tests; SwiftPM compiles the shipping helper and passes
|
|
665
|
+
all seven geometry tests. These are local unit/build checks, not a new
|
|
666
|
+
combined-package application or physical-device acceptance run.
|
package/docs/STYLE_SPEC.md
CHANGED
|
@@ -249,7 +249,7 @@ Each cell describes the same public contract on **Web + iOS + Android**.
|
|
|
249
249
|
| `identity` | title, subtitle, tertiary, badge, value, valueSecondary | padding, leadingGap, lineGap, titleBadgeGap, trailingGap, image |
|
|
250
250
|
| `walletGroup` | None; members own their identity styles | padding |
|
|
251
251
|
| `rail` | title, badge, status | padding, leadingGap, titleBadgeGap, trailingGap, image |
|
|
252
|
-
| `activity` | title, description, status, primaryAmount, secondaryAmount | padding, leadingGap, lineGap, trailingGap, image |
|
|
252
|
+
| `activity` | title, description, status, primaryAmount, secondaryAmount | padding, leadingGap, lineGap, titleBadgeGap, trailingGap, image |
|
|
253
253
|
| `message` | title, body, time | padding, leadingGap, lineGap, image |
|
|
254
254
|
| `dataRow` | columns, columnSecondary, index | padding, leadingGap, lineGap, titleBadgeGap, image |
|
|
255
255
|
| `market` | title, subtitle, price, change | padding, leadingGap, lineGap, titleBadgeGap, trailingGap, image; Market-specific properties below |
|
|
@@ -265,7 +265,9 @@ its existing template-specific style surface on every platform.
|
|
|
265
265
|
|
|
266
266
|
Gap meanings are structural: `leadingGap` separates the primary visual from
|
|
267
267
|
content; `lineGap` separates content text rows (primary/secondary per data column);
|
|
268
|
-
`titleBadgeGap` separates a title and its badges (vertical for walletSidebar
|
|
268
|
+
`titleBadgeGap` separates a title and its badges (vertical for walletSidebar;
|
|
269
|
+
for activity, the native failure label or rich title badges; Web has no activity
|
|
270
|
+
badge target);
|
|
269
271
|
`trailingGap` separates trailing values/controls (title/badge to status for rail).
|
|
270
272
|
`walletGroup` padding applies only to the group; it never cascades into members.
|
|
271
273
|
Composite metric-card `lineGap` separates heading/metric blocks and dividers; it
|
|
@@ -49,25 +49,87 @@ final class NativeListActivityDetailsView: UIStackView {
|
|
|
49
49
|
}
|
|
50
50
|
required init(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
51
51
|
|
|
52
|
+
private static let sizingButton: UIButton = {
|
|
53
|
+
let button = UIButton(type: .system)
|
|
54
|
+
button.titleLabel?.font = nativeListFont(ofSize: 14, weight: .medium)
|
|
55
|
+
button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
|
|
56
|
+
return button
|
|
57
|
+
}()
|
|
58
|
+
|
|
59
|
+
/// Mirrors bind(): the same resolved texts, stack spacings and column widths, so the
|
|
60
|
+
/// automatic height matches the rendered stacks.
|
|
52
61
|
static func measure(_ data: [String: Any], width: CGFloat) -> CGFloat {
|
|
53
62
|
let style = data.dictionary("style") ?? [:]
|
|
54
|
-
let
|
|
55
|
-
let
|
|
56
|
-
let
|
|
57
|
-
let
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
+
let table = data.string("presentation") == "table"
|
|
64
|
+
let image = style.dictionary("image") ?? [:]
|
|
65
|
+
let horizontalPadding = CGFloat(style.double("horizontalPadding", default: table ? 16 : 12))
|
|
66
|
+
let verticalPadding = CGFloat(style.double("verticalPadding", default: 8))
|
|
67
|
+
let lineGap = CGFloat(style.double("lineGap"))
|
|
68
|
+
let gap = CGFloat(style.double("leadingGap", default: 12))
|
|
69
|
+
let imageWidth = CGFloat(image.double("width", default: 40))
|
|
70
|
+
let imageHeight = CGFloat(image.double("height", default: 40))
|
|
71
|
+
let mainWidth = max(0, width - horizontalPadding * 2)
|
|
72
|
+
|
|
73
|
+
let amounts = data.dictionaries("amounts").map { amount -> (width: CGFloat, height: CGFloat) in
|
|
74
|
+
let primary = NativeListResolvedText(amount.string("text"), style: style.dictionary("primaryAmount"),
|
|
75
|
+
size: 16, weight: .medium, color: .label, lineHeight: 24, lines: 1, tabular: true)
|
|
76
|
+
let secondary = NativeListResolvedText(amount.string("secondaryText"), style: style.dictionary("secondaryAmount"),
|
|
77
|
+
size: 14, color: .label, lineHeight: 20, lines: 1)
|
|
78
|
+
let visual: CGFloat = amount.dictionary("leading") == nil ? 0 : 20
|
|
79
|
+
return (
|
|
80
|
+
(visual > 0 ? visual + 6 : 0) + max(primary.measureWidth(), secondary.measureWidth()),
|
|
81
|
+
max(visual, primary.measure(width: .greatestFiniteMagnitude) + secondary.measure(width: .greatestFiniteMagnitude))
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
let amountsGap = CGFloat(style.double("trailingGap", default: 2))
|
|
85
|
+
let amountsHeight = amounts.reduce(CGFloat(0)) { $0 + $1.height } + CGFloat(max(0, amounts.count - 1)) * amountsGap
|
|
86
|
+
let amountsWidth = amounts.map(\.width).max() ?? 0
|
|
87
|
+
|
|
88
|
+
var feeWidth: CGFloat = 0
|
|
89
|
+
var feeHeight: CGFloat = 0
|
|
90
|
+
if let feeData = data.dictionary("fee") {
|
|
91
|
+
let secondaryStyle = style.dictionary("secondaryAmount")
|
|
92
|
+
let label = NativeListResolvedText(feeData.string("label"), style: secondaryStyle, size: 12, color: .label, lineHeight: 16, lines: 1)
|
|
93
|
+
let primary = NativeListResolvedText(feeData.string("primary"), style: secondaryStyle, size: 14, color: .label, lineHeight: 20, lines: 1)
|
|
94
|
+
let secondary = NativeListResolvedText(feeData.string("secondary"), style: secondaryStyle, size: 12, color: .label, lineHeight: 16, lines: 1)
|
|
95
|
+
let lineWidth = primary.measureWidth() + secondary.measureWidth() +
|
|
96
|
+
(primary.text.isEmpty || secondary.text.isEmpty ? 0 : 4)
|
|
97
|
+
feeWidth = max(label.measureWidth(), lineWidth)
|
|
98
|
+
feeHeight = label.measure(width: .greatestFiniteMagnitude) +
|
|
99
|
+
max(primary.measure(width: .greatestFiniteMagnitude), secondary.measure(width: .greatestFiniteMagnitude))
|
|
100
|
+
}
|
|
101
|
+
let feeColumn = data.dictionary("fee") == nil ? 0 : gap + feeWidth
|
|
102
|
+
let identityWidth: CGFloat
|
|
103
|
+
if table {
|
|
104
|
+
let shared = (mainWidth - imageWidth - gap * 2 - feeColumn) / 2
|
|
105
|
+
identityWidth = min(mainWidth * 0.42, shared)
|
|
106
|
+
} else {
|
|
107
|
+
identityWidth = mainWidth - imageWidth - gap * 2 - feeColumn - min(amountsWidth, mainWidth * 0.5)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let title = NativeListResolvedText(data.string("title"), style: style.dictionary("title"), size: 16,
|
|
111
|
+
weight: .medium, color: .label, lineHeight: 24, lines: 1)
|
|
112
|
+
let titleHeight = max(
|
|
113
|
+
title.measure(width: .greatestFiniteMagnitude),
|
|
114
|
+
data.dictionaries("badges").isEmpty ? 0 : 16)
|
|
63
115
|
let description = NativeListResolvedText(data.string("description"), style: style.dictionary("description"),
|
|
64
116
|
size: 14, color: .label, lineHeight: 20, lines: 2)
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
117
|
+
let status = NativeListResolvedText(data.string("status"), style: style.dictionary("status"),
|
|
118
|
+
size: 12, color: .label, lineHeight: 16, lines: 1)
|
|
119
|
+
var identityHeight = titleHeight
|
|
120
|
+
for text in [description, status] where !text.text.isEmpty {
|
|
121
|
+
identityHeight += lineGap + text.measure(width: max(1, identityWidth))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var actionsHeight: CGFloat = 0
|
|
125
|
+
let actions = data.dictionaries("footerActions")
|
|
126
|
+
if !actions.isEmpty {
|
|
127
|
+
actionsHeight = actions.reduce(CGFloat(0)) { height, action in
|
|
128
|
+
sizingButton.setTitle(action.string("label"), for: .normal)
|
|
129
|
+
return max(height, ceil(sizingButton.intrinsicContentSize.height))
|
|
130
|
+
} + 8
|
|
131
|
+
}
|
|
132
|
+
return max(imageHeight, identityHeight, amountsHeight, feeHeight) + actionsHeight + verticalPadding * 2
|
|
71
133
|
}
|
|
72
134
|
|
|
73
135
|
func bind(_ item: NativeListItem, theme: [String: Any]?) {
|
|
@@ -10,11 +10,16 @@ private final class NativeListPausedVideoView: UIView {
|
|
|
10
10
|
override func layoutSubviews() { super.layoutSubviews(); onLayoutChanged?() }
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
/// Uses the same AVPlayer source semantics as native Video, always paused and muted.
|
|
13
|
+
/// Uses the same AVPlayer source semantics as native Video, always paused and muted. A player
|
|
14
|
+
/// lives only until its first frame is copied; the tile then shows that still frame.
|
|
14
15
|
final class NativeListMediaPreviewSlot {
|
|
15
16
|
let view = UIView()
|
|
16
17
|
private let image = NativeListImageSlot()
|
|
17
18
|
private let video = NativeListPausedVideoView()
|
|
19
|
+
private let frameView = UIImageView()
|
|
20
|
+
private var videoOutput: AVPlayerItemVideoOutput?
|
|
21
|
+
private static let frameContext = CIContext(options: [.cacheIntermediates: false])
|
|
22
|
+
private static let frameCaptureAttempts = 6
|
|
18
23
|
private var identity: String?
|
|
19
24
|
private var epoch = 0
|
|
20
25
|
private var candidateGeneration = 0
|
|
@@ -37,6 +42,10 @@ final class NativeListMediaPreviewSlot {
|
|
|
37
42
|
}
|
|
38
43
|
video.clipsToBounds = true
|
|
39
44
|
video.isHidden = true
|
|
45
|
+
frameView.frame = video.bounds
|
|
46
|
+
frameView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
47
|
+
frameView.isHidden = true
|
|
48
|
+
video.addSubview(frameView)
|
|
40
49
|
video.onWindowChanged = { [weak self] in self?.observeViewport(); self?.updateVisibility() }
|
|
41
50
|
video.onLayoutChanged = { [weak self] in self?.updateVisibility() }
|
|
42
51
|
lifecycleObservers = [
|
|
@@ -63,7 +72,9 @@ final class NativeListMediaPreviewSlot {
|
|
|
63
72
|
recycle()
|
|
64
73
|
identity = next
|
|
65
74
|
self.completion = completion
|
|
66
|
-
|
|
75
|
+
let cover = (fit ?? source.string("contentFit")) == "cover"
|
|
76
|
+
video.playerLayer.videoGravity = cover ? .resizeAspectFill : .resizeAspect
|
|
77
|
+
frameView.contentMode = cover ? .scaleAspectFill : .scaleAspectFit
|
|
67
78
|
probe(source, key: key, fit: fit, placeholder: placeholder, order: probeOrder, attempt: 0, token: epoch)
|
|
68
79
|
}
|
|
69
80
|
|
|
@@ -109,6 +120,11 @@ final class NativeListMediaPreviewSlot {
|
|
|
109
120
|
let asset = AVURLAsset(url: url, options: ["AVURLAssetHTTPHeaderFieldsKey": source.dictionary("headers") ?? [:]])
|
|
110
121
|
let item = AVPlayerItem(asset: asset)
|
|
111
122
|
item.preferredForwardBufferDuration = 1
|
|
123
|
+
let output = AVPlayerItemVideoOutput(pixelBufferAttributes: [
|
|
124
|
+
kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA,
|
|
125
|
+
])
|
|
126
|
+
item.add(output)
|
|
127
|
+
self.videoOutput = output
|
|
112
128
|
let player = AVPlayer(playerItem: item)
|
|
113
129
|
player.isMuted = true
|
|
114
130
|
player.pause()
|
|
@@ -123,7 +139,9 @@ final class NativeListMediaPreviewSlot {
|
|
|
123
139
|
self.readyObservation = self.video.playerLayer.observe(\.isReadyForDisplay, options: [.initial, .new]) { [weak self] layer, _ in
|
|
124
140
|
DispatchQueue.main.async {
|
|
125
141
|
guard let self, self.playerGeneration == generation else { return }
|
|
126
|
-
|
|
142
|
+
guard layer.isReadyForDisplay else { return }
|
|
143
|
+
finished(true)
|
|
144
|
+
self.captureFirstFrame(generation: generation, attemptsLeft: Self.frameCaptureAttempts)
|
|
127
145
|
}
|
|
128
146
|
}
|
|
129
147
|
}
|
|
@@ -131,6 +149,42 @@ final class NativeListMediaPreviewSlot {
|
|
|
131
149
|
updateVisibility()
|
|
132
150
|
}
|
|
133
151
|
|
|
152
|
+
/// A paused item may not have handed its preroll frame to the output yet, so copying retries
|
|
153
|
+
/// on later runloop turns. If no frame arrives the paused player stays attached.
|
|
154
|
+
private func captureFirstFrame(generation: Int, attemptsLeft: Int) {
|
|
155
|
+
guard playerGeneration == generation, let player, let item = player.currentItem, let output = videoOutput else { return }
|
|
156
|
+
let time = item.currentTime()
|
|
157
|
+
if let buffer = output.copyPixelBuffer(forItemTime: time, itemTimeForDisplay: nil),
|
|
158
|
+
let still = Self.frameContext.createCGImage(CIImage(cvPixelBuffer: buffer), from: CGRect(
|
|
159
|
+
x: 0, y: 0, width: CVPixelBufferGetWidth(buffer), height: CVPixelBufferGetHeight(buffer))) {
|
|
160
|
+
let transform = item.tracks.lazy.compactMap(\.assetTrack).first { $0.mediaType == .video }?.preferredTransform
|
|
161
|
+
frameView.image = UIImage(cgImage: still, scale: 1, orientation: Self.orientation(transform))
|
|
162
|
+
frameView.isHidden = false
|
|
163
|
+
resumeVideo = nil
|
|
164
|
+
viewportObservations.removeAll()
|
|
165
|
+
releasePlayer()
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
guard attemptsLeft > 1 else { return }
|
|
169
|
+
// An exact seek re-delivers the paused preroll frame to newly attached outputs.
|
|
170
|
+
if attemptsLeft == Self.frameCaptureAttempts {
|
|
171
|
+
player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero)
|
|
172
|
+
}
|
|
173
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in
|
|
174
|
+
self?.captureFirstFrame(generation: generation, attemptsLeft: attemptsLeft - 1)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private static func orientation(_ transform: CGAffineTransform?) -> UIImage.Orientation {
|
|
179
|
+
guard let transform else { return .up }
|
|
180
|
+
switch (transform.a, transform.b, transform.c, transform.d) {
|
|
181
|
+
case (0, 1, -1, 0): return .right
|
|
182
|
+
case (0, -1, 1, 0): return .left
|
|
183
|
+
case (-1, 0, 0, -1): return .down
|
|
184
|
+
default: return .up
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
134
188
|
private func observeViewport() {
|
|
135
189
|
viewportObservations.removeAll()
|
|
136
190
|
guard resumeVideo != nil, video.window != nil else { return }
|
|
@@ -149,6 +203,9 @@ final class NativeListMediaPreviewSlot {
|
|
|
149
203
|
}
|
|
150
204
|
}
|
|
151
205
|
|
|
206
|
+
var hasLivePlayer: Bool { player != nil }
|
|
207
|
+
var capturedFrame: UIImage? { frameView.image }
|
|
208
|
+
|
|
152
209
|
/// Retained pager pages can have a window while lying outside its clipped viewport.
|
|
153
210
|
static func intersectsViewport(_ view: UIView) -> Bool {
|
|
154
211
|
guard let window = view.window, !view.bounds.isEmpty else { return false }
|
|
@@ -173,6 +230,7 @@ final class NativeListMediaPreviewSlot {
|
|
|
173
230
|
playerGeneration &+= 1
|
|
174
231
|
itemObservation = nil
|
|
175
232
|
readyObservation = nil
|
|
233
|
+
videoOutput = nil
|
|
176
234
|
player?.pause()
|
|
177
235
|
video.playerLayer.player = nil
|
|
178
236
|
player?.replaceCurrentItem(with: nil)
|
|
@@ -187,6 +245,8 @@ final class NativeListMediaPreviewSlot {
|
|
|
187
245
|
image.recycle()
|
|
188
246
|
image.view.isHidden = false
|
|
189
247
|
video.isHidden = true
|
|
248
|
+
frameView.image = nil
|
|
249
|
+
frameView.isHidden = true
|
|
190
250
|
identity = nil
|
|
191
251
|
result = nil
|
|
192
252
|
completion = nil
|
|
@@ -104,6 +104,14 @@ struct NativeListResolvedText {
|
|
|
104
104
|
return cache
|
|
105
105
|
}()
|
|
106
106
|
|
|
107
|
+
/// Single-line natural width of the full-size text (subscript runs only make it narrower).
|
|
108
|
+
func measureWidth() -> CGFloat {
|
|
109
|
+
guard !text.isEmpty else { return 0 }
|
|
110
|
+
return ceil(attributed(direction: .leftToRight).boundingRect(
|
|
111
|
+
with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude),
|
|
112
|
+
options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).width)
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
func measure(width: CGFloat) -> CGFloat {
|
|
108
116
|
guard !text.isEmpty else { return 0 }
|
|
109
117
|
let width = max(1, width)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
func nativeListAlignedScrollOffset(
|
|
4
|
+
itemStart: CGFloat,
|
|
5
|
+
startInset: CGFloat,
|
|
6
|
+
viewportLength: CGFloat,
|
|
7
|
+
itemLength: CGFloat,
|
|
8
|
+
viewPosition: CGFloat,
|
|
9
|
+
viewOffset: CGFloat,
|
|
10
|
+
nearest: Bool
|
|
11
|
+
) -> CGFloat {
|
|
12
|
+
let alignmentSpace = viewportLength - itemLength
|
|
13
|
+
let resolvedSpace = nearest ? max(0, alignmentSpace) : alignmentSpace
|
|
14
|
+
return itemStart - startInset - viewPosition * resolvedSpace - viewOffset
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
func nativeListClampedScrollOffset(
|
|
18
|
+
_ requestedOffset: CGFloat,
|
|
19
|
+
viewportLength: CGFloat,
|
|
20
|
+
contentLength: CGFloat,
|
|
21
|
+
startInset: CGFloat,
|
|
22
|
+
endInset: CGFloat
|
|
23
|
+
) -> CGFloat {
|
|
24
|
+
let minimum = -startInset
|
|
25
|
+
let maximum = max(minimum, contentLength - viewportLength + endInset)
|
|
26
|
+
return min(maximum, max(minimum, requestedOffset))
|
|
27
|
+
}
|
|
@@ -6,21 +6,34 @@ import UniformTypeIdentifiers
|
|
|
6
6
|
final class NativeListView: UIView {
|
|
7
7
|
private var refreshEmittedForDrag = false
|
|
8
8
|
private var minimumDragOffset: CGFloat = 0
|
|
9
|
-
private var reactContainerSlots: [UIView] = []
|
|
10
9
|
private var containerSlotHeights: [CGFloat] = [0, 0, 0]
|
|
10
|
+
// Fabric keeps assigning each slot root the frame React computed (inset, 0, width, height).
|
|
11
|
+
// Each root therefore lives in a list-owned host whose origin the list alone controls, so a
|
|
12
|
+
// React layout update can never move a slot out of its native position, even for a frame.
|
|
13
|
+
private var reactContainerSlots: [(content: UIView, host: UIView)] = []
|
|
11
14
|
private var lastLaidOutContentHeight: CGFloat?
|
|
12
15
|
private var needsContentShrinkCorrection = false
|
|
13
16
|
private var contentShrinkCorrectionScheduled = false
|
|
14
17
|
|
|
15
18
|
@objc func mountContainerSlot(_ view: UIView, atIndex index: Int) {
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
let host = UIView()
|
|
20
|
+
// Clipping to the reported height keeps new content from overlapping rows until the list
|
|
21
|
+
// has reserved space for it.
|
|
22
|
+
host.clipsToBounds = true
|
|
23
|
+
host.addSubview(view)
|
|
24
|
+
reactContainerSlots.insert((view, host), at: min(index, reactContainerSlots.count))
|
|
25
|
+
collectionView.addSubview(host)
|
|
26
|
+
layoutContainerSlots()
|
|
18
27
|
setNeedsLayout()
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
@objc func unmountContainerSlot(_ view: UIView) {
|
|
22
|
-
reactContainerSlots.removeAll {
|
|
23
|
-
|
|
31
|
+
reactContainerSlots.removeAll { slot in
|
|
32
|
+
guard slot.content === view else { return false }
|
|
33
|
+
view.removeFromSuperview()
|
|
34
|
+
slot.host.removeFromSuperview()
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
func setContainerSlotHeightsJson(_ json: String) {
|
|
@@ -29,11 +42,11 @@ final class NativeListView: UIView {
|
|
|
29
42
|
heights.count == 3, heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
|
|
30
43
|
containerSlotHeights = heights.map { CGFloat($0) }
|
|
31
44
|
if let config { configureLayout(config) }
|
|
45
|
+
layoutContainerSlots()
|
|
32
46
|
setNeedsLayout()
|
|
33
47
|
}
|
|
34
48
|
|
|
35
49
|
private func layoutContainerSlots() {
|
|
36
|
-
guard reactContainerSlots.count == 3 else { return }
|
|
37
50
|
let empty = config?.items.isEmpty ?? true
|
|
38
51
|
let header = containerSlotHeights[0]
|
|
39
52
|
let emptyHeight = empty ? containerSlotHeights[1] : 0
|
|
@@ -43,12 +56,11 @@ final class NativeListView: UIView {
|
|
|
43
56
|
let footerY = max(paddingTop + header + emptyHeight,
|
|
44
57
|
collectionView.contentSize.height - paddingBottom - footer)
|
|
45
58
|
let positions = [paddingTop, paddingTop + header, footerY]
|
|
46
|
-
for (index,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
width:
|
|
51
|
-
height: containerSlotHeights[index])
|
|
59
|
+
for (index, slot) in reactContainerSlots.prefix(3).enumerated() {
|
|
60
|
+
slot.host.isHidden = index == 1 && !empty
|
|
61
|
+
// React places the root at the horizontal inset inside this full-width host.
|
|
62
|
+
slot.host.frame = CGRect(x: 0, y: positions[index],
|
|
63
|
+
width: collectionView.bounds.width, height: containerSlotHeights[index])
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
66
|
|
|
@@ -722,10 +734,15 @@ final class NativeListView: UIView {
|
|
|
722
734
|
} else {
|
|
723
735
|
resolvedPosition = CGFloat(min(1, max(0, viewPosition)))
|
|
724
736
|
}
|
|
725
|
-
let target =
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
737
|
+
let target = nativeListAlignedScrollOffset(
|
|
738
|
+
itemStart: itemStart,
|
|
739
|
+
startInset: startInset,
|
|
740
|
+
viewportLength: viewportLength,
|
|
741
|
+
itemLength: itemLength,
|
|
742
|
+
viewPosition: resolvedPosition,
|
|
743
|
+
viewOffset: CGFloat(viewOffset),
|
|
744
|
+
nearest: alignment == "nearest"
|
|
745
|
+
)
|
|
729
746
|
setScrollOffset(target, animated: animated)
|
|
730
747
|
return true
|
|
731
748
|
}
|
|
@@ -737,12 +754,13 @@ final class NativeListView: UIView {
|
|
|
737
754
|
let contentLength = isHorizontal
|
|
738
755
|
? collectionView.contentSize.width
|
|
739
756
|
: collectionView.contentSize.height
|
|
740
|
-
let
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
contentLength
|
|
757
|
+
let offset = nativeListClampedScrollOffset(
|
|
758
|
+
requestedOffset,
|
|
759
|
+
viewportLength: viewportLength,
|
|
760
|
+
contentLength: contentLength,
|
|
761
|
+
startInset: isHorizontal ? insets.left : insets.top,
|
|
762
|
+
endInset: isHorizontal ? insets.right : insets.bottom
|
|
744
763
|
)
|
|
745
|
-
let offset = min(maximum, max(minimum, requestedOffset))
|
|
746
764
|
let point = isHorizontal
|
|
747
765
|
? CGPoint(x: offset, y: collectionView.contentOffset.y)
|
|
748
766
|
: CGPoint(x: collectionView.contentOffset.x, y: offset)
|
|
@@ -40,4 +40,58 @@ final class NativeListActivityPresentationTests: XCTestCase {
|
|
|
40
40
|
XCTAssertEqual(countBaseline?.doubleValue ?? 0, baseline?.doubleValue ?? 0)
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
func testAutomaticHeightMatchesRenderedStacks() throws {
|
|
45
|
+
let amount: [String: Any] = ["key": "send", "text": "-0.5 ETH", "secondaryText": "$1,000.00"]
|
|
46
|
+
let cases: [(String, [String: Any])] = [
|
|
47
|
+
("stacked single-line", [
|
|
48
|
+
"presentation": "stacked", "description": "Jan 1 • 0x1234…abcd", "amounts": [amount],
|
|
49
|
+
"style": ["horizontalPadding": 20, "verticalPadding": 12, "lineGap": 0,
|
|
50
|
+
"title": ["fontSize": 16, "lineHeight": 24, "fontWeight": "medium", "lines": 1],
|
|
51
|
+
"description": ["fontSize": 14, "lineHeight": 20, "lines": 1]],
|
|
52
|
+
]),
|
|
53
|
+
("table line gap without secondary amount", [
|
|
54
|
+
"presentation": "table", "description": "0x1234…abcd",
|
|
55
|
+
"amounts": [["key": "approve", "text": "Unlimited USDC"]],
|
|
56
|
+
"fee": ["label": "Network fee", "primary": "0.0001 ETH", "secondary": "$0.20"],
|
|
57
|
+
"badges": [["key": "risk", "text": "Scam", "tone": "danger"]],
|
|
58
|
+
"style": ["horizontalPadding": 20, "verticalPadding": 12, "lineGap": 4,
|
|
59
|
+
"title": ["fontSize": 14, "lineHeight": 20, "fontWeight": "medium", "lines": 1],
|
|
60
|
+
"description": ["fontSize": 14, "lineHeight": 20, "lines": 1]],
|
|
61
|
+
]),
|
|
62
|
+
("wrapped description, status and actions", [
|
|
63
|
+
"description": String(repeating: "Contract interaction with a long label ", count: 3),
|
|
64
|
+
"status": "Pending", "amounts": [amount, ["key": "receive", "text": "+1 USDC"]],
|
|
65
|
+
"footerActions": [["key": "speedUp", "label": "Speed up"], ["key": "cancel", "label": "Cancel"]],
|
|
66
|
+
"style": ["lineGap": 6],
|
|
67
|
+
]),
|
|
68
|
+
]
|
|
69
|
+
for (name, fields) in cases {
|
|
70
|
+
var data: [String: Any] = [
|
|
71
|
+
"type": "activity", "key": name, "title": "Send",
|
|
72
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
73
|
+
]
|
|
74
|
+
fields.forEach { data[$0.key] = $0.value }
|
|
75
|
+
let item = try NativeListItem(data: data)
|
|
76
|
+
let width: CGFloat = 390
|
|
77
|
+
let style = data["style"] as? [String: Any] ?? [:]
|
|
78
|
+
let table = data["presentation"] as? String == "table"
|
|
79
|
+
let horizontal = CGFloat(style.double("horizontalPadding", default: table ? 16 : 12))
|
|
80
|
+
let vertical = CGFloat(style.double("verticalPadding", default: 8))
|
|
81
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: width - horizontal * 2, height: 1000))
|
|
82
|
+
let view = NativeListActivityDetailsView()
|
|
83
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
84
|
+
container.addSubview(view)
|
|
85
|
+
NSLayoutConstraint.activate([
|
|
86
|
+
view.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
87
|
+
view.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
88
|
+
view.topAnchor.constraint(equalTo: container.topAnchor),
|
|
89
|
+
])
|
|
90
|
+
view.bind(item, theme: nil)
|
|
91
|
+
container.layoutIfNeeded()
|
|
92
|
+
container.layoutIfNeeded()
|
|
93
|
+
let rendered = ceil(view.frame.height) + vertical * 2
|
|
94
|
+
XCTAssertEqual(NativeListActivityDetailsView.measure(data, width: width), rendered, accuracy: 1, name)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
43
97
|
}
|