@onekeyfe/react-native-native-list 6.7.0-49 → 6.7.0-50

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/docs/SPEC.md CHANGED
@@ -1550,15 +1550,37 @@ width React lays it out at. Android's narrow-screen row scale and section-index
1550
1550
  apply to data rows only. Slot React trees own their internal layout and
1551
1551
  business actions; NativeList owns their scroll placement and lifecycle.
1552
1552
 
1553
- The wrapper mounts four non-collapsible slot roots and reports measured
1554
- heights through `containerSlotHeightsJson` in header/empty/footer/sidecar order.
1555
- The sidecar root has zero reserved height when absent. Native validates four
1556
- finite, non-negative heights. Slot updates MUST NOT alter data-row
1557
- keys or public row indices. No per-scroll-frame JS position updates are used.
1553
+ The wrapper mounts six non-collapsible slot roots and reports measured heights
1554
+ through `containerSlotHeightsJson` in header/empty/footer/sidecar/expanded/toggle
1555
+ order. The sidecar root has zero reserved height when absent. Native validates
1556
+ six finite, non-negative heights and still accepts legacy four-number arrays,
1557
+ except for the iOS pending-header state described below. Slot updates MUST NOT
1558
+ alter data-row keys or public row indices. No per-scroll-frame JS position updates are used.
1558
1559
  iOS mounts each slot root inside a list-owned host view in UICollectionView and
1559
1560
  reserves native layout space. The host owns the slot's vertical position and clips to
1560
1561
  the reported height, so React frame updates cannot move a slot out of place and a slot
1561
1562
  whose height has not been reported yet (or has just grown) never draws over rows.
1563
+
1564
+ iOS header first-frame measurement: when `listHeader` is present but
1565
+ its first layout has not arrived, the matching wrapper sends `null` for slot 0
1566
+ instead of an authoritative zero. The other five slot values remain finite,
1567
+ non-negative numbers; Android serialization stays unchanged. On iOS, an absent
1568
+ header always reports numeric zero. Each absent/present boundary replaces only
1569
+ the header slot root and starts a new measurement epoch; a layout callback from
1570
+ an earlier epoch MUST NOT make the current header ready. Replacing header content
1571
+ while it remains present does not start another epoch. A newly present header stays pending
1572
+ until its own layout reports a number, including zero.
1573
+ Before that measurement, the iOS host may reserve the current mounted header
1574
+ root's finite, non-negative `ceil(bounds.height)` when its bounds width is finite
1575
+ and positive. It applies that height to both clipping and row placement in the
1576
+ same native update, regardless of whether the root or pending heights arrive
1577
+ first. Without a valid current root, pending height is zero. Unmounting or
1578
+ recycling the root discards its provisional height; another root cannot inherit
1579
+ it. The first numeric measurement, including a genuine zero, is authoritative
1580
+ and retains ordinary dynamic growth and shrink behavior. Legacy four- and
1581
+ six-number arrays remain accepted. Only header slot 0 may be null, and the
1582
+ wrapper and native binary must match for this pending-header protocol.
1583
+
1562
1584
  Android uses ConcatAdapter with three single-item slot adapters around the existing
1563
1585
  data adapter; adapter binding indices stay local while layout-manager positions
1564
1586
  are explicitly translated. Slots span all grid columns, do not select/reorder,
@@ -31,6 +31,8 @@ final class NativeListView: UIView {
31
31
  private var refreshEmittedForDrag = false
32
32
  private var minimumDragOffset: CGFloat = 0
33
33
  private var containerSlotHeights: [CGFloat] = [0, 0, 0, 0, 0, 0]
34
+ private var containerHeaderHeightIsAuthoritative = false
35
+ private weak var currentHeaderRoot: UIView?
34
36
  private var disclosureCVisibleHeight: CGFloat = 0
35
37
  private var disclosureInset: CGFloat = 0
36
38
  private var disclosureStartCHeight: CGFloat = 0
@@ -295,6 +297,10 @@ final class NativeListView: UIView {
295
297
  host.addSubview(view)
296
298
  reactContainerSlots.insert((view, host), at: min(index, reactContainerSlots.count))
297
299
  collectionView.addSubview(host)
300
+ if index == 0 {
301
+ currentHeaderRoot = view
302
+ if !containerHeaderHeightIsAuthoritative { updatePendingHeaderHeight() }
303
+ }
298
304
  layoutContainerSlots()
299
305
  setNeedsLayout()
300
306
  }
@@ -306,12 +312,17 @@ final class NativeListView: UIView {
306
312
  updateTopScrollEdge()
307
313
  return
308
314
  }
315
+ let removedCurrentHeader = currentHeaderRoot === view
316
+ if removedCurrentHeader { currentHeaderRoot = nil }
309
317
  reactContainerSlots.removeAll { slot in
310
318
  guard slot.content === view else { return false }
311
319
  view.removeFromSuperview()
312
320
  slot.host.removeFromSuperview()
313
321
  return true
314
322
  }
323
+ if removedCurrentHeader && !containerHeaderHeightIsAuthoritative {
324
+ updatePendingHeaderHeight()
325
+ }
315
326
  }
