@onekeyfe/react-native-native-list 3.0.107 → 3.0.108

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.
@@ -15,6 +15,7 @@ internal class NativeListAdapter(
15
15
  private val context: ThemedReactContext,
16
16
  ) : RecyclerView.Adapter<NativeListViewHolder>() {
17
17
  private var suppressDifferUpdates = false
18
+ private var needsThemeRebind = false
18
19
  private var reorderItems: MutableList<NativeListItem>? = null
19
20
  private val differ = AsyncListDiffer(
20
21
  object : ListUpdateCallback {
@@ -43,6 +44,10 @@ internal class NativeListAdapter(
43
44
  )
44
45
  var usesSelectorSourceScale = false
45
46
  var theme: JSONObject? = null
47
+ set(value) {
48
+ if (field?.toString() != value?.toString()) needsThemeRebind = true
49
+ field = value
50
+ }
46
51
  var layout: String = "linear"
47
52
  var orientation: String = "vertical"
48
53
  var selectedKeys: Set<String> = emptySet()
@@ -117,11 +122,20 @@ internal class NativeListAdapter(
117
122
  (reorderItems ?: differ.currentList).indexOfFirst { it.key == key }
118
123
 
119
124
  fun submitList(items: List<NativeListItem>, commitCallback: (() -> Unit)? = null) {
125
+ // A newer submission can discard the reorder diff and its completion callback.
126
+ suppressDifferUpdates = false
120
127
  if (reorderItems != null) {
121
128
  reorderItems = null
122
129
  notifyDataSetChanged()
123
130
  }
124
- differ.submitList(items.toList()) { commitCallback?.invoke() }
131
+ differ.submitList(items.toList()) {
132
+ // Retain this invalidation across superseded submissions, even when rows are unchanged.
133
+ if (needsThemeRebind) {
134
+ needsThemeRebind = false
135
+ notifyItemRangeChanged(0, itemCount)
136
+ }
137
+ commitCallback?.invoke()
138
+ }
125
139
  }
126
140
 
127
141
  fun moveReordered(from: Int, to: Int): List<NativeListItem>? {
@@ -144,6 +158,7 @@ internal class NativeListAdapter(
144
158
  }
145
159
 
146
160
  fun cancelReorder() {
161
+ suppressDifferUpdates = false
147
162
  if (reorderItems == null) return
148
163
  reorderItems = null
149
164
  notifyDataSetChanged()
@@ -1345,6 +1345,7 @@ class NativeListView(
1345
1345
  val from = dragFrom
1346
1346
  val to = dragTo
1347
1347
  val reordered = pendingReorder
1348
+ var reorderPayload: JSONObject? = null
1348
1349
  val destinationPosition = if (to != RecyclerView.NO_POSITION) {
1349
1350
  to
1350
1351
  } else {
@@ -1384,12 +1385,12 @@ class NativeListView(
1384
1385
  .put("toIndex", to)
1385
1386
  reordered.getOrNull(to - 1)?.let { payload.put("beforeKey", it.key) }
1386
1387
  reordered.getOrNull(to + 1)?.let { payload.put("afterKey", it.key) }
1388
+ reorderPayload = payload
1387
1389
  adapter.commitReordered(reordered) {
1388
1390
  finishCompactWalletGroup()
1389
1391
  if (!wasCompactWalletGroupDrag) {
1390
1392
  recyclerView.postOnAnimation(::relayoutRecyclerViewImmediately)
1391
1393
  }
1392
- emit(REORDER, payload)
1393
1394
  }
1394
1395
  }
1395
1396
  } else {
@@ -1399,6 +1400,8 @@ class NativeListView(
1399
1400
  dragFrom = RecyclerView.NO_POSITION
1400
1401
  dragTo = RecyclerView.NO_POSITION
1401
1402
  pendingReorder = null
1403
+ // The gesture is committed now; a later snapshot may supersede its async diff.
1404
+ reorderPayload?.let { emit(REORDER, it) }
1402
1405
  }
1403
1406
  }
1404
1407
  itemTouchHelper = ItemTouchHelper(callback).also { it.attachToRecyclerView(recyclerView) }
@@ -253,6 +253,7 @@ final class NativeListView: UIView {
253
253
  return
254
254
  }
255
255
  let oldItems = itemsByKey
256
+ let themeChanged = !dictionariesEqual(config?.theme, next.theme)
256
257
  if config?.generation != next.generation { endReachedGeneration = nil }
257
258
  config = next
258
259
  itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
@@ -267,7 +268,7 @@ final class NativeListView: UIView {
267
268
  snapshot.appendItems(keys, toSection: 0)
268
269
  let changedKeys = keys.filter { key in
269
270
  guard let old = oldItems[key], let new = itemsByKey[key] else { return false }
270
- return old.revision != new.revision || old.content != new.content
271
+ return themeChanged || old.revision != new.revision || old.content != new.content
271
272
  }
272
273
  snapshot.reconfigureItems(changedKeys)
273
274
  dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in
@@ -190,7 +190,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
190
190
  emitIndexFailure(-1, 'item-not-found');
191
191
  return;
192
192
  }
193
- dispatchIndexScroll(index, normalizePositionScroll(params, 'start'));
193
+ dispatchKeyScroll(params.item.key, normalizePositionScroll(params, 'start'));
194
194
  },
195
195
  scrollToOffset({
196
196
  offset,
@@ -144,7 +144,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
144
144
  emitIndexFailure(-1, 'item-not-found');
145
145
  return;
146
146
  }
147
- engineRef.current?.scrollToIndex(index, normalizePositionScroll(params, 'start'));
147
+ engineRef.current?.scrollToKey(params.item.key, normalizePositionScroll(params, 'start'));
148
148
  },
149
149
  scrollToOffset({
150
150
  offset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "3.0.107",
3
+ "version": "3.0.108",
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",
@@ -82,7 +82,7 @@
82
82
  "typescript": "^5.9.2"
83
83
  },
84
84
  "peerDependencies": {
85
- "@onekeyfe/react-native-image": "3.0.107",
85
+ "@onekeyfe/react-native-image": "3.0.108",
86
86
  "react": "*",
87
87
  "react-native": "*",
88
88
  "react-native-nitro-modules": "0.37.0"
@@ -328,7 +328,10 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
328
328
  emitIndexFailure(-1, 'item-not-found');
329
329
  return;
330
330
  }
331
- dispatchIndexScroll(index, normalizePositionScroll(params, 'start'));
331
+ dispatchKeyScroll(
332
+ params.item.key,
333
+ normalizePositionScroll(params, 'start')
334
+ );
332
335
  },
333
336
  scrollToOffset({ offset, animated = true }) {
334
337
  validateOffset(offset);
@@ -234,8 +234,8 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
234
234
  emitIndexFailure(-1, 'item-not-found');
235
235
  return;
236
236
  }
237
- engineRef.current?.scrollToIndex(
238
- index,
237
+ engineRef.current?.scrollToKey(
238
+ params.item.key,
239
239
  normalizePositionScroll(params, 'start')
240
240
  );
241
241
  },