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

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 (33) 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 +59 -0
  5. package/ios/RCTBottomAccessoryContainerView.swift +2 -0
  6. package/ios/RCTBottomTabsContainerView.swift +219 -12
  7. package/ios/RCTBottomTabsDrawerContainerView.swift +19 -0
  8. package/ios/SVG/SvgDecoder.mm +7 -3
  9. package/ios/TabBarFontSize.swift +2 -0
  10. package/lib/module/BottomAccessoryViewNativeComponent.ts +10 -10
  11. package/lib/module/BottomTabs.js +83 -55
  12. package/lib/module/BottomTabsDrawerNativeComponent.ts +12 -12
  13. package/lib/module/BottomTabsNativeComponent.ts +22 -23
  14. package/lib/typescript/src/BottomAccessoryView.d.ts +1 -1
  15. package/lib/typescript/src/BottomAccessoryViewNativeComponent.d.ts +6 -7
  16. package/lib/typescript/src/BottomTabs.d.ts +12 -6
  17. package/lib/typescript/src/BottomTabsDrawerNativeComponent.d.ts +8 -9
  18. package/lib/typescript/src/BottomTabsDrawerNativeComponent.web.d.ts +1 -1
  19. package/lib/typescript/src/BottomTabsNativeComponent.d.ts +15 -16
  20. package/lib/typescript/src/DelayedFreeze.d.ts +1 -1
  21. package/lib/typescript/src/SceneMap.d.ts +1 -1
  22. package/lib/typescript/src/index.d.ts +1 -1
  23. package/lib/typescript/src/types.d.ts +6 -2
  24. package/package.json +5 -4
  25. package/react-native-bottom-tabs.podspec +2 -0
  26. package/src/BottomAccessoryViewNativeComponent.ts +10 -10
  27. package/src/BottomTabs.tsx +118 -56
  28. package/src/BottomTabsDrawerNativeComponent.ts +12 -12
  29. package/src/BottomTabsNativeComponent.ts +22 -23
  30. package/src/index.tsx +7 -1
  31. package/src/types.ts +10 -2
  32. package/ios/SVG/CoreSVG.h +0 -13
  33. 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
@@ -56,6 +104,11 @@ height: a rendered custom bar's own measured height takes precedence; otherwise
56
104
  `tabBarHidden` forces zero. Native hide measurements MUST NOT overwrite a custom
57
105
  bar's height, including across native/custom presentation switches.
58
106
 
107
+ The iOS drawer MUST NOT receive touches inside the native tab bar at any
108
+ placement, because a vertical bar reports no bottom height. That covers
109
+ everything under the tab controller's view outside tab content, including the
110
+ floating item platter and side accessory.
111
+
59
112
  With opening swipes enabled, a one-finger rightward gesture may start anywhere
60
113
  in the foreground content. At the first confirmed direction, the actual native
61
114
  touch target and its ancestor chain determine ownership. A horizontal scroll
@@ -278,6 +331,12 @@ placement and can draw one round accessory button above the vertical bar.
278
331
  tab bar controller. It fires once after the bar is created and again on every
279
332
  change (rotation, folding, window resizing). Builds without the iOS 27.1 SDK
280
333
  and earlier systems always report `bottom`. Android never fires it.
334
+ - **Height on placement change:** every placement event is followed by
335
+ `onTabBarMeasured` with the bar's current height, because the height reported
336
+ for the previous placement no longer applies. A vertical bar reports its full
337
+ column height, so `BottomTabs` MUST expose 0 through
338
+ `BottomTabBarHeightContext` and the drawer's `bottomBarHeight` for `leading`
339
+ and `trailing` placement, and the measured height only for `bottom`.
281
340
  - **Side accessory:** `sideAccessoryIcon` (an image source, loaded with the
282
341
  React image loader and drawn as a template tinted with `inactiveTintColor`),
283
342
  `sideAccessoryLabel` (accessibility label), and `onSideAccessoryPress`. The
@@ -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
@@ -259,6 +344,9 @@ class RCTBottomTabsContainerView: UIView {
259
344
  if placement != reportedTabBarPlacement {
260
345
  reportedTabBarPlacement = placement
261
346
  onTabBarPlacementChange?(["placement": placement])
347
+ // The bar's frame follows its placement, so the height reported for the
348
+ // previous placement is stale.
349
+ onTabBarMeasured?(["height": tabBarHidden ? 0 : Double(tbc.tabBar.frame.size.height)])
262
350
  }
263
351
 
264
352
  guard placement != "bottom",
@@ -340,6 +428,7 @@ class RCTBottomTabsContainerView: UIView {
340
428
  private func loadSideAccessoryIcon() {
341
429
  sideAccessoryIconRequest += 1
342
430
  let request = sideAccessoryIconRequest
431
+ OneKeyNamedSVGLoader.cancel(owner: sideAccessoryRequestToken)
343
432
  // Drop the previous icon so a slower or failed load never leaves it shown
344
433
  // for the new source.
345
434
  if loadedSideAccessoryIcon != nil {
@@ -347,7 +436,37 @@ class RCTBottomTabsContainerView: UIView {
347
436
  scheduleSideAccessoryLayout()
348
437
  }
349
438
  let source = sideAccessoryIcon.map { IconSource(dict: $0) }
350
- guard let source, let url = URL(string: source.uri) else { return }
439
+ guard let source, !source.uri.isEmpty else { return }
440
+ if let iconName = Self.oneKeyIconName(from: source.uri) {
441
+ let token = NSObject()
442
+ sideAccessoryRequestToken = token
443
+ let scale = max(1.0, window?.screen.scale ?? UIScreen.main.scale)
444
+ let pxW = max(1, Int(ceil(iconSize.width * scale)))
445
+ let pxH = max(1, Int(ceil(iconSize.height * scale)))
446
+ OneKeyNamedSVGLoader.request(
447
+ owner: token,
448
+ name: iconName,
449
+ color: "rgba(0,0,0,1)",
450
+ width: pxW,
451
+ height: pxH,
452
+ scale: scale
453
+ ) { [weak self] image in
454
+ guard let self,
455
+ request == self.sideAccessoryIconRequest,
456
+ self.sideAccessoryRequestToken === token,
457
+ let image else { return }
458
+ let scaledImage: UIImage
459
+ if let cgImage = image.cgImage {
460
+ scaledImage = UIImage(cgImage: cgImage, scale: scale, orientation: .up)
461
+ } else {
462
+ scaledImage = image
463
+ }
464
+ self.loadedSideAccessoryIcon = scaledImage.withRenderingMode(.alwaysTemplate)
465
+ self.scheduleSideAccessoryLayout()
466
+ }
467
+ return
468
+ }
469
+ guard let url = URL(string: source.uri) else { return }
351
470
  // The image loader arrives with the first state update; setImageLoader
352
471
  // calls this again.
353
472
  guard let imageLoader else { return }
@@ -755,21 +874,69 @@ class RCTBottomTabsContainerView: UIView {
755
874
 
756
875
  @objc func setImageLoader(_ loader: RCTImageLoaderProtocol) {
757
876
  self.imageLoader = loader
758
- loadIconsFromSources()
759
- loadSelectedIconsFromSources()
760
- loadSideAccessoryIcon()
877
+ let iconSources = (icons ?? []).map { IconSource(dict: $0) }
878
+ if iconSources.contains(where: { !$0.uri.isEmpty && Self.oneKeyIconName(from: $0.uri) == nil }) {
879
+ loadIconsFromSources()
880
+ }
881
+ let selectedIconSources = (selectedIcons ?? []).map { IconSource(dict: $0) }
882
+ if selectedIconSources.contains(where: { !$0.uri.isEmpty && Self.oneKeyIconName(from: $0.uri) == nil }) {
883
+ loadSelectedIconsFromSources()
884
+ }
885
+ if let sideSource = sideAccessoryIcon.map({ IconSource(dict: $0) }),
886
+ !sideSource.uri.isEmpty,
887
+ Self.oneKeyIconName(from: sideSource.uri) == nil {
888
+ loadSideAccessoryIcon()
889
+ }
761
890
  }
762
891
 
763
892
  private func loadIconsFromSources() {
764
- guard let imageLoader, let iconDicts = icons else { return }
893
+ guard let iconDicts = icons else { return }
765
894
 
766
895
  let iconSources = iconDicts.map { IconSource(dict: $0) }
896
+ let imageLoader = self.imageLoader
897
+
898
+ for staleIndex in iconRequestTokens.keys where staleIndex >= iconSources.count {
899
+ if let previous = iconRequestTokens.removeValue(forKey: staleIndex) {
900
+ OneKeyNamedSVGLoader.cancel(owner: previous)
901
+ }
902
+ }
767
903
 
768
904
  for (index, source) in iconSources.enumerated() {
905
+ if let previous = iconRequestTokens.removeValue(forKey: index) {
906
+ OneKeyNamedSVGLoader.cancel(owner: previous)
907
+ }
769
908
  guard !source.uri.isEmpty else { continue }
909
+ let token = NSObject()
910
+ iconRequestTokens[index] = token
911
+
912
+ if let iconName = Self.oneKeyIconName(from: source.uri) {
913
+ let scale = max(1.0, window?.screen.scale ?? UIScreen.main.scale)
914
+ let pxW = max(1, Int(ceil(iconSize.width * scale)))
915
+ let pxH = max(1, Int(ceil(iconSize.height * scale)))
916
+ OneKeyNamedSVGLoader.request(
917
+ owner: token,
918
+ name: iconName,
919
+ color: "rgba(0,0,0,1)",
920
+ width: pxW,
921
+ height: pxH,
922
+ scale: scale
923
+ ) { [weak self] image in
924
+ guard let self,
925
+ self.iconRequestTokens[index] === token,
926
+ let image else { return }
927
+ let scaledImage: UIImage
928
+ if let cgImage = image.cgImage {
929
+ scaledImage = UIImage(cgImage: cgImage, scale: scale, orientation: .up)
930
+ } else {
931
+ scaledImage = image
932
+ }
933
+ self.loadedIcons[index] = scaledImage
934
+ self.rebuildViewControllers()
935
+ }
936
+ continue
937
+ }
770
938
 
771
- let url = URL(string: source.uri)
772
- guard let url else { continue }
939
+ guard let imageLoader, let url = URL(string: source.uri) else { continue }
773
940
 
774
941
  let request = URLRequest(url: url)
775
942
  let size = CGSize(width: source.width, height: source.height)
@@ -787,6 +954,7 @@ class RCTBottomTabsContainerView: UIView {
787
954
  if error != nil { return }
788
955
  guard let image, let self else { return }
789
956
  DispatchQueue.main.async {
957
+ guard self.iconRequestTokens[index] === token else { return }
790
958
  self.loadedIcons[index] = image.resizeImageTo(size: self.iconSize)
791
959
  self.rebuildViewControllers()
792
960
  }
@@ -795,15 +963,53 @@ class RCTBottomTabsContainerView: UIView {
795
963
  }
796
964
 
797
965
  private func loadSelectedIconsFromSources() {
798
- guard let imageLoader, let iconDicts = selectedIcons else { return }
966
+ guard let iconDicts = selectedIcons else { return }
799
967
 
800
968
  let iconSources = iconDicts.map { IconSource(dict: $0) }
969
+ let imageLoader = self.imageLoader
970
+
971
+ for staleIndex in selectedIconRequestTokens.keys where staleIndex >= iconSources.count {
972
+ if let previous = selectedIconRequestTokens.removeValue(forKey: staleIndex) {
973
+ OneKeyNamedSVGLoader.cancel(owner: previous)
974
+ }
975
+ }
801
976
 
802
977
  for (index, source) in iconSources.enumerated() {
978
+ if let previous = selectedIconRequestTokens.removeValue(forKey: index) {
979
+ OneKeyNamedSVGLoader.cancel(owner: previous)
980
+ }
803
981
  guard !source.uri.isEmpty else { continue }
982
+ let token = NSObject()
983
+ selectedIconRequestTokens[index] = token
984
+
985
+ if let iconName = Self.oneKeyIconName(from: source.uri) {
986
+ let scale = max(1.0, window?.screen.scale ?? UIScreen.main.scale)
987
+ let pxW = max(1, Int(ceil(iconSize.width * scale)))
988
+ let pxH = max(1, Int(ceil(iconSize.height * scale)))
989
+ OneKeyNamedSVGLoader.request(
990
+ owner: token,
991
+ name: iconName,
992
+ color: "rgba(0,0,0,1)",
993
+ width: pxW,
994
+ height: pxH,
995
+ scale: scale
996
+ ) { [weak self] image in
997
+ guard let self,
998
+ self.selectedIconRequestTokens[index] === token,
999
+ let image else { return }
1000
+ let scaledImage: UIImage
1001
+ if let cgImage = image.cgImage {
1002
+ scaledImage = UIImage(cgImage: cgImage, scale: scale, orientation: .up)
1003
+ } else {
1004
+ scaledImage = image
1005
+ }
1006
+ self.loadedSelectedIcons[index] = scaledImage
1007
+ self.rebuildViewControllers()
1008
+ }
1009
+ continue
1010
+ }
804
1011
 
805
- let url = URL(string: source.uri)
806
- guard let url else { continue }
1012
+ guard let imageLoader, let url = URL(string: source.uri) else { continue }
807
1013
 
808
1014
  let request = URLRequest(url: url)
809
1015
  let size = CGSize(width: source.width, height: source.height)
@@ -821,6 +1027,7 @@ class RCTBottomTabsContainerView: UIView {
821
1027
  if error != nil { return }
822
1028
  guard let image, let self else { return }
823
1029
  DispatchQueue.main.async {
1030
+ guard self.selectedIconRequestTokens[index] === token else { return }
824
1031
  self.loadedSelectedIcons[index] = image.resizeImageTo(size: self.iconSize)
825
1032
  self.rebuildViewControllers()
826
1033
  }
@@ -135,6 +135,7 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
135
135
  guard enabled else { return false }
136
136
  let start = touch.location(in: self)
137
137
  guard start.y < bounds.height - CGFloat(max(0, bottomBarHeight)) else { return false }
138
+ guard !isInsideNativeTabBar(touch.view) else { return false }
138
139
  touchTarget = touch.view
139
140
  if progress > 0 { return start.x >= bounds.width * 0.78 * progress }
140
141
  return swipeEnabled && !touchPathContainsExclusiveControl()
@@ -171,6 +172,24 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
171
172
  return other is UIScreenEdgePanGestureRecognizer
172
173
  }
173
174
 
175
+ // A vertical bar reports no bottom height, and UIKit draws its items in a
176
+ // floating platter outside UITabBar, so match anything under the tab
177
+ // controller's view that is not tab content.
178
+ private func isInsideNativeTabBar(_ target: UIView?) -> Bool {
179
+ var path: [UIView] = []
180
+ var view = target
181
+ while let current = view, current !== self {
182
+ if current is UITabBar { return true }
183
+ if let tabs = current.next as? UITabBarController {
184
+ let content = (tabs.viewControllers ?? []).compactMap { $0.viewIfLoaded }
185
+ return !path.contains { step in content.contains { $0 === step } }
186
+ }
187
+ path.append(current)
188
+ view = current.superview
189
+ }
190
+ return false
191
+ }
192
+
174
193
  private func touchPathContainsExclusiveControl() -> Bool {
175
194
  var view = touchTarget
176
195
  while let current = view, current !== self {
@@ -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);