316
327
 
317
328
  func setTopScrollEdge(effect: NativeListTopScrollEdgeEffect, overlayHeight: CGFloat) {
@@ -376,12 +387,37 @@ final class NativeListView: UIView {
376
387
 
377
388
  func setContainerSlotHeightsJson(_ json: String, followedBySnapshot: Bool = false) {
378
389
  guard let data = json.data(using: .utf8),
379
- let heights = try? JSONSerialization.jsonObject(with: data) as? [Double],
380
- (heights.count == 4 || heights.count == 6),
390
+ var values = try? JSONSerialization.jsonObject(with: data) as? [Any],
391
+ (values.count == 4 || values.count == 6) else { return }
392
+ let headerPending = values[0] is NSNull
393
+ if headerPending { values[0] = 0.0 }
394
+ guard let heights = values as? [Double],
381
395
  heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
396
+ containerHeaderHeightIsAuthoritative = !headerPending
397
+ var next = heights.map { CGFloat($0) } + (heights.count == 4 ? [0, 0] : [])
398
+ if headerPending { next[0] = pendingHeaderHeight() }
399
+ applyContainerSlotHeights(next, followedBySnapshot: followedBySnapshot)
400
+ }
401
+
402
+ private func pendingHeaderHeight() -> CGFloat {
403
+ guard let bounds = currentHeaderRoot?.bounds,
404
+ bounds.width.isFinite, bounds.width > 0,
405
+ bounds.height.isFinite, bounds.height >= 0 else { return 0 }
406
+ return ceil(bounds.height)
407
+ }
408
+
409
+ private func updatePendingHeaderHeight() {
410
+ let height = pendingHeaderHeight()
411
+ guard height != containerSlotHeights[0] else { return }
412
+ var next = containerSlotHeights
413
+ next[0] = height
414
+ applyContainerSlotHeights(next)
415
+ }
416
+
417
+ private func applyContainerSlotHeights(_ heights: [CGFloat], followedBySnapshot: Bool = false) {
382
418
  let previousHeights = containerSlotHeights
383
- let footerDelta = containerSlotHeights[2] - CGFloat(heights[2])
384
- containerSlotHeights = heights.map { CGFloat($0) } + (heights.count == 4 ? [0, 0] : [])
419
+ let footerDelta = containerSlotHeights[2] - heights[2]
420
+ containerSlotHeights = heights
385
421
  let contentHeightChanged = previousHeights[4] != containerSlotHeights[4]
386
422
  let toggleHeightChanged = previousHeights[5] != containerSlotHeights[5]
387
423
  let disclosureGeometryInvalid = structuralTail != nil && config?.disclosure != nil
@@ -3085,6 +3121,9 @@ final class NativeListView: UIView {
3085
3121
  dataSource = nil
3086
3122
 
3087
3123
  config = nil
3124
+ currentHeaderRoot = nil
3125
+ containerHeaderHeightIsAuthoritative = false
3126
+ containerSlotHeights[0] = 0
3088
3127
  acceptedRowIndex = nil
3089
3128
  pagerStickyHeights.removeAllObjects()
3090
3129
  for slot in reactContainerSlots { slot.host.layer.mask = nil }
@@ -1228,7 +1228,9 @@ final class NativeListLifecycleTests: XCTestCase {
1228
1228
  list.layoutIfNeeded()
1229
1229
  let header = try XCTUnwrap(slots[0].superview)
1230
1230
  XCTAssertTrue(header.clipsToBounds)
1231
- XCTAssertEqual(header.bounds.height, 0, "An unmeasured header cannot draw over the first rows")
1231
+ XCTAssertEqual(header.bounds.height, 44, "The mounted Fabric header reserves its first-frame height")
1232
+ let firstRow = try XCTUnwrap(list.layoutAttributesForItem(at: IndexPath(item: 0, section: 0)))
1233
+ XCTAssertEqual(firstRow.frame.minY, 44, accuracy: 0.5)
1232
1234
 
1233
1235
  view.setContainerSlotHeightsJson("[44,44,60,0]")
1234
1236
  view.layoutIfNeeded()
@@ -1245,6 +1247,99 @@ final class NativeListLifecycleTests: XCTestCase {
1245
1247
  XCTAssertNil(slots[2].superview)
1246
1248
  }
1247
1249
 
1250
+ func testPendingHeaderReservesMountedGeometryInEitherPropertyOrder() throws {
1251
+ for pendingBeforeMount in [true, false] {
1252
+ let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
1253
+ view.applySnapshotJson(try scrollingSnapshot(count: 3))
1254
+ let header = UIView(frame: CGRect(x: 16, y: 0, width: 288, height: 44.2))
1255
+ if pendingBeforeMount { view.setContainerSlotHeightsJson("[null,0,0,0,0,0]") }
1256
+ view.mountContainerSlot(header, atIndex: 0)
1257
+ if !pendingBeforeMount { view.setContainerSlotHeightsJson("[null,0,0,0,0,0]") }
1258
+ view.layoutIfNeeded()
1259
+ let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
1260
+ list.layoutIfNeeded()
1261
+ let host = try XCTUnwrap(header.superview)
1262
+ XCTAssertTrue(host.clipsToBounds)
1263
+ XCTAssertEqual(host.bounds.height, 45, accuracy: 0.5)
1264
+ let firstRow = try XCTUnwrap(list.layoutAttributesForItem(at: IndexPath(item: 0, section: 0)))
1265
+ XCTAssertEqual(firstRow.frame.minY, 45, accuracy: 0.5)
1266
+
1267
+ view.setContainerSlotHeightsJson("[null,0,18,0,0,0]")
1268
+ view.layoutIfNeeded()
1269
+ list.layoutIfNeeded()
1270
+ XCTAssertEqual(host.bounds.height, 45, accuracy: 0.5)
1271
+ XCTAssertEqual(list.layoutAttributesForItem(
1272
+ at: IndexPath(item: 0, section: 0))?.frame.minY, 45)
1273
+
1274
+ view.setContainerSlotHeightsJson("[18,0,0,0,0,0]")
1275
+ view.layoutIfNeeded()
1276
+ list.layoutIfNeeded()
1277
+ XCTAssertEqual(host.bounds.height, 18, accuracy: 0.5)
1278
+ XCTAssertEqual(list.collectionViewLayout.layoutAttributesForItem(
1279
+ at: IndexPath(item: 0, section: 0))?.frame.minY, 18)
1280
+ view.setContainerSlotHeightsJson("[0,0,0,0,0,0]")
1281
+ view.layoutIfNeeded()
1282
+ list.layoutIfNeeded()
1283
+ XCTAssertEqual(host.bounds.height, 0)
1284
+ XCTAssertEqual(list.collectionViewLayout.layoutAttributesForItem(
1285
+ at: IndexPath(item: 0, section: 0))?.frame.minY, 0)
1286
+ view.dispose()
1287
+ }
1288
+ }
1289
+
1290
+ func testNumericHeaderHeightIsAuthoritativeBeforeRootMounts() throws {
1291
+ for height in [0, 24] {
1292
+ let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
1293
+ view.setContainerSlotHeightsJson("[\(height),0,0,0]")
1294
+ view.applySnapshotJson(try scrollingSnapshot(count: 3))
1295
+ let header = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 44))
1296
+ view.mountContainerSlot(header, atIndex: 0)
1297
+ view.layoutIfNeeded()
1298
+ let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
1299
+ list.layoutIfNeeded()
1300
+ XCTAssertEqual(header.superview?.bounds.height, CGFloat(height))
1301
+ XCTAssertEqual(list.layoutAttributesForItem(
1302
+ at: IndexPath(item: 0, section: 0))?.frame.minY, CGFloat(height))
1303
+ view.dispose()
1304
+ }
1305
+ }
1306
+
1307
+ func testPendingHeaderDoesNotInheritAnUnmountedRootsHeight() throws {
1308
+ let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
1309
+ view.applySnapshotJson(try scrollingSnapshot(count: 3))
1310
+ view.setContainerSlotHeightsJson("[null,0,0,0,0,0]")
1311
+ let first = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 44))
1312
+ view.mountContainerSlot(first, atIndex: 0)
1313
+ XCTAssertEqual(first.superview?.bounds.height, 44)
1314
+ view.unmountContainerSlot(first)
1315
+ let empty = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 0))
1316
+ view.mountContainerSlot(empty, atIndex: 0)
1317
+ XCTAssertEqual(empty.superview?.bounds.height, 0)
1318
+ view.unmountContainerSlot(empty)
1319
+ let replacement = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 27))
1320
+ view.mountContainerSlot(replacement, atIndex: 0)
1321
+ XCTAssertEqual(replacement.superview?.bounds.height, 27)
1322
+ view.setContainerSlotHeightsJson("[0,0,0,0,0,0]")
1323
+ view.unmountContainerSlot(replacement)
1324
+ let authoritativeZero = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
1325
+ view.mountContainerSlot(authoritativeZero, atIndex: 0)
1326
+ XCTAssertEqual(authoritativeZero.superview?.bounds.height, 0)
1327
+ view.dispose()
1328
+ }
1329
+
1330
+ func testPendingHeaderOnlyAcceptsNullAtTheHeaderSlot() throws {
1331
+ let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
1332
+ view.setContainerSlotHeightsJson("[24,0,0,0,0,0]")
1333
+ let header = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 44))
1334
+ view.mountContainerSlot(header, atIndex: 0)
1335
+ for invalid in ["[null,null,0,0,0,0]", "[\"invalid\",0,0,0,0,0]",
1336
+ "[null,0,0,0,-1,0]", "[null,0,0,0,0,null]"] {
1337
+ view.setContainerSlotHeightsJson(invalid)
1338
+ XCTAssertEqual(header.superview?.bounds.height, 24)
1339
+ }
1340
+ view.dispose()
1341
+ }
1342
+
1248
1343
  func testSidecarCentersRowsWhenConfiguredBeforeFirstWidth() throws {
1249
1344
  try assertHomeSidecarGeometry(sidecarBeforeFirstLayout: true)
1250
1345
  }
