@onekeyfe/react-native-native-list 3.0.157-alpha.262 → 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 CHANGED
@@ -302,7 +302,9 @@ The ref exposes `applySnapshot`, `applyPatches`, `reconcileSelection`,
302
302
  `scrollToKey(key, animated, alignment)` signatures remain supported. Object
303
303
  parameters follow React Native list semantics: `viewPosition` is from `0`
304
304
  (start) through `1` (end), and a positive `viewOffset` leaves space before the
305
- target row.
305
+ target row. Web, Android and iOS explicit position alignment also centers/ends
306
+ oversized rows; `nearest` preserves its legacy behavior. See [scrolling contract](docs/SPEC.md#explicit-scroll-alignment-ok-64041)
307
+ for platform status.
306
308
 
307
309
  Use `initialScrollIndex` or the stable-key extension `initialScrollKey` to set
308
310
  the first position. They are mutually exclusive, run once after the first
@@ -418,3 +420,17 @@ status. See [docs/DESIGN.md](docs/DESIGN.md) for the architecture and ownership
418
420
  tokens, local layout-safety rules, common list capabilities and current implementation
419
421
  gaps. [docs/ROW_TEMPLATES.md](docs/ROW_TEMPLATES.md) defines all 12 row types with
420
422
  structural illustrations, required fields, variants and styling boundaries.
423
+
424
+ ## Native scrolling regression tests
425
+
426
+ In a configured React Native example/consumer Android project, run
427
+ `./gradlew :onekeyfe_react-native-native-list:testDebugUnitTest --tests com.margelo.nitro.nativelist.NativeListScrollAlignmentTest`.
428
+ This uses the existing JUnit dependency and compiles the shipping Kotlin helper
429
+ and NativeListView. The Gradle project name may differ in another consumer.
430
+
431
+ Run `swift test --package-path tests/swiftpm` from this package for the native
432
+ Swift geometry regression suite. Its source symlink compiles the shipping
433
+ helper directly. These are geometry unit tests, not RecyclerView/UICollectionView
434
+ integration tests. Full-app visibility, unmounted/deferred behavior and
435
+ consumer-owned layout/input cancellation require separate runtime validation;
436
+ see [the scrolling spec](docs/SPEC.md).
@@ -0,0 +1,29 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import kotlin.math.roundToInt
4
+
5
+ internal fun nativeListAlignedStart(
6
+ viewportStart: Int,
7
+ viewportLength: Int,
8
+ itemLength: Int,
9
+ viewPosition: Double,
10
+ viewOffset: Int,
11
+ nearest: Boolean,
12
+ ): Int {
13
+ val alignmentSpace = viewportLength - itemLength
14
+ val resolvedSpace = if (nearest) alignmentSpace.coerceAtLeast(0) else alignmentSpace
15
+ return viewportStart + (viewPosition * resolvedSpace).roundToInt() + viewOffset
16
+ }
17
+
18
+ internal fun nativeListProvisionalStart(
19
+ viewportLength: Int,
20
+ viewPosition: Double,
21
+ viewOffset: Int,
22
+ nearest: Boolean,
23
+ ): Int {
24
+ val provisionalOffset = (viewPosition * viewportLength).roundToInt() + viewOffset
25
+ // Keep an explicit target mounted until its measured size can be aligned.
26
+ return if (nearest) provisionalOffset else {
27
+ provisionalOffset.coerceIn(0, (viewportLength - 1).coerceAtLeast(0))
28
+ }
29
+ }
@@ -1179,9 +1179,10 @@ class NativeListView(
1179
1179
  requestedViewPosition.coerceIn(0.0, 1.0)
1180
1180
  }
1181
1181
  val offsetPx = (viewOffset * density).roundToInt()
1182
+ val nearest = alignment == "nearest"
1182
1183
 
1183
1184
  if (visibleView != null) {
1184
- alignVisibleView(manager, visibleView, viewPosition, offsetPx, animated)
1185
+ alignVisibleView(manager, visibleView, viewPosition, offsetPx, animated, nearest)
1185
1186
  return
1186
1187
  }
1187
1188
  if (animated) {
@@ -1191,12 +1192,12 @@ class NativeListView(
1191
1192
 
1192
1193
  override fun calculateDyToMakeVisible(view: View, snapPreference: Int): Int {
1193
1194
  if (manager.orientation != RecyclerView.VERTICAL) return 0
1194
- return smoothAlignmentDelta(manager, view, viewPosition, offsetPx)
1195
+ return smoothAlignmentDelta(manager, view, viewPosition, offsetPx, nearest)
1195
1196
  }
1196
1197
 
1197
1198
  override fun calculateDxToMakeVisible(view: View, snapPreference: Int): Int {
1198
1199
  if (manager.orientation != RecyclerView.HORIZONTAL) return 0
1199
- return smoothAlignmentDelta(manager, view, viewPosition, offsetPx)
1200
+ return smoothAlignmentDelta(manager, view, viewPosition, offsetPx, nearest)
1200
1201
  }
1201
1202
  }
1202
1203
  smoothScroller.targetPosition = scrollPositionForRow(index)
@@ -1204,10 +1205,12 @@ class NativeListView(
1204
1205
  return
1205
1206
  }
1206
1207
 
1207
- val provisionalOffset = (viewPosition * viewportLength(manager)).roundToInt() + offsetPx
1208
- manager.scrollToPositionWithOffset(scrollPositionForRow(index), provisionalOffset)
1208
+ val layoutOffset = nativeListProvisionalStart(
1209
+ viewportLength(manager), viewPosition, offsetPx, nearest,
1210
+ )
1211
+ manager.scrollToPositionWithOffset(scrollPositionForRow(index), layoutOffset)
1209
1212
  relayoutRecyclerView()
1210
- alignAfterLayout(index, viewPosition, offsetPx)
1213
+ alignAfterLayout(index, viewPosition, offsetPx, nearest)
1211
1214
  }
1212
1215
 
1213
1216
  private fun performOffsetScroll(offset: Double, animated: Boolean) {
@@ -1243,6 +1246,7 @@ class NativeListView(
1243
1246
  index: Int,
1244
1247
  viewPosition: Double,
1245
1248
  viewOffset: Int,
1249
+ nearest: Boolean,
1246
1250
  attemptsRemaining: Int = 2,
1247
1251
  ) {
1248
1252
  recyclerView.post {
@@ -1250,11 +1254,11 @@ class NativeListView(
1250
1254
  val view = manager.findViewByPosition(scrollPositionForRow(index))
1251
1255
  if (view == null) {
1252
1256
  if (attemptsRemaining > 0) {
1253
- alignAfterLayout(index, viewPosition, viewOffset, attemptsRemaining - 1)
1257
+ alignAfterLayout(index, viewPosition, viewOffset, nearest, attemptsRemaining - 1)
1254
1258
  }
1255
1259
  return@post
1256
1260
  }
1257
- alignVisibleView(manager, view, viewPosition, viewOffset, false)
1261
+ alignVisibleView(manager, view, viewPosition, viewOffset, false, nearest)
1258
1262
  }
1259
1263
  }
1260
1264
 
@@ -1264,6 +1268,7 @@ class NativeListView(
1264
1268
  viewPosition: Double,
1265
1269
  viewOffset: Int,
1266
1270
  animated: Boolean,
1271
+ nearest: Boolean,
1267
1272
  ) {
1268
1273
  val itemStart = decoratedStart(manager, view)
1269
1274
  val itemLength = decoratedEnd(manager, view) - itemStart
@@ -1272,9 +1277,9 @@ class NativeListView(
1272
1277
  } else {
1273
1278
  manager.paddingLeft
1274
1279
  }
1275
- val targetStart = viewportStart +
1276
- (viewPosition * (viewportLength(manager) - itemLength).coerceAtLeast(0)).roundToInt() +
1277
- viewOffset
1280
+ val targetStart = nativeListAlignedStart(
1281
+ viewportStart, viewportLength(manager), itemLength, viewPosition, viewOffset, nearest,
1282
+ )
1278
1283
  val delta = itemStart - targetStart
1279
1284
  if (manager.orientation == RecyclerView.VERTICAL) {
1280
1285
  if (animated) recyclerView.smoothScrollBy(0, delta) else recyclerView.scrollBy(0, delta)
@@ -1288,6 +1293,7 @@ class NativeListView(
1288
1293
  view: View,
1289
1294
  viewPosition: Double,
1290
1295
  viewOffset: Int,
1296
+ nearest: Boolean,
1291
1297
  ): Int {
1292
1298
  val itemStart = decoratedStart(manager, view)
1293
1299
  val itemLength = decoratedEnd(manager, view) - itemStart
@@ -1296,9 +1302,9 @@ class NativeListView(
1296
1302
  } else {
1297
1303
  manager.paddingLeft
1298
1304
  }
1299
- val targetStart = viewportStart +
1300
- (viewPosition * (viewportLength(manager) - itemLength).coerceAtLeast(0)).roundToInt() +
1301
- viewOffset
1305
+ val targetStart = nativeListAlignedStart(
1306
+ viewportStart, viewportLength(manager), itemLength, viewPosition, viewOffset, nearest,
1307
+ )
1302
1308
  return targetStart - itemStart
1303
1309
  }
1304
1310
 
@@ -0,0 +1,62 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import org.junit.Assert.assertEquals
4
+ import org.junit.Test
5
+
6
+ class NativeListScrollAlignmentTest {
7
+ @Test
8
+ fun oversizedGroupUsesMeasuredSignedSpaceForParentMiddleAndLastMember() {
9
+ // Complete-app measurements: usable viewport 1377px, decorated group 4648px.
10
+ // The caller supplies offsets for the parent and two hidden-wallet members.
11
+ val offsets = listOf(2205, 105, -1995)
12
+ assertEquals(
13
+ listOf(591, -1509, -3609),
14
+ offsets.map { nativeListAlignedStart(21, 1377, 4648, 0.5, it, false) },
15
+ )
16
+ }
17
+
18
+ @Test
19
+ fun explicitStartCenterAndEndPreservePaddingAndSignedOffsets() {
20
+ assertEquals(8, nativeListAlignedStart(8, 400, 870, 0.0, 0, false))
21
+ assertEquals(-227, nativeListAlignedStart(8, 400, 870, 0.5, 0, false))
22
+ assertEquals(-462, nativeListAlignedStart(8, 400, 870, 1.0, 0, false))
23
+ assertEquals(-547, nativeListAlignedStart(8, 400, 870, 0.5, -320, false))
24
+ assertEquals(93, nativeListAlignedStart(8, 400, 870, 0.5, 320, false))
25
+ }
26
+
27
+ @Test
28
+ fun shortAndEqualRowsKeepTheirExistingAlignment() {
29
+ assertEquals(8, nativeListAlignedStart(8, 400, 68, 0.0, 0, false))
30
+ assertEquals(174, nativeListAlignedStart(8, 400, 68, 0.5, 0, false))
31
+ assertEquals(340, nativeListAlignedStart(8, 400, 68, 1.0, 0, false))
32
+ assertEquals(28, nativeListAlignedStart(8, 400, 400, 0.5, 20, false))
33
+ }
34
+
35
+ @Test
36
+ fun nearestRetainsLegacyOversizedAndShortRowBehavior() {
37
+ assertEquals(21, nativeListAlignedStart(21, 1377, 4648, 0.0, 0, true))
38
+ assertEquals(126, nativeListAlignedStart(21, 1377, 4648, 1.0, 105, true))
39
+ assertEquals(174, nativeListAlignedStart(8, 400, 68, 0.5, 0, true))
40
+ }
41
+
42
+ @Test
43
+ fun unmountedExplicitTargetStartsInsideViewportUntilMeasured() {
44
+ assertEquals(1376, nativeListProvisionalStart(1377, 0.5, 2205, false))
45
+ assertEquals(794, nativeListProvisionalStart(1377, 0.5, 105, false))
46
+ assertEquals(0, nativeListProvisionalStart(1377, 0.5, -1995, false))
47
+ assertEquals(1376, nativeListProvisionalStart(1377, 1.0, 0, false))
48
+ }
49
+
50
+ @Test
51
+ fun provisionalBoundaryIsDefinedForEmptyAndOnePixelViewports() {
52
+ assertEquals(0, nativeListProvisionalStart(0, 0.5, 2205, false))
53
+ assertEquals(0, nativeListProvisionalStart(1, 0.5, -1995, false))
54
+ assertEquals(0, nativeListProvisionalStart(1, 1.0, 2205, false))
55
+ }
56
+
57
+ @Test
58
+ fun nearestKeepsItsExistingUnboundedProvisionalPosition() {
59
+ assertEquals(2894, nativeListProvisionalStart(1377, 0.5, 2205, true))
60
+ assertEquals(-1306, nativeListProvisionalStart(1377, 0.5, -1995, true))
61
+ }
62
+ }
package/docs/SPEC.md CHANGED
@@ -619,3 +619,48 @@ tall empty slot with viewport padding, animated decorated-bottom correction,
619
619
  and short footer. These validate geometry, not actual RecyclerView animation or
620
620
  Fabric lifecycle. Native simulator acceptance remains required. The iOS fallback
621
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.
@@ -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
+ }
@@ -734,10 +734,15 @@ final class NativeListView: UIView {
734
734
  } else {
735
735
  resolvedPosition = CGFloat(min(1, max(0, viewPosition)))
736
736
  }
737
- let target = itemStart
738
- - startInset
739
- - resolvedPosition * max(0, viewportLength - itemLength)
740
- - CGFloat(viewOffset)
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
+ )
741
746
  setScrollOffset(target, animated: animated)
742
747
  return true
743
748
  }
@@ -749,12 +754,13 @@ final class NativeListView: UIView {
749
754
  let contentLength = isHorizontal
750
755
  ? collectionView.contentSize.width
751
756
  : collectionView.contentSize.height
752
- let minimum = -(isHorizontal ? insets.left : insets.top)
753
- let maximum = max(
754
- minimum,
755
- contentLength - viewportLength + (isHorizontal ? insets.right : insets.bottom)
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
756
763
  )
757
- let offset = min(maximum, max(minimum, requestedOffset))
758
764
  let point = isHorizontal
759
765
  ? CGPoint(x: offset, y: collectionView.contentOffset.y)
760
766
  : CGPoint(x: collectionView.contentOffset.x, y: offset)
@@ -115,7 +115,9 @@ export function calculateAlignedScrollOffset({
115
115
  if (alignment === 'nearest') {
116
116
  if (itemOffset < currentOffset) resolvedPosition = 0;else if (itemOffset + itemLength > currentOffset + viewportLength) resolvedPosition = 1;else return currentOffset;
117
117
  }
118
- const target = itemOffset - resolvedPosition * Math.max(0, viewportLength - itemLength) - viewOffset;
118
+ const alignmentSpace = viewportLength - itemLength;
119
+ // Explicit positions align oversized rows too; preserve legacy nearest calls.
120
+ const target = itemOffset - resolvedPosition * (alignment === 'nearest' ? Math.max(0, alignmentSpace) : alignmentSpace) - viewOffset;
119
121
  return Math.min(Math.max(0, target), Math.max(0, contentLength - viewportLength));
120
122
  }
121
123
  //# sourceMappingURL=scrolling.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "3.0.157-alpha.262",
3
+ "version": "3.0.157-alpha.273",
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",
@@ -84,8 +84,8 @@
84
84
  "typescript": "^5.9.2"
85
85
  },
86
86
  "peerDependencies": {
87
- "@onekeyfe/react-native-image": "3.0.157-alpha.262",
88
- "@onekeyfe/react-native-native-logger": "3.0.157-alpha.262",
87
+ "@onekeyfe/react-native-image": "3.0.157-alpha.273",
88
+ "@onekeyfe/react-native-native-logger": "3.0.157-alpha.273",
89
89
  "react": "*",
90
90
  "react-native": "*",
91
91
  "react-native-nitro-modules": "0.37.0"
package/src/scrolling.ts CHANGED
@@ -178,9 +178,12 @@ export function calculateAlignedScrollOffset({
178
178
  resolvedPosition = 1;
179
179
  else return currentOffset;
180
180
  }
181
+ const alignmentSpace = viewportLength - itemLength;
182
+ // Explicit positions align oversized rows too; preserve legacy nearest calls.
181
183
  const target =
182
184
  itemOffset -
183
- resolvedPosition * Math.max(0, viewportLength - itemLength) -
185
+ resolvedPosition *
186
+ (alignment === 'nearest' ? Math.max(0, alignmentSpace) : alignmentSpace) -
184
187
  viewOffset;
185
188
  return Math.min(
186
189
  Math.max(0, target),