@onekeyfe/react-native-native-list 3.0.135 → 3.0.136

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.
@@ -395,6 +395,30 @@ private class NativeListTableColumnView(context: android.content.Context) : Line
395
395
  private fun sp(value: Float): Float = NativeListScale.font(resources, value)
396
396
  }
397
397
 
398
+ private object NativeListSourceFallbackState {
399
+ private const val CACHE_LIMIT = 128
400
+ private val sources = LinkedHashMap<String, Unit>(CACHE_LIMIT, 0.75f, true)
401
+
402
+ fun has(key: String): Boolean = synchronized(sources) {
403
+ sources[key] != null
404
+ }
405
+
406
+ fun remember(key: String) {
407
+ synchronized(sources) {
408
+ sources[key] = Unit
409
+ while (sources.size > CACHE_LIMIT) {
410
+ sources.remove(sources.entries.first().key)
411
+ }
412
+ }
413
+ }
414
+
415
+ fun forget(key: String) {
416
+ synchronized(sources) {
417
+ sources.remove(key)
418
+ }
419
+ }
420
+ }
421
+
398
422
  internal class NativeListRowView(
399
423
  private val reactContext: ThemedReactContext,
400
424
  ) : LinearLayout(reactContext) {
@@ -1372,6 +1396,7 @@ internal class NativeListRowView(
1372
1396
  leadingIcon.visibility = GONE
1373
1397
  leadingIcon.iconName = ""
1374
1398
  leadingIcon.layoutParams = FrameLayout.LayoutParams(dp(18), dp(18), Gravity.CENTER)
1399
+ leadingIcon.glyphSizeDp = null
1375
1400
  favoriteIcon.visibility = GONE
1376
1401
  favoriteIcon.iconName = ""
1377
1402
  headerTitleIcon.visibility = GONE
@@ -3214,13 +3239,27 @@ internal class NativeListRowView(
3214
3239
  val cornerIconData = visual.optJSONObject("cornerIcon")
3215
3240
  val fallback = visual.optString("fallbackText").take(2)
3216
3241
  val fallbackIconData = visual.optJSONObject("fallbackIcon")
3242
+ val fallbackIconSizeDp = fallbackIconData?.let {
3243
+ val slotSizeDp = minOf(sizeDp, heightDp)
3244
+ if (it.optString("name") == "GlobusOutline") {
3245
+ (slotSizeDp * 1.2f).roundToInt()
3246
+ } else {
3247
+ slotSizeDp
3248
+ }
3249
+ }
3217
3250
  val sourceLoadingStrategy = sources.firstOrNull()?.first?.optString("loadingStrategy", "none") ?: "none"
3218
3251
  val showsSourcePlaceholder = !isIcon && sources.isNotEmpty() && sourceLoadingStrategy != "none"
3219
3252
  val handlesSourceFallback =
3220
3253
  !isIcon && sources.isNotEmpty() &&
3221
3254
  showsSourcePlaceholder &&
3222
3255
  (visual.has("fallbackText") || fallbackIconData != null)
3223
- leadingFallback.text = if (handlesSourceFallback) "" else fallback
3256
+ val sourceFallbackKey = if (handlesSourceFallback) {
3257
+ sources.firstOrNull()?.first?.let(::sourceFallbackStateKey)
3258
+ } else null
3259
+ val restoresSourceFallback =
3260
+ sourceFallbackKey?.let(NativeListSourceFallbackState::has) == true
3261
+ leadingFallback.text =
3262
+ if (handlesSourceFallback && !restoresSourceFallback) "" else fallback
3224
3263
  leadingFallback.setTextColor(parseNativeListColor("#00000072"))
3225
3264
  val visualBackground = safeColor(
3226
3265
  visual.optString("backgroundColor"),
@@ -3239,6 +3278,23 @@ internal class NativeListRowView(
3239
3278
  )
3240
3279
  leadingFallback.visibility =
3241
3280
  if (!isIcon && (sources.isEmpty() || handlesSourceFallback)) VISIBLE else GONE
3281
+ if (handlesSourceFallback && fallbackIconData != null) {
3282
+ leadingIcon.iconName = fallbackIconData.optString("name")
3283
+ leadingIcon.tintColor = safeColor(
3284
+ fallbackIconData.optString("tintColor"),
3285
+ parseNativeListColor("#0000009B"),
3286
+ )
3287
+ leadingIcon.layoutParams = FrameLayout.LayoutParams(
3288
+ dp(fallbackIconSizeDp ?: sizeDp),
3289
+ dp(fallbackIconSizeDp ?: heightDp),
3290
+ Gravity.CENTER,
3291
+ )
3292
+ leadingIcon.glyphSizeDp = fallbackIconSizeDp
3293
+ // Keep the fallback measured while the source loads so an asynchronous
3294
+ // failure can reveal it without waiting for another RecyclerView layout.
3295
+ leadingFallback.visibility = if (restoresSourceFallback) GONE else VISIBLE
3296
+ leadingIcon.visibility = if (restoresSourceFallback) VISIBLE else INVISIBLE
3297
+ }
3242
3298
  if (isIcon) {
3243
3299
  leadingFrame.background = GradientDrawable().apply {
3244
3300
  setColor(visualBackground)
@@ -3258,6 +3314,12 @@ internal class NativeListRowView(
3258
3314
  fallbackIconData.optString("tintColor"),
3259
3315
  parseNativeListColor("#0000009B"),
3260
3316
  )
3317
+ leadingIcon.layoutParams = FrameLayout.LayoutParams(
3318
+ dp(fallbackIconSizeDp ?: sizeDp),
3319
+ dp(fallbackIconSizeDp ?: heightDp),
3320
+ Gravity.CENTER,
3321
+ )
3322
+ leadingIcon.glyphSizeDp = fallbackIconSizeDp
3261
3323
  leadingIcon.visibility = VISIBLE
3262
3324
  }
3263
3325
  val visibleSources = sources.take(leadingImages.size)
@@ -3356,6 +3418,7 @@ internal class NativeListRowView(
3356
3418
  bindImage(source, image, boundKey ?: "", index, variant,
3357
3419
  onLoad = if (!ownsSourceFallback) null else ({
3358
3420
  if (bindingEpoch == expectedEpoch) {
3421
+ sourceFallbackKey?.let(NativeListSourceFallbackState::forget)
3359
3422
  image.visibility = VISIBLE
3360
3423
  leadingFallback.visibility = GONE
3361
3424
  leadingIcon.visibility = GONE
@@ -3363,6 +3426,7 @@ internal class NativeListRowView(
3363
3426
  }),
3364
3427
  onError = if (!ownsSourceFallback) null else ({
3365
3428
  if (bindingEpoch == expectedEpoch) {
3429
+ sourceFallbackKey?.let(NativeListSourceFallbackState::remember)
3366
3430
  image.visibility = GONE
3367
3431
  if (fallbackIcon != null) {
3368
3432
  leadingFallback.visibility = GONE
@@ -3473,6 +3537,11 @@ internal class NativeListRowView(
3473
3537
  }
3474
3538
  }
3475
3539
 
3540
+ private fun sourceFallbackStateKey(source: JSONObject): String? =
3541
+ source.optString("uri").trim().takeIf(String::isNotEmpty)?.let { uri ->
3542
+ "$uri\u0000${source.optJSONObject("headers")?.toString().orEmpty()}"
3543
+ }
3544
+
3476
3545
  private fun leadingImageLayout(
3477
3546
  index: Int,
3478
3547
  count: Int,
@@ -4159,8 +4228,10 @@ internal class NativeListRowView(
4159
4228
  val uri = source.optString("uri").trim().takeIf(String::isNotEmpty)
4160
4229
  val sourceHeadersJson = source.optJSONObject("headers")?.toString()
4161
4230
  val recyclingKey = if (retryAttempt == 0) "$token:$slot" else "$token:$slot:retry:$retryAttempt"
4162
- if (hideUntilLoaded && !imageView.isDisplaying(uri, sourceHeadersJson, recyclingKey)) {
4163
- imageView.visibility = INVISIBLE
4231
+ if (hideUntilLoaded) {
4232
+ imageView.visibility = if (
4233
+ imageView.isDisplaying(uri, sourceHeadersJson, recyclingKey)
4234
+ ) VISIBLE else INVISIBLE
4164
4235
  }
4165
4236
  val handleLoad: (() -> Unit)? = if (hideUntilLoaded) ({
4166
4237
  if (bindingEpoch == expectedEpoch) {
@@ -4194,8 +4265,8 @@ internal class NativeListRowView(
4194
4265
  }),
4195
4266
  onError = if (retryLimit == 0) handleError else ({
4196
4267
  if (bindingEpoch == expectedEpoch) {
4197
- if (retryAttempt >= retryLimit) handleError?.invoke()
4198
- else if (!selectorImageRetries.containsKey(imageView)) {
4268
+ handleError?.invoke()
4269
+ if (retryAttempt < retryLimit && !selectorImageRetries.containsKey(imageView)) {
4199
4270
  val retry = Runnable {
4200
4271
  if (bindingEpoch == expectedEpoch) {
4201
4272
  selectorImageRetries.remove(imageView)
@@ -53,6 +53,24 @@ import kotlin.math.roundToInt
53
53
  import kotlin.math.sin
54
54
  import kotlin.math.sqrt
55
55
 
56
+ private class NativeListGridLayoutManager(
57
+ context: Context,
58
+ spanCount: Int,
59
+ ) : GridLayoutManager(context, spanCount) {
60
+ override fun removeAndRecycleViewAt(index: Int, recycler: RecyclerView.Recycler) {
61
+ val child = getChildAt(index) ?: return
62
+ removeViewAt(index)
63
+ // An index-based removal can leave the selected child attached during rapid
64
+ // nested scrolling. Detach that exact view before giving it to RecyclerView.
65
+ if (child.parent != null) removeView(child)
66
+ if (child.parent == null) {
67
+ recycler.recycleView(child)
68
+ } else {
69
+ requestLayout()
70
+ }
71
+ }
72
+ }
73
+
56
74
  class NativeListView(
57
75
  private val reactContext: ThemedReactContext,
58
76
  ) : LinearLayout(reactContext) {
@@ -110,7 +128,7 @@ class NativeListView(
110
128
  private var refreshIndicatorOffsetPx = 0
111
129
  private val contentContainer = FrameLayout(context)
112
130
  private val adapter = NativeListAdapter(reactContext)
113
- private val layoutManager = GridLayoutManager(context, 1)
131
+ private val layoutManager = NativeListGridLayoutManager(context, 1)
114
132
  // OneKey patch: vertical lists retain vertical drags and leave horizontal drags to a parent pager.
115
133
  private val pagerGestureTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
116
134
  private var pagerGestureIsVertical = false
@@ -4,6 +4,26 @@ import CoreText
4
4
  import OneKeyImage
5
5
  import UIKit
6
6
 
7
+ private enum NativeListSourceFallbackState {
8
+ private static let sources: NSCache<NSString, NSNumber> = {
9
+ let cache = NSCache<NSString, NSNumber>()
10
+ cache.countLimit = 128
11
+ return cache
12
+ }()
13
+
14
+ static func has(_ key: String) -> Bool {
15
+ sources.object(forKey: key as NSString) != nil
16
+ }
17
+
18
+ static func remember(_ key: String) {
19
+ sources.setObject(NSNumber(value: true), forKey: key as NSString)
20
+ }
21
+
22
+ static func forget(_ key: String) {
23
+ sources.removeObject(forKey: key as NSString)
24
+ }
25
+ }
26
+
7
27
  // Market/TokenListSkeleton: source geometry and the native Skeleton's 3s shimmer.
8
28
  private final class NativeListMarketSkeleton: UIView {
9
29
  private let marks = (0..<5).map { _ in UIView() }
@@ -3408,12 +3428,20 @@ final class NativeListCell: UICollectionViewCell {
3408
3428
  let cornerIcon = visual.dictionary("cornerIcon")
3409
3429
  let fallbackText = String(visual.string("fallbackText").prefix(2))
3410
3430
  let fallbackIconData = visual.dictionary("fallbackIcon")
3431
+ let fallbackIconSize = fallbackIconData.map {
3432
+ let slotSize = min(leadingWidth.constant, leadingHeight.constant)
3433
+ return $0.string("name") == "GlobusOutline" ? slotSize * 1.2 : slotSize
3434
+ }
3411
3435
  let sourceLoadingStrategy = sources.first?.data.string("loadingStrategy", default: "none") ?? "none"
3412
3436
  let showsSourcePlaceholder = !isIcon && !sources.isEmpty && sourceLoadingStrategy != "none"
3413
3437
  let handlesSourceFallback = !isIcon && !sources.isEmpty &&
3414
3438
  showsSourcePlaceholder &&
3415
3439
  (visual["fallbackText"] != nil || fallbackIconData != nil)
3416
- fallbackLabel.text = handlesSourceFallback ? nil : fallbackText
3440
+ let sourceFallbackKey = handlesSourceFallback
3441
+ ? sources.first.flatMap { sourceFallbackStateKey($0.data) }
3442
+ : nil
3443
+ let restoresSourceFallback = sourceFallbackKey.map(NativeListSourceFallbackState.has) ?? false
3444
+ fallbackLabel.text = handlesSourceFallback && !restoresSourceFallback ? nil : fallbackText
3417
3445
  let sourceFallbackBackground = currentTheme?["strongBackground"] as? String ?? "#0000000F"
3418
3446
  // OneKey patch: source-backed visuals default to no placeholder/background.
3419
3447
  // A non-none image loadingStrategy opts back into the themed placeholder.
@@ -3451,6 +3479,20 @@ final class NativeListCell: UICollectionViewCell {
3451
3479
  leadingIconImageView.image = nativeListIcon(named: fallbackIconData.string("name"))
3452
3480
  leadingIconImageView.contentMode = .scaleAspectFit
3453
3481
  }
3482
+ if handlesSourceFallback, let fallbackIconData {
3483
+ fallbackLabel.isHidden = true
3484
+ leadingIconImageView.image = nativeListIcon(named: fallbackIconData.string("name"))
3485
+ leadingIconImageView.tintColor = UIColor(
3486
+ nativeListHex: fallbackIconData.string("tintColor", default: "#646464"),
3487
+ fallback: .darkGray
3488
+ )
3489
+ leadingIconImageView.contentMode = .scaleAspectFit
3490
+ leadingIconWidth.constant = fallbackIconSize ?? leadingWidth.constant
3491
+ leadingIconHeight.constant = fallbackIconSize ?? leadingHeight.constant
3492
+ leadingIconImageView.isHidden = !restoresSourceFallback
3493
+ } else if handlesSourceFallback {
3494
+ fallbackLabel.isHidden = !restoresSourceFallback
3495
+ }
3454
3496
  let visibleSources = Array(sources.prefix(leadingImages.count))
3455
3497
  let tokenPair = kind == "token" && visibleSources.count > 1
3456
3498
  leadingContainer.clipsToBounds = !tokenPair && cornerIcon == nil
@@ -3506,6 +3548,9 @@ final class NativeListCell: UICollectionViewCell {
3506
3548
  bindImage(source.data, into: imageView, token: key, slot: index, variant: source.variant,
3507
3549
  onLoad: !ownsSourceFallback ? nil : { [weak self, weak imageView] in
3508
3550
  guard let self, self.bindingEpoch == expectedEpoch else { return }
3551
+ if let sourceFallbackKey {
3552
+ NativeListSourceFallbackState.forget(sourceFallbackKey)
3553
+ }
3509
3554
  imageView?.isHidden = false
3510
3555
  self.fallbackLabel.isHidden = true
3511
3556
  self.leadingIconImageView.isHidden = true
@@ -3513,6 +3558,9 @@ final class NativeListCell: UICollectionViewCell {
3513
3558
  },
3514
3559
  onError: !ownsSourceFallback ? nil : { [weak self, weak imageView] in
3515
3560
  guard let self, self.bindingEpoch == expectedEpoch else { return }
3561
+ if let sourceFallbackKey {
3562
+ NativeListSourceFallbackState.remember(sourceFallbackKey)
3563
+ }
3516
3564
  imageView?.isHidden = true
3517
3565
  if let fallbackIcon {
3518
3566
  self.fallbackLabel.isHidden = true
@@ -3643,6 +3691,20 @@ final class NativeListCell: UICollectionViewCell {
3643
3691
  return sources
3644
3692
  }
3645
3693
 
3694
+ private func sourceFallbackStateKey(_ source: [String: Any]) -> String? {
3695
+ let uri = source.string("uri").trimmingCharacters(in: .whitespacesAndNewlines)
3696
+ guard !uri.isEmpty else { return nil }
3697
+ let headersJson: String
3698
+ if let headers = source.dictionary("headers"),
3699
+ JSONSerialization.isValidJSONObject(headers),
3700
+ let data = try? JSONSerialization.data(withJSONObject: headers, options: [.sortedKeys]) {
3701
+ headersJson = String(data: data, encoding: .utf8) ?? ""
3702
+ } else {
3703
+ headersJson = ""
3704
+ }
3705
+ return "\(uri)\u{0}\(headersJson)"
3706
+ }
3707
+
3646
3708
  private func leadingConstraints(
3647
3709
  _ imageView: UIView,
3648
3710
  index: Int,
@@ -537,6 +537,10 @@ export const WEB_LIST_CSS = `
537
537
  .ok-native-list-account-row[data-native-list-selector="accountSelector"]>.ok-native-list-accessories[data-native-list-account-control="createAddress"]{position:absolute;top:18px;right:12px}
538
538
  .ok-native-list-account-row[data-native-list-selector="accountSelector"] .ok-native-list-accessories>[data-native-list-account-control="createAddress"]{flex-basis:36px;width:36px;height:36px;padding:6px;border-radius:8px}
539
539
  .ok-native-list-account-action-row{padding-left:12px;padding-right:12px}.ok-native-list-account-action-row .ok-native-list-action-title{font-size:16px;line-height:24px;font-weight:400}.ok-native-list-account-action-row .ok-native-list-action-title[data-tone="primary"]{color:var(--nl-primary)}
540
+ /* OneKey patch: account selector wallets and accounts keep the default cursor instead of pointer or grab affordances. */
541
+ .ok-native-list-root .ok-native-list-item>.ok-native-list-wallet-row,.ok-native-list-root .ok-native-list-wallet-member>.ok-native-list-wallet-row,.ok-native-list-root .ok-native-list-item>.ok-native-list-account-row,.ok-native-list-root .ok-native-list-item>.ok-native-list-account-action-row,.ok-native-list-wallet-member,.ok-native-list-wallet-row *,.ok-native-list-account-row *,.ok-native-list-account-action-row *{cursor:default}
542
+ /* OneKey patch: Add account hover and pressed backgrounds keep the account row corner radius. */
543
+ .ok-native-list-account-action-row{border-radius:12px}
540
544
  `;
541
545
  function createElement(document, tag, className, text) {
542
546
  const element = document.createElement(tag);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "3.0.135",
3
+ "version": "3.0.136",
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.135",
87
- "@onekeyfe/react-native-native-logger": "3.0.135",
86
+ "@onekeyfe/react-native-image": "3.0.136",
87
+ "@onekeyfe/react-native-native-logger": "3.0.136",
88
88
  "react": "*",
89
89
  "react-native": "*",
90
90
  "react-native-nitro-modules": "0.37.0"
@@ -965,6 +965,10 @@ export const WEB_LIST_CSS = `
965
965
  .ok-native-list-account-row[data-native-list-selector="accountSelector"]>.ok-native-list-accessories[data-native-list-account-control="createAddress"]{position:absolute;top:18px;right:12px}
966
966
  .ok-native-list-account-row[data-native-list-selector="accountSelector"] .ok-native-list-accessories>[data-native-list-account-control="createAddress"]{flex-basis:36px;width:36px;height:36px;padding:6px;border-radius:8px}
967
967
  .ok-native-list-account-action-row{padding-left:12px;padding-right:12px}.ok-native-list-account-action-row .ok-native-list-action-title{font-size:16px;line-height:24px;font-weight:400}.ok-native-list-account-action-row .ok-native-list-action-title[data-tone="primary"]{color:var(--nl-primary)}
968
+ /* OneKey patch: account selector wallets and accounts keep the default cursor instead of pointer or grab affordances. */
969
+ .ok-native-list-root .ok-native-list-item>.ok-native-list-wallet-row,.ok-native-list-root .ok-native-list-wallet-member>.ok-native-list-wallet-row,.ok-native-list-root .ok-native-list-item>.ok-native-list-account-row,.ok-native-list-root .ok-native-list-item>.ok-native-list-account-action-row,.ok-native-list-wallet-member,.ok-native-list-wallet-row *,.ok-native-list-account-row *,.ok-native-list-account-action-row *{cursor:default}
970
+ /* OneKey patch: Add account hover and pressed backgrounds keep the account row corner radius. */
971
+ .ok-native-list-account-action-row{border-radius:12px}
968
972
  `;
969
973
 
970
974
  function createElement(