@@ -91,10 +91,21 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
91
91
  }
92
92
  const expandedEpoch = disclosureSlotMounts.current.expandedEpoch;
93
93
  const toggleEpoch = disclosureSlotMounts.current.toggleEpoch;
94
+ const iosHeaderPresent = Platform.OS === 'ios' && listHeader != null;
94
95
  const [slotMeasurements, setSlotMeasurements] = useState({
95
96
  heights: [0, 0, 0, 0, 0, 0],
96
- readyEpochs: [-1, -1, -1, -1, -1, -1]
97
+ readyEpochs: [-1, -1, -1, -1, -1, -1],
98
+ iosHeaderPresent,
99
+ headerEpoch: 0
97
100
  });
101
+ if (slotMeasurements.iosHeaderPresent !== iosHeaderPresent) {
102
+ setSlotMeasurements({
103
+ ...slotMeasurements,
104
+ iosHeaderPresent,
105
+ headerEpoch: slotMeasurements.headerEpoch + 1
106
+ });
107
+ }
108
+ const headerEpoch = slotMeasurements.headerEpoch;
98
109
  const hasSidecar = listSidecar !== undefined;
99
110
  const sidecarWidth = sidecarLayout?.width;
100
111
  const sidecarGap = sidecarLayout?.gap;
