@onekeyfe/react-native-bottom-tabs 6.7.0-21 → 6.7.0-22

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.
Files changed (32) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/onekey/bottomtabs/BottomTabsView.kt +58 -7
  3. package/android/src/main/java/com/onekey/bottomtabs/SharedSvgDecoder.kt +51 -0
  4. package/docs/SPEC.md +48 -0
  5. package/ios/RCTBottomAccessoryContainerView.swift +2 -0
  6. package/ios/RCTBottomTabsContainerView.swift +216 -12
  7. package/ios/SVG/SvgDecoder.mm +7 -3
  8. package/ios/TabBarFontSize.swift +2 -0
  9. package/lib/module/BottomAccessoryViewNativeComponent.ts +10 -10
  10. package/lib/module/BottomTabs.js +77 -53
  11. package/lib/module/BottomTabsDrawerNativeComponent.ts +12 -12
  12. package/lib/module/BottomTabsNativeComponent.ts +22 -23
  13. package/lib/typescript/src/BottomAccessoryView.d.ts +1 -1
  14. package/lib/typescript/src/BottomAccessoryViewNativeComponent.d.ts +6 -7
  15. package/lib/typescript/src/BottomTabs.d.ts +12 -6
  16. package/lib/typescript/src/BottomTabsDrawerNativeComponent.d.ts +8 -9
  17. package/lib/typescript/src/BottomTabsDrawerNativeComponent.web.d.ts +1 -1
  18. package/lib/typescript/src/BottomTabsNativeComponent.d.ts +15 -16
  19. package/lib/typescript/src/DelayedFreeze.d.ts +1 -1
  20. package/lib/typescript/src/SceneMap.d.ts +1 -1
  21. package/lib/typescript/src/index.d.ts +1 -1
  22. package/lib/typescript/src/types.d.ts +6 -2
  23. package/package.json +5 -4
  24. package/react-native-bottom-tabs.podspec +2 -0
  25. package/src/BottomAccessoryViewNativeComponent.ts +10 -10
  26. package/src/BottomTabs.tsx +111 -54
  27. package/src/BottomTabsDrawerNativeComponent.ts +12 -12
  28. package/src/BottomTabsNativeComponent.ts +22 -23
  29. package/src/index.tsx +7 -1
  30. package/src/types.ts +10 -2
  31. package/ios/SVG/CoreSVG.h +0 -13
  32. package/ios/SVG/CoreSVG.mm +0 -177
@@ -107,7 +107,7 @@ dependencies {
107
107
 
108
108
  implementation("io.coil-kt.coil3:coil:${COIL_VERSION}")
109
109
  implementation("io.coil-kt.coil3:coil-network-okhttp:${COIL_VERSION}")
110
- implementation("io.coil-kt.coil3:coil-svg:${COIL_VERSION}")
110
+ implementation project(":onekeyfe_react-native-image")
111
111
  }
112
112
 
113
113
  if (isNewArchitectureEnabled()) {
@@ -9,6 +9,7 @@ import androidx.appcompat.view.ContextThemeWrapper
9
9
  import android.graphics.Color
10
10
  import android.graphics.Canvas
11
11
  import android.graphics.Outline
12
+ import android.graphics.drawable.BitmapDrawable
12
13
  import android.graphics.drawable.ColorDrawable
13
14
  import android.graphics.drawable.Drawable
14
15
  import android.graphics.drawable.GradientDrawable
@@ -39,7 +40,6 @@ import androidx.core.view.forEachIndexed
39
40
  import coil3.ImageLoader
40
41
  import coil3.asDrawable
41
42
  import coil3.request.ImageRequest
42
- import coil3.svg.SvgDecoder
43
43
  import coil3.size.Precision
44
44
  import coil3.size.Size as CoilSize
45
45
  import coil3.size.Scale
@@ -55,9 +55,12 @@ import com.google.android.material.navigation.NavigationBarView.LABEL_VISIBILITY
55
55
  import com.google.android.material.navigation.NavigationBarView.LABEL_VISIBILITY_LABELED
56
56
  import com.google.android.material.navigation.NavigationBarView.LABEL_VISIBILITY_UNLABELED
57
57
  import com.google.android.material.transition.platform.MaterialFadeThrough
58
+ import com.margelo.nitro.onekeyimage.OneKeyNamedSVG
58
59
  import kotlin.math.abs
59
60
  import kotlin.math.roundToInt
60
61
 
62
+ private const val ONEKEY_ICON_URI_PREFIX = "onekey-icon://"
63
+
61
64
  private fun getMaterialContext(context: Context): Context {
62
65
  return ContextThemeWrapper(context, com.google.android.material.R.style.Theme_MaterialComponents_DayNight)
63
66
  }
@@ -193,6 +196,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
193
196
  var items: MutableList<TabInfo> = mutableListOf()
194
197
  private val iconSources: MutableMap<Int, ImageSource> = mutableMapOf()
195
198
  private val drawableCache: MutableMap<ImageSource, Drawable> = mutableMapOf()
199
+ private val iconRequestTokens: MutableMap<Int, Any> = mutableMapOf()
196
200
 
197
201
  private var isLayoutEnqueued = false
198
202
  private var selectedItem: String? = null
@@ -260,7 +264,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
260
264
 
261
265
  private val imageLoader = ImageLoader.Builder(context)
262
266
  .components {
263
- add(SvgDecoder.Factory())
267
+ add(SharedSvgDecoder.Factory())
264
268
  }
265
269
  .build()
266
270
 
@@ -466,7 +470,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
466
470
  drawableCache.clear()
467
471
  iconSources.forEach { (index, source) ->
468
472
  bottomNavigation.menu.findItem(index)?.let { menuItem ->
469
- getDrawable(source) { menuItem.icon = it }
473
+ getDrawable(index, source) { menuItem.icon = it }
470
474
  }
471
475
  }
472
476
  }
@@ -1253,7 +1257,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1253
1257
 
1254
1258
  menuItem.isVisible = !item.hidden
1255
1259
  if (iconSources.containsKey(index)) {
1256
- getDrawable(iconSources[index]!!) {
1260
+ getDrawable(index, iconSources[index]!!) {
1257
1261
  menuItem.icon = it
1258
1262
  }
1259
1263
  }
@@ -1323,7 +1327,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1323
1327
 
1324
1328
  // Update existing item if exists.
1325
1329
  bottomNavigation.menu.findItem(idx)?.let { menuItem ->
1326
- getDrawable(imageSource) {
1330
+ getDrawable(idx, imageSource) {
1327
1331
  menuItem.icon = it
1328
1332
  }
1329
1333
  }
@@ -1355,11 +1359,50 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1355
1359
  }
1356
1360
 
1357
1361
  @SuppressLint("CheckResult")
1358
- private fun getDrawable(imageSource: ImageSource, onDrawableReady: (Drawable?) -> Unit) {
1362
+ private fun getDrawable(index: Int, imageSource: ImageSource, onDrawableReady: (Drawable?) -> Unit) {
1363
+ iconRequestTokens.remove(index)?.let { OneKeyNamedSVG.cancel(it) }
1359
1364
  drawableCache[imageSource]?.let {
1360
1365
  onDrawableReady(it)
1361
1366
  return
1362
1367
  }
1368
+ val rawSource = imageSource.uri.orEmpty()
1369
+ if (rawSource.startsWith(ONEKEY_ICON_URI_PREFIX)) {
1370
+ val iconName = rawSource.removePrefix(ONEKEY_ICON_URI_PREFIX).trim()
1371
+ if (iconName.isEmpty()) {
1372
+ onDrawableReady(null)
1373
+ return
1374
+ }
1375
+ val token = Any()
1376
+ iconRequestTokens[index] = token
1377
+ val iconSizePx = bottomNavigation.itemIconSize.coerceAtLeast(1)
1378
+ val density = resources.displayMetrics.density
1379
+ OneKeyNamedSVG.request(
1380
+ owner = token,
1381
+ assets = context.applicationContext.assets,
1382
+ name = iconName,
1383
+ color = "rgba(0,0,0,1)",
1384
+ width = iconSizePx,
1385
+ height = iconSizePx,
1386
+ scale = density,
1387
+ ) { bitmap ->
1388
+ if (iconRequestTokens[index] !== token) {
1389
+ return@request
1390
+ }
1391
+ iconRequestTokens.remove(index)
1392
+ if (bitmap == null) {
1393
+ onDrawableReady(null)
1394
+ return@request
1395
+ }
1396
+ val stateDrawable = BitmapDrawable(context.resources, bitmap)
1397
+ drawableCache[imageSource] = stateDrawable
1398
+ if (iconSources[index] == imageSource) {
1399
+ onDrawableReady(stateDrawable)
1400
+ }
1401
+ }
1402
+ return
1403
+ }
1404
+ val token = Any()
1405
+ iconRequestTokens[index] = token
1363
1406
  val iconSizePx = bottomNavigation.itemIconSize
1364
1407
  val request = ImageRequest.Builder(context)
1365
1408
  .data(imageSource.getUri(context))
@@ -1368,9 +1411,15 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1368
1411
  .precision(Precision.EXACT)
1369
1412
  .target { drawable ->
1370
1413
  post {
1414
+ if (iconRequestTokens[index] !== token) {
1415
+ return@post
1416
+ }
1417
+ iconRequestTokens.remove(index)
1371
1418
  val stateDrawable = drawable.asDrawable(context.resources)
1372
1419
  drawableCache[imageSource] = stateDrawable
1373
- onDrawableReady(stateDrawable)
1420
+ if (iconSources[index] == imageSource) {
1421
+ onDrawableReady(stateDrawable)
1422
+ }
1374
1423
  }
1375
1424
  }
1376
1425
  .listener(
@@ -1440,6 +1489,8 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1440
1489
  }
1441
1490
 
1442
1491
  fun onDropViewInstance() {
1492
+ iconRequestTokens.values.forEach { OneKeyNamedSVG.cancel(it) }
1493
+ iconRequestTokens.clear()
1443
1494
  androidBottomBlurEnabled = false
1444
1495
  updateBlurAppearance()
1445
1496
  releaseBottomBlur()
@@ -0,0 +1,51 @@
1
+ package com.onekey.bottomtabs
2
+
3
+ import coil3.ImageLoader
4
+ import coil3.asImage
5
+ import coil3.decode.DecodeResult
6
+ import coil3.decode.DecodeUtils
7
+ import coil3.decode.Decoder
8
+ import coil3.fetch.SourceFetchResult
9
+ import coil3.request.Options
10
+ import coil3.request.maxBitmapSize
11
+ import com.margelo.nitro.onekeyimage.OneKeySVG
12
+ import kotlinx.coroutines.runInterruptible
13
+ import okio.ByteString.Companion.encodeUtf8
14
+ import kotlin.math.roundToInt
15
+
16
+ /** Coil retains fetching, cancellation and sizing; image owns SVG parsing/rendering. */
17
+ internal class SharedSvgDecoder(private val result: SourceFetchResult, private val options: Options) : Decoder {
18
+ override suspend fun decode(): DecodeResult = runInterruptible {
19
+ val document = result.source.source().inputStream().use { OneKeySVG.decode(it) }
20
+ val width = document.viewBoxWidth ?: document.intrinsicWidth
21
+ val height = document.viewBoxHeight ?: document.intrinsicHeight
22
+ val destination = DecodeUtils.computeDstSize(
23
+ if (width > 0) width.roundToInt() else 512,
24
+ if (height > 0) height.roundToInt() else 512,
25
+ options.size, options.scale, options.maxBitmapSize)
26
+ val dstWidth = destination.first
27
+ val dstHeight = destination.second
28
+ val (outputWidth, outputHeight) = if (width > 0 && height > 0) {
29
+ val multiplier = DecodeUtils.computeSizeMultiplier(width, height, dstWidth.toFloat(), dstHeight.toFloat(), options.scale)
30
+ (width * multiplier).toInt() to (height * multiplier).toInt()
31
+ } else dstWidth to dstHeight
32
+ DecodeResult(document.render(outputWidth, outputHeight).asImage(), isSampled = true)
33
+ }
34
+
35
+ class Factory : Decoder.Factory {
36
+ override fun create(result: SourceFetchResult, options: Options, imageLoader: ImageLoader): Decoder? {
37
+ if (result.mimeType != "image/svg+xml") {
38
+ val source = result.source.source()
39
+ if (!source.rangeEquals(0, "<".encodeUtf8())) return null
40
+ val tag = "<svg".encodeUtf8()
41
+ var found = false
42
+ for (index in 0L until (1024L - tag.size)) {
43
+ if (!source.request(index + tag.size)) break
44
+ if (source.rangeEquals(index, tag)) { found = true; break }
45
+ }
46
+ if (!found) return null
47
+ }
48
+ return SharedSvgDecoder(result, options)
49
+ }
50
+ }
51
+ }
package/docs/SPEC.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # Native Tab View behavioral contract
2
2
 
3
+ ## Shared image SVG decoder — Implemented
4
+
5
+ BottomTabs depends on the matching image SDK peer/native module and delegates
6
+ SVG byte decoding to its native facade. No new third-party dependency or SVG
7
+ renderer is introduced. JavaScript props, source resolution and existing tab
8
+ behavior remain unchanged. There is no independent Web SVG reader to migrate.
9
+
10
+ iOS keeps the existing SvgDecoder RCTImageDataDecoder registration (which is
11
+ available to the React image loader beyond tabs), source detection, failure
12
+ delivery and its no-op cancellation block; only data-to-image implementation
13
+ moves out of the local CoreSVG fork. Existing URI loaders, selected/unselected
14
+ and side-accessory paths, SF Symbols, resize/tint and source ordering remain.
15
+ Raw decoding may retain intrinsic/vector dimensions where the old decoder
16
+ ignored target dimensions; it does not use named-icon workers or wait for a
17
+ main-thread callback.
18
+
19
+ Android retains Coil fetching, cache and ordinary image decoders. Its SVG factory
20
+ uses image's parse/render facility with the existing requested dimensions,
21
+ Scale.FILL and Precision.EXACT semantics. The independent coil-svg dependency is
22
+ removed once that route is replaced; no URI loading is moved to Glide. Decoder
23
+ execution remains in Coil's existing worker/cancellation/error lifecycle, with
24
+ no additional pool, cache or main-queue hop. Mutable drawable bounds are owned
25
+ per request, while shared raster data remains immutable.
26
+
27
+ Focused SDK fixtures cover raw SVG and ordinary images through actual RCTImageLoader
28
+ and Coil/BottomTabs consumers, source sizing/non-square art and iOS SF Symbols.
29
+ The current iOS 18.6 fixture does not accept iOS 27.1 side placement; complete
30
+ App styling, platform navigation and signed release acceptance remain separate. Existing source callback races are
31
+ not silently repaired as part of decoding unification. Builds and runtime
32
+ evidence are reported separately. This implementation does not change global image
33
+ loader registration or default-device configuration.
34
+
35
+ ## Tab icon source resolution
36
+
37
+ String names matching `[A-Z][A-Za-z0-9]*` and explicit `{ iconName }` sources
38
+ resolve to `onekey-icon://` resources. An already prefixed string keeps that
39
+ scheme. Ordinary URI strings (including HTTP(S), file, data and other schemes,
40
+ absolute/relative paths and protocol-relative URLs) use the existing React Native
41
+ image-source path with `{ uri }`; they MUST NOT receive the named-icon prefix.
42
+ Whitespace-only strings resolve to an empty source. Numeric assets, URI objects
43
+ and SF Symbols retain their existing resolution. The shared resolver is used for
44
+ focused/unfocused icons and the iOS side-accessory icon.
45
+
46
+ The default `getIcon` resolver has a stable identity. With the same routes array
47
+ and resolver, iOS retains both normal and selected icon-source arrays across tab
48
+ selection and unrelated renders. Replacing the routes array or supplying a new
49
+ resolver recomputes both arrays. Android keeps its focus-dependent icon choice.
50
+
3
51
  ## Native left drawer
4
52
 
5
53
  Status: implemented in module source. Package TypeScript, iOS/Android Fabric
@@ -1,6 +1,8 @@
1
1
  import Foundation
2
2
  import UIKit
3
+ #if canImport(React)
3
4
  import React
5
+ #endif
4
6
 
5
7
  extension Notification.Name {
6
8
  static let bottomAccessoryPlacementChanged = Notification.Name("bottomAccessoryPlacementChanged")
@@ -1,6 +1,71 @@
1
1
  import Foundation
2
2
  import UIKit
3
+ #if canImport(React)
3
4
  import React
5
+ #endif
6
+
7
+ @objc private protocol OneKeyNamedSVGBridgeProtocol: AnyObject {
8
+ @objc(cancelWithOwner:)
9
+ func cancel(owner: AnyObject)
10
+
11
+ @objc(requestWithOwner:name:color:width:height:scale:complete:)
12
+ func request(
13
+ owner: AnyObject,
14
+ name: String,
15
+ color: String,
16
+ width: Int,
17
+ height: Int,
18
+ scale: Double,
19
+ complete: @escaping (UIImage?) -> Void
20
+ )
21
+ }
22
+
23
+ /// Bridges to OneKeyNamedSVG.shared in OneKeyImage without importing the OneKeyImage
24
+ /// Swift module (which transitively imports NitroModules C++ headers).
25
+ private enum OneKeyNamedSVGLoader {
26
+ private static var bridge: OneKeyNamedSVGBridgeProtocol? {
27
+ guard let cls: AnyClass = NSClassFromString("OneKeyNamedSVGBridge")
28
+ ?? NSClassFromString("OneKeyImage.OneKeyNamedSVGBridge")
29
+ else {
30
+ return nil
31
+ }
32
+ let meta = cls as AnyObject
33
+ guard meta.responds(to: #selector(OneKeyNamedSVGBridgeProtocol.cancel(owner:))),
34
+ meta.responds(to: #selector(OneKeyNamedSVGBridgeProtocol.request(owner:name:color:width:height:scale:complete:)))
35
+ else {
36
+ return nil
37
+ }
38
+ return unsafeBitCast(meta, to: OneKeyNamedSVGBridgeProtocol.self)
39
+ }
40
+
41
+ static func cancel(owner: AnyObject) {
42
+ bridge?.cancel(owner: owner)
43
+ }
44
+
45
+ static func request(
46
+ owner: AnyObject,
47
+ name: String,
48
+ color: String,
49
+ width: Int,
50
+ height: Int,
51
+ scale: CGFloat,
52
+ complete: @escaping (UIImage?) -> Void
53
+ ) {
54
+ guard let bridge else {
55
+ complete(nil)
56
+ return
57
+ }
58
+ bridge.request(
59
+ owner: owner,
60
+ name: name,
61
+ color: color,
62
+ width: width,
63
+ height: height,
64
+ scale: Double(scale),
65
+ complete: complete
66
+ )
67
+ }
68
+ }
4
69
 
5
70
  // MARK: - Data types for props from JS
6
71
 
@@ -77,6 +142,10 @@ class RCTBottomTabsContainerView: UIView {
77
142
  private var loadedSideAccessoryIcon: UIImage?
78
143
  // Increments per icon load; a completion applies only to the latest one.
79
144
  private var sideAccessoryIconRequest = 0
145
+ private static let oneKeyIconSchemePrefix = "onekey-icon://"
146
+ private var iconRequestTokens: [Int: NSObject] = [:]
147
+ private var selectedIconRequestTokens: [Int: NSObject] = [:]
148
+ private var sideAccessoryRequestToken = NSObject()
80
149
  private var isSideAccessoryLayoutScheduled = false
81
150
  private static let sideAccessorySize: CGFloat = 48
82
151
  private static let sideAccessorySpacing: CGFloat = 12
@@ -188,6 +257,22 @@ class RCTBottomTabsContainerView: UIView {
188
257
  fatalError("init(coder:) has not been implemented")
189
258
  }
190
259
 
260
+ deinit {
261
+ for token in iconRequestTokens.values {
262
+ OneKeyNamedSVGLoader.cancel(owner: token)
263
+ }
264
+ for token in selectedIconRequestTokens.values {
265
+ OneKeyNamedSVGLoader.cancel(owner: token)
266
+ }
267
+ OneKeyNamedSVGLoader.cancel(owner: sideAccessoryRequestToken)
268
+ }
269
+
270
+ private static func oneKeyIconName(from uri: String) -> String? {
271
+ guard uri.hasPrefix(oneKeyIconSchemePrefix) else { return nil }
272
+ let name = String(uri.dropFirst(oneKeyIconSchemePrefix.count)).trimmingCharacters(in: .whitespacesAndNewlines)
273
+ return name.isEmpty ? nil : name
274
+ }
275
+
191
276
  override func didAddSubview(_ subview: UIView) {
192
277
  super.didAddSubview(subview)
193
278
  if let tbcView = tabBarController?.view, subview !== tbcView {
@@ -217,7 +302,7 @@ class RCTBottomTabsContainerView: UIView {
217
302
  /// Where the system draws the tab bar: "bottom", or "leading"/"trailing" for
218
303
  /// the vertical bar some devices (iPhone Duo) place in a side strip.
219
304
  private func currentTabBarPlacement() -> String {
220
- #if compiler(>=6.4)
305
+ #if compiler(>=6.4) && !targetEnvironment(macCatalyst)
221
306
  if #available(iOS 27.1, *), let tbc = tabBarController {
222
307
  switch tbc.traitCollection.verticalBarEdge {
223
308
  case .leading: return "leading"
@@ -230,7 +315,7 @@ class RCTBottomTabsContainerView: UIView {
230
315
  }
231
316
 
232
317
  private func registerVerticalBarTraitChanges(_ tbc: UITabBarController) {
233
- #if compiler(>=6.4)
318
+ #if compiler(>=6.4) && !targetEnvironment(macCatalyst)
234
319
  if #available(iOS 27.1, *) {
235
320
  tbc.registerForTraitChanges(
236
321
  UITraitCollection.systemTraitsAffectingVerticalBarEdge
@@ -340,6 +425,7 @@ class RCTBottomTabsContainerView: UIView {
340
425
  private func loadSideAccessoryIcon() {
341
426
  sideAccessoryIconRequest += 1
342
427
  let request = sideAccessoryIconRequest
428
+ OneKeyNamedSVGLoader.cancel(owner: sideAccessoryRequestToken)
343
429
  // Drop the previous icon so a slower or failed load never leaves it shown
344
430
  // for the new source.
345
431
  if loadedSideAccessoryIcon != nil {
@@ -347,7 +433,37 @@ class RCTBottomTabsContainerView: UIView {
347
433
  scheduleSideAccessoryLayout()
348
434
  }
349
435
  let source = sideAccessoryIcon.map { IconSource(dict: $0) }
350
- guard let source, let url = URL(string: source.uri) else { return }
436
+ guard let source, !source.uri.isEmpty else { return }
437
+ if let iconName = Self.oneKeyIconName(from: source.uri) {
438
+ let token = NSObject()
439
+ sideAccessoryRequestToken = token
440
+ let scale = max(1.0, window?.screen.scale ?? UIScreen.main.scale)
441
+ let pxW = max(1, Int(ceil(iconSize.width * scale)))
442
+ let pxH = max(1, Int(ceil(iconSize.height * scale)))
443
+ OneKeyNamedSVGLoader.request(
444
+ owner: token,
445
+ name: iconName,
446
+ color: "rgba(0,0,0,1)",
447
+ width: pxW,
448
+ height: pxH,
449
+ scale: scale
450
+ ) { [weak self] image in
451
+ guard let self,
452
+ request == self.sideAccessoryIconRequest,
453
+ self.sideAccessoryRequestToken === token,
454
+ let image else { return }
455
+ let scaledImage: UIImage
456
+ if let cgImage = image.cgImage {
457
+ scaledImage = UIImage(cgImage: cgImage, scale: scale, orientation: .up)
458
+ } else {
459
+ scaledImage = image
460
+ }
461
+ self.loadedSideAccessoryIcon = scaledImage.withRenderingMode(.alwaysTemplate)
462
+ self.scheduleSideAccessoryLayout()
463
+ }
464
+ return
465
+ }
466
+ guard let url = URL(string: source.uri) else { return }
351
467
  // The image loader arrives with the first state update; setImageLoader
352
468
  // calls this again.
353
469
  guard let imageLoader else { return }
@@ -755,21 +871,69 @@ class RCTBottomTabsContainerView: UIView {
755
871
 
756
872
  @objc func setImageLoader(_ loader: RCTImageLoaderProtocol) {
757
873
  self.imageLoader = loader
758
- loadIconsFromSources()
759
- loadSelectedIconsFromSources()
760
- loadSideAccessoryIcon()
874
+ let iconSources = (icons ?? []).map { IconSource(dict: $0) }
875
+ if iconSources.contains(where: { !$0.uri.isEmpty && Self.oneKeyIconName(from: $0.uri) == nil }) {
876
+ loadIconsFromSources()
877
+ }
878
+ let selectedIconSources = (selectedIcons ?? []).map { IconSource(dict: $0) }
879
+ if selectedIconSources.contains(where: { !$0.uri.isEmpty && Self.oneKeyIconName(from: $0.uri) == nil }) {
880
+ loadSelectedIconsFromSources()
881
+ }
882
+ if let sideSource = sideAccessoryIcon.map({ IconSource(dict: $0) }),
883
+ !sideSource.uri.isEmpty,
884
+ Self.oneKeyIconName(from: sideSource.uri) == nil {
885
+ loadSideAccessoryIcon()
886
+ }
761
887
  }
762
888
 
763
889
  private func loadIconsFromSources() {
764
- guard let imageLoader, let iconDicts = icons else { return }
890
+ guard let iconDicts = icons else { return }
765
891
 
766
892
  let iconSources = iconDicts.map { IconSource(dict: $0) }
893
+ let imageLoader = self.imageLoader
894
+
895
+ for staleIndex in iconRequestTokens.keys where staleIndex >= iconSources.count {
896
+ if let previous = iconRequestTokens.removeValue(forKey: staleIndex) {
897
+ OneKeyNamedSVGLoader.cancel(owner: previous)
898
+ }
899
+ }
767
900
 
768
901
  for (index, source) in iconSources.enumerated() {
902
+ if let previous = iconRequestTokens.removeValue(forKey: index) {
903
+ OneKeyNamedSVGLoader.cancel(owner: previous)
904
+ }
769
905
  guard !source.uri.isEmpty else { continue }
906
+ let token = NSObject()
907
+ iconRequestTokens[index] = token
908
+
909
+ if let iconName = Self.oneKeyIconName(from: source.uri) {
910
+ let scale = max(1.0, window?.screen.scale ?? UIScreen.main.scale)
911
+ let pxW = max(1, Int(ceil(iconSize.width * scale)))
912
+ let pxH = max(1, Int(ceil(iconSize.height * scale)))
913
+ OneKeyNamedSVGLoader.request(
914
+ owner: token,
915
+ name: iconName,
916
+ color: "rgba(0,0,0,1)",
917
+ width: pxW,
918
+ height: pxH,
919
+ scale: scale
920
+ ) { [weak self] image in
921
+ guard let self,
922
+ self.iconRequestTokens[index] === token,
923
+ let image else { return }
924
+ let scaledImage: UIImage
925
+ if let cgImage = image.cgImage {
926
+ scaledImage = UIImage(cgImage: cgImage, scale: scale, orientation: .up)
927
+ } else {
928
+ scaledImage = image
929
+ }
930
+ self.loadedIcons[index] = scaledImage
931
+ self.rebuildViewControllers()
932
+ }
933
+ continue
934
+ }
770
935
 
771
- let url = URL(string: source.uri)
772
- guard let url else { continue }
936
+ guard let imageLoader, let url = URL(string: source.uri) else { continue }
773
937
 
774
938
  let request = URLRequest(url: url)
775
939
  let size = CGSize(width: source.width, height: source.height)
@@ -787,6 +951,7 @@ class RCTBottomTabsContainerView: UIView {
787
951
  if error != nil { return }
788
952
  guard let image, let self else { return }
789
953
  DispatchQueue.main.async {
954
+ guard self.iconRequestTokens[index] === token else { return }
790
955
  self.loadedIcons[index] = image.resizeImageTo(size: self.iconSize)
791
956
  self.rebuildViewControllers()
792
957
  }
@@ -795,15 +960,53 @@ class RCTBottomTabsContainerView: UIView {
795
960
  }
796
961
 
797
962
  private func loadSelectedIconsFromSources() {
798
- guard let imageLoader, let iconDicts = selectedIcons else { return }
963
+ guard let iconDicts = selectedIcons else { return }
799
964
 
800
965
  let iconSources = iconDicts.map { IconSource(dict: $0) }
966
+ let imageLoader = self.imageLoader
967
+
968
+ for staleIndex in selectedIconRequestTokens.keys where staleIndex >= iconSources.count {
969
+ if let previous = selectedIconRequestTokens.removeValue(forKey: staleIndex) {
970
+ OneKeyNamedSVGLoader.cancel(owner: previous)
971
+ }
972
+ }
801
973
 
802
974
  for (index, source) in iconSources.enumerated() {
975
+ if let previous = selectedIconRequestTokens.removeValue(forKey: index) {
976
+ OneKeyNamedSVGLoader.cancel(owner: previous)
977
+ }
803
978
  guard !source.uri.isEmpty else { continue }
979
+ let token = NSObject()
980
+ selectedIconRequestTokens[index] = token
981
+
982
+ if let iconName = Self.oneKeyIconName(from: source.uri) {
983
+ let scale = max(1.0, window?.screen.scale ?? UIScreen.main.scale)
984
+ let pxW = max(1, Int(ceil(iconSize.width * scale)))
985
+ let pxH = max(1, Int(ceil(iconSize.height * scale)))
986
+ OneKeyNamedSVGLoader.request(
987
+ owner: token,
988
+ name: iconName,
989
+ color: "rgba(0,0,0,1)",
990
+ width: pxW,
991
+ height: pxH,
992
+ scale: scale
993
+ ) { [weak self] image in
994
+ guard let self,
995
+ self.selectedIconRequestTokens[index] === token,
996
+ let image else { return }
997
+ let scaledImage: UIImage
998
+ if let cgImage = image.cgImage {
999
+ scaledImage = UIImage(cgImage: cgImage, scale: scale, orientation: .up)
1000
+ } else {
1001
+ scaledImage = image
1002
+ }
1003
+ self.loadedSelectedIcons[index] = scaledImage
1004
+ self.rebuildViewControllers()
1005
+ }
1006
+ continue
1007
+ }
804
1008
 
805
- let url = URL(string: source.uri)
806
- guard let url else { continue }
1009
+ guard let imageLoader, let url = URL(string: source.uri) else { continue }
807
1010
 
808
1011
  let request = URLRequest(url: url)
809
1012
  let size = CGSize(width: source.width, height: source.height)
@@ -821,6 +1024,7 @@ class RCTBottomTabsContainerView: UIView {
821
1024
  if error != nil { return }
822
1025
  guard let image, let self else { return }
823
1026
  DispatchQueue.main.async {
1027
+ guard self.selectedIconRequestTokens[index] === token else { return }
824
1028
  self.loadedSelectedIcons[index] = image.resizeImageTo(size: self.iconSize)
825
1029
  self.rebuildViewControllers()
826
1030
  }
@@ -1,5 +1,5 @@
1
1
  #import "SvgDecoder.h"
2
- #import "CoreSVG.h"
2
+ #import <OneKeyImage/OneKeyImageCoderBridge.h>
3
3
 
4
4
  @implementation SvgDecoder
5
5
 
@@ -7,7 +7,11 @@ RCT_EXPORT_MODULE()
7
7
 
8
8
  - (BOOL)canDecodeImageData:(NSData *)imageData
9
9
  {
10
- return [CoreSVGWrapper isSVGData:imageData];
10
+ if (!imageData) return NO;
11
+ // Preserve the existing global React image-decoder selection boundary.
12
+ return [imageData rangeOfData:[@"</svg>" dataUsingEncoding:NSUTF8StringEncoding]
13
+ options:NSDataSearchBackwards
14
+ range:NSMakeRange(imageData.length - MIN(100, imageData.length), MIN(100, imageData.length))].location != NSNotFound;
11
15
  }
12
16
 
13
17
  - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)imageData
@@ -16,7 +20,7 @@ RCT_EXPORT_MODULE()
16
20
  resizeMode:(RCTResizeMode)resizeMode
17
21
  completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
18
22
  {
19
- UIImage *image = [CoreSVGWrapper.shared imageFromSVGData:imageData];
23
+ UIImage *image = [OneKeyImageCoderBridge decodeSVGData:imageData pixelSize:CGSizeZero];
20
24
 
21
25
  if (image) {
22
26
  completionHandler(nil, image);
@@ -1,4 +1,6 @@
1
+ #if canImport(React)
1
2
  import React
3
+ #endif
2
4
  import UIKit
3
5
 
4
6
  enum TabBarFontSize {
@@ -1,13 +1,13 @@
1
- import { codegenNativeComponent } from 'react-native';
2
- import type { ViewProps } from 'react-native';
3
- import type {
4
- DirectEventHandler,
5
- Double,
6
- } from 'react-native/Libraries/Types/CodegenTypes';
1
+ import {
2
+ codegenNativeComponent,
3
+ type CodegenTypes,
4
+ type ViewProps,
5
+ } from 'react-native';
6
+
7
7
 
8
8
  export type OnNativeLayout = Readonly<{
9
- width: Double;
10
- height: Double;
9
+ width: CodegenTypes.Double;
10
+ height: CodegenTypes.Double;
11
11
  }>;
12
12
 
13
13
  export type OnPlacementChanged = Readonly<{
@@ -15,8 +15,8 @@ export type OnPlacementChanged = Readonly<{
15
15
  }>;
16
16
 
17
17
  export interface BottomAccessoryViewNativeProps extends ViewProps {
18
- onNativeLayout?: DirectEventHandler<OnNativeLayout>;
19
- onPlacementChanged?: DirectEventHandler<OnPlacementChanged>;
18
+ onNativeLayout?: CodegenTypes.DirectEventHandler<OnNativeLayout>;
19
+ onPlacementChanged?: CodegenTypes.DirectEventHandler<OnPlacementChanged>;
20
20
  }
21
21
 
22
22
  export default codegenNativeComponent<BottomAccessoryViewNativeProps>(