@onekeyfe/react-native-native-list 3.0.124 → 3.0.126

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.
@@ -1442,6 +1442,16 @@ internal class NativeListRowView(
1442
1442
  restoreRestingBackground()
1443
1443
  }
1444
1444
 
1445
+ fun canStartWalletGroupReorder(localY: Float): Boolean {
1446
+ if ((tag as? NativeListItem)?.type != "walletGroup") return true
1447
+ walletGroupRows.forEach { row ->
1448
+ if (localY >= row.top && localY < row.bottom) {
1449
+ return (row.tag as? NativeListItem)?.json?.optBoolean("draggable", true) != false
1450
+ }
1451
+ }
1452
+ return true
1453
+ }
1454
+
1445
1455
  fun finishWalletGroupReorder(
1446
1456
  durationMs: Long,
1447
1457
  interpolator: TimeInterpolator,
@@ -1533,11 +1543,14 @@ internal class NativeListRowView(
1533
1543
  }
1534
1544
  }
1535
1545
  if (members.first().has("height")) setPadding(dp(1), dp(1), dp(1), dp(1))
1536
- walletGroupDragChildCount = members.size - 1
1546
+ val childCount = members.size - 1
1547
+ walletGroupDragChildCount = members.drop(1).count {
1548
+ it.optBoolean("draggable", true)
1549
+ }
1537
1550
  walletGroupExpandedHeightPx =
1538
1551
  // OneKey patch: expanded groups include individual wallet badge heights.
1539
1552
  // dp(members.size * 68 + walletGroupDragChildCount * 12)
1540
- dp(members.sumOf { it.optInt("height", if ((it.optJSONArray("badges")?.length() ?: 0) > 0) 92 else 68) } + walletGroupDragChildCount * 12 + if (members.first().has("height")) 2 else 0)
1553
+ dp(members.sumOf { it.optInt("height", if ((it.optJSONArray("badges")?.length() ?: 0) > 0) 92 else 68) } + childCount * 12 + if (members.first().has("height")) 2 else 0)
1541
1554
  walletGroupDragBadgeBackgroundPaint.color = color(
1542
1555
  theme,
1543
1556
  "inverseBackground",
@@ -1839,7 +1839,10 @@ class NativeListView(
1839
1839
  // item.type != "walletGroup" ||
1840
1840
  // event.rawY in holderLocation[1].toFloat()..(holderLocation[1] + dp(68)).toFloat()
1841
1841
  // )
1842
- item.isReorderable
1842
+ item.isReorderable &&
1843
+ (holder as? NativeListViewHolder)?.rowView?.canStartWalletGroupReorder(
1844
+ event.y - holder.itemView.top,
1845
+ ) != false
1843
1846
  } == true
1844
1847
  }
1845
1848
  if (candidate != null) handler.postDelayed(startDrag, REORDER_LONG_PRESS_MS)
@@ -1519,7 +1519,9 @@ final class NativeListCell: UICollectionViewCell {
1519
1519
  checkboxState: checkboxState
1520
1520
  )
1521
1521
  }
1522
- let childCount = item.data.dictionaries("children").count
1522
+ let childCount = item.data.dictionaries("children").filter {
1523
+ ($0["draggable"] as? Bool) != false
1524
+ }.count
1523
1525
  walletGroupDragBadge.text = childCount > 0 ? "+\(childCount)" : nil
1524
1526
  walletGroupDragBadge.isHidden = childCount == 0
1525
1527
  walletGroupDragBadge.backgroundColor = nativeListColor(
@@ -1565,6 +1567,16 @@ final class NativeListCell: UICollectionViewCell {
1565
1567
  isHighlighted = pressed && isUserInteractionEnabled
1566
1568
  }
1567
1569
 
1570
+ func canStartWalletGroupReorder(at point: CGPoint) -> Bool {
1571
+ guard currentItem?.type == "walletGroup" else { return true }
1572
+ let groupPoint = rootStack.convert(point, from: self)
1573
+ for (index, cell) in walletGroupCells.prefix(walletGroupMembers.count).enumerated()
1574
+ where cell.frame.contains(groupPoint) {
1575
+ return (walletGroupMembers[index].data["draggable"] as? Bool) != false
1576
+ }
1577
+ return true
1578
+ }
1579
+
1568
1580
  func setWalletGroupReorderCompact(_ compact: Bool) {
1569
1581
  guard currentItem?.type == "walletGroup" else { return }
1570
1582
  walletGroupCompactAppearanceActive = compact
@@ -66,7 +66,7 @@ final class NativeListView: UIView {
66
66
  private let sectionIndexView = NativeListSectionIndexView()
67
67
  private let sectionIndexPreview = NativeListSectionIndexPreviewView()
68
68
  private var sectionIndexLayoutConstraints: [NSLayoutConstraint] = []
69
- private var sectionIndexWindowHeightConstraint: NSLayoutConstraint?
69
+ private var sectionIndexHostHeightConstraint: NSLayoutConstraint?
70
70
  private var footerHeightConstraint: NSLayoutConstraint!
71
71
  private var dataSource: UICollectionViewDiffableDataSource<Int, String>!
72
72
  private var config: NativeListConfig?
@@ -609,7 +609,8 @@ final class NativeListView: UIView {
609
609
  let indexPath = collectionView.indexPathForItem(at: point),
610
610
  let item = item(at: indexPath),
611
611
  item.isReorderable,
612
- let cell = collectionView.cellForItem(at: indexPath) as? NativeListCell else {
612
+ let cell = collectionView.cellForItem(at: indexPath) as? NativeListCell,
613
+ cell.canStartWalletGroupReorder(at: gesture.location(in: cell)) else {
613
614
  interactiveReorderSource = nil
614
615
  interactiveReorderCell = nil
615
616
  interactiveReorderTargetIndex = nil
@@ -1065,11 +1066,24 @@ final class NativeListView: UIView {
1065
1066
  bounds.width > 0,
1066
1067
  bounds.height > 0,
1067
1068
  isVisibleInHierarchy,
1068
- let window else {
1069
+ let window,
1070
+ let hostView = sectionIndexHostView,
1071
+ hostView.window === window else {
1069
1072
  attachSectionIndexToList()
1070
1073
  return
1071
1074
  }
1072
- attachSectionIndex(to: window)
1075
+ attachSectionIndex(to: hostView)
1076
+ }
1077
+
1078
+ private var sectionIndexHostView: UIView? {
1079
+ var responder: UIResponder? = self
1080
+ while let current = responder {
1081
+ if let viewController = current as? UIViewController {
1082
+ return viewController.view
1083
+ }
1084
+ responder = current.next
1085
+ }
1086
+ return nil
1073
1087
  }
1074
1088
 
1075
1089
  private var isVisibleInHierarchy: Bool {
@@ -1084,7 +1098,7 @@ final class NativeListView: UIView {
1084
1098
  private func attachSectionIndexToList() {
1085
1099
  guard sectionIndexView.superview !== self || sectionIndexLayoutConstraints.isEmpty else { return }
1086
1100
  NSLayoutConstraint.deactivate(sectionIndexLayoutConstraints)
1087
- sectionIndexWindowHeightConstraint = nil
1101
+ sectionIndexHostHeightConstraint = nil
1088
1102
  sectionIndexView.removeFromSuperview()
1089
1103
  addSubview(sectionIndexView)
1090
1104
  sectionIndexLayoutConstraints = [
@@ -1096,20 +1110,20 @@ final class NativeListView: UIView {
1096
1110
  NSLayoutConstraint.activate(sectionIndexLayoutConstraints)
1097
1111
  }
1098
1112
 
1099
- private func attachSectionIndex(to window: UIWindow) {
1100
- let railHeight = sectionIndexView.preferredHeight(constrainedTo: window.bounds.height)
1101
- if sectionIndexView.superview === window {
1102
- sectionIndexWindowHeightConstraint?.constant = railHeight
1113
+ private func attachSectionIndex(to hostView: UIView) {
1114
+ let railHeight = sectionIndexView.preferredHeight(constrainedTo: hostView.bounds.height)
1115
+ if sectionIndexView.superview === hostView {
1116
+ sectionIndexHostHeightConstraint?.constant = railHeight
1103
1117
  return
1104
1118
  }
1105
1119
  NSLayoutConstraint.deactivate(sectionIndexLayoutConstraints)
1106
1120
  sectionIndexView.removeFromSuperview()
1107
- window.addSubview(sectionIndexView)
1121
+ hostView.addSubview(sectionIndexView)
1108
1122
  let heightConstraint = sectionIndexView.heightAnchor.constraint(equalToConstant: railHeight)
1109
- sectionIndexWindowHeightConstraint = heightConstraint
1123
+ sectionIndexHostHeightConstraint = heightConstraint
1110
1124
  sectionIndexLayoutConstraints = [
1111
1125
  sectionIndexView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
1112
- sectionIndexView.centerYAnchor.constraint(equalTo: window.centerYAnchor),
1126
+ sectionIndexView.centerYAnchor.constraint(equalTo: hostView.centerYAnchor),
1113
1127
  sectionIndexView.widthAnchor.constraint(equalToConstant: Self.sectionIndexRailWidth),
1114
1128
  heightConstraint,
1115
1129
  ]
@@ -360,7 +360,13 @@ export function computeWebListLayout(snapshot, viewportWidth, viewportHeight, co
360
360
  };
361
361
  }
362
362
  export function webWalletGroupReorderBadge(row) {
363
- return row.type === 'walletGroup' && row.children.length > 0 ? '+' + String(row.children.length) : undefined;
363
+ const draggableChildCount = row.type === 'walletGroup' ? row.children.filter(child => child.draggable !== false).length : 0;
364
+ return draggableChildCount > 0 ? '+' + String(draggableChildCount) : undefined;
365
+ }
366
+ export function canStartWebWalletGroupReorder(row, memberKey) {
367
+ if (row.type !== 'walletGroup' || !memberKey) return true;
368
+ const member = [row.parent, ...row.children].find(candidate => candidate.key === memberKey);
369
+ return member?.draggable !== false;
364
370
  }
365
371
  function itemStart(item, horizontal) {
366
372
  return horizontal ? item.x : item.y;
@@ -3246,6 +3252,8 @@ export class NativeListWebEngine {
3246
3252
  const index = Number(rowElement?.dataset.nativeListRowIndex);
3247
3253
  const row = this.rows[index];
3248
3254
  if (!row || !this.isReorderable(row)) return;
3255
+ const memberKey = target.closest('[data-native-list-group-member-key]')?.dataset.nativeListGroupMemberKey;
3256
+ if (!canStartWebWalletGroupReorder(row, memberKey)) return;
3249
3257
  // OneKey patch: a child drag reorders its parent wallet group as one item.
3250
3258
  // if (
3251
3259
  // row.type === 'walletGroup' &&
@@ -65,6 +65,7 @@ export declare function hasExceededWebReorderMouseThreshold(deltaX: number, delt
65
65
  export declare function estimateWebRowHeight(row: RowModel, snapshot: NativeListSnapshot, availableWidth: number): number;
66
66
  export declare function computeWebListLayout(snapshot: NativeListSnapshot, viewportWidth: number, viewportHeight: number, compactRowKey?: string): WebListLayout;
67
67
  export declare function webWalletGroupReorderBadge(row: RowModel): string | undefined;
68
+ export declare function canStartWebWalletGroupReorder(row: RowModel, memberKey: string | undefined): boolean;
68
69
  export declare function visibleWebLayoutItems(layout: WebListLayout, offset: number, viewportLength: number, overscan?: number): readonly WebLayoutItem[];
69
70
  export type WebCollapsiblePagerScrollMetrics = Readonly<{
70
71
  offset: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "3.0.124",
3
+ "version": "3.0.126",
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",
@@ -83,8 +83,8 @@
83
83
  "typescript": "^5.9.2"
84
84
  },
85
85
  "peerDependencies": {
86
- "@onekeyfe/react-native-image": "3.0.124",
87
- "@onekeyfe/react-native-native-logger": "3.0.124",
86
+ "@onekeyfe/react-native-image": "3.0.126",
87
+ "@onekeyfe/react-native-native-logger": "3.0.126",
88
88
  "react": "*",
89
89
  "react-native": "*",
90
90
  "react-native-nitro-modules": "0.37.0"
@@ -715,11 +715,26 @@ export function computeWebListLayout(
715
715
  }
716
716
 
717
717
  export function webWalletGroupReorderBadge(row: RowModel): string | undefined {
718
- return row.type === 'walletGroup' && row.children.length > 0
719
- ? '+' + String(row.children.length)
718
+ const draggableChildCount =
719
+ row.type === 'walletGroup'
720
+ ? row.children.filter((child) => child.draggable !== false).length
721
+ : 0;
722
+ return draggableChildCount > 0
723
+ ? '+' + String(draggableChildCount)
720
724
  : undefined;
721
725
  }
722
726
 
727
+ export function canStartWebWalletGroupReorder(
728
+ row: RowModel,
729
+ memberKey: string | undefined
730
+ ): boolean {
731
+ if (row.type !== 'walletGroup' || !memberKey) return true;
732
+ const member = [row.parent, ...row.children].find(
733
+ (candidate) => candidate.key === memberKey
734
+ );
735
+ return member?.draggable !== false;
736
+ }
737
+
723
738
  function itemStart(item: WebLayoutItem, horizontal: boolean): number {
724
739
  return horizontal ? item.x : item.y;
725
740
  }
@@ -5404,6 +5419,10 @@ export class NativeListWebEngine {
5404
5419
  const index = Number(rowElement?.dataset.nativeListRowIndex);
5405
5420
  const row = this.rows[index];
5406
5421
  if (!row || !this.isReorderable(row)) return;
5422
+ const memberKey = target.closest<HTMLElement>(
5423
+ '[data-native-list-group-member-key]'
5424
+ )?.dataset.nativeListGroupMemberKey;
5425
+ if (!canStartWebWalletGroupReorder(row, memberKey)) return;
5407
5426
  // OneKey patch: a child drag reorders its parent wallet group as one item.
5408
5427
  // if (
5409
5428
  // row.type === 'walletGroup' &&