@@ -155,7 +166,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
155
166
  const [viewportWidth, setViewportWidth] = useState(0);
156
167
  const [topOverlayHeight, setTopOverlayHeight] = useState(0);
157
168
  const hasTopOverlay = Platform?.OS === 'ios' && parseInt(String(Platform.Version), 10) >= 26 && (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') && topOverlay != null;
158
- const containerSlotHeightsJson = JSON.stringify(slotHeights);
169
+ const containerSlotHeightsJson = JSON.stringify(Platform.OS === 'ios' && (!iosHeaderPresent || slotMeasurements.readyEpochs[0] !== headerEpoch) ? [iosHeaderPresent ? null : 0, ...slotHeights.slice(1)] : slotHeights);
159
170
  const defaultSlotInset = snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0;
160
171
  const bandWidth = sidecarLayout ? Math.min(viewportWidth, sidecarLayout.maxContentWidth) : 0;
161
172
  const slotInset = sidecarLayout ? Math.max(0, (viewportWidth - bandWidth) / 2) + defaultSlotInset : defaultSlotInset;
@@ -166,6 +177,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
166
177
  return;
167
178
  }
168
179
  setSlotMeasurements(previous => {
180
+ if (index === 0 && epoch !== previous.headerEpoch) return previous;
169
181
  if (previous.heights[index] === height && previous.readyEpochs[index] === epoch) {
170
182
  return previous;
171
183
  }
@@ -174,6 +186,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
174
186
  heights[index] = height;
175
187
  readyEpochs[index] = epoch;
176
188
  return {
189
+ ...previous,
177
190
  heights,
178
191
  readyEpochs
179
192
  };
@@ -521,7 +534,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
521
534
  },
522
535
  onLayout: event => {
523
536
  if (index < 4) {
524
- recordSlotLayout(index, Math.ceil(event.nativeEvent.layout.height), 0);
537
+ recordSlotLayout(index, Math.ceil(event.nativeEvent.layout.height), index === 0 ? headerEpoch : 0);
525
538
  }
526
539
  },
527
540
  children: index >= 4 ? /*#__PURE__*/_jsx(View, {
@@ -530,7 +543,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
530
543
  onLayout: event => recordSlotLayout(index, Math.ceil(event.nativeEvent.layout.height), index === 4 ? expandedEpoch : toggleEpoch),
531
544
  children: content
532
545
  }, index === 4 ? `expanded-${expandedEpoch}` : `toggle-${toggleEpoch}`) : content
533
- }, index)), hasTopOverlay ? /*#__PURE__*/_jsx(View, {
546
+ }, index === 0 && Platform.OS === 'ios' ? `header-${headerEpoch}` : index)), hasTopOverlay ? /*#__PURE__*/_jsx(View, {
534
547
  collapsable: false,
535
548
  style: {
536
549
  position: 'absolute',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "6.7.0-49",
3
+ "version": "6.7.0-50",
4
4
  "description": "Template-driven native RecyclerView and UICollectionView for React Native",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",
@@ -185,10 +185,21 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
185
185
  }
186
186
  const expandedEpoch = disclosureSlotMounts.current.expandedEpoch;
187
187
  const toggleEpoch = disclosureSlotMounts.current.toggleEpoch;
188
+ const iosHeaderPresent = Platform.OS === 'ios' && listHeader != null;
188
189
  const [slotMeasurements, setSlotMeasurements] = useState({
189
190
  heights: [0, 0, 0, 0, 0, 0],
190
191
  readyEpochs: [-1, -1, -1, -1, -1, -1],
192
+ iosHeaderPresent,
193
+ headerEpoch: 0,
191
194
  });
195
+ if (slotMeasurements.iosHeaderPresent !== iosHeaderPresent) {
196
+ setSlotMeasurements({
197
+ ...slotMeasurements,
198
+ iosHeaderPresent,
199
+ headerEpoch: slotMeasurements.headerEpoch + 1,
200
+ });
201
+ }
202
+ const headerEpoch = slotMeasurements.headerEpoch;
192
203
  const hasSidecar = listSidecar !== undefined;
193
204
  const sidecarWidth = sidecarLayout?.width;
194
205
  const sidecarGap = sidecarLayout?.gap;
@@ -321,7 +332,12 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
321
332
  parseInt(String(Platform.Version), 10) >= 26 &&
322
333
  (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') &&
323
334
  topOverlay != null;
324
- const containerSlotHeightsJson = JSON.stringify(slotHeights);
335
+ const containerSlotHeightsJson = JSON.stringify(
336
+ Platform.OS === 'ios' &&
337
+ (!iosHeaderPresent || slotMeasurements.readyEpochs[0] !== headerEpoch)
338
+ ? [iosHeaderPresent ? null : 0, ...slotHeights.slice(1)]
339
+ : slotHeights
340
+ );
325
341
  const defaultSlotInset =
326
342
  snapshot.layout.contentPaddingHorizontal ??
327
343
  snapshot.layout.contentPadding ??
@@ -351,6 +367,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
351
367
  return;
352
368
  }
353
369
  setSlotMeasurements((previous) => {
370
+ if (index === 0 && epoch !== previous.headerEpoch) return previous;
354
371
  if (
355
372
  previous.heights[index] === height &&
356
373
  previous.readyEpochs[index] === epoch
@@ -361,7 +378,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
361
378
  const readyEpochs = [...previous.readyEpochs];
362
379
  heights[index] = height;
363
380
  readyEpochs[index] = epoch;
364
- return { heights, readyEpochs };
381
+ return { ...previous, heights, readyEpochs };
365
382
  });
366
383
  };
367
384
  const sidecarLayoutJson = sidecarLayout
@@ -835,7 +852,11 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
835
852
  >
836
853
  {slotContents.map((content, index) => (
837
854
  <View
838
- key={index}
855
+ key={
856
+ index === 0 && Platform.OS === 'ios'
857
+ ? `header-${headerEpoch}`
858
+ : index
859
+ }
839
860
  collapsable={false}
840
861
  style={{
841
862
  position: 'absolute',
@@ -849,7 +870,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
849
870
  recordSlotLayout(
850
871
  index,
851
872
  Math.ceil(event.nativeEvent.layout.height),
852
- 0
873
+ index === 0 ? headerEpoch : 0
853
874
  );
854
875
  }
855
876
  }}