@onekeyfe/react-native-bottom-tabs 6.7.0-40 → 6.7.0-42

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.
@@ -201,8 +201,10 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
201
201
  }
202
202
  var items: MutableList<TabInfo> = mutableListOf()
203
203
  private val iconSources: MutableMap<Int, ImageSource> = mutableMapOf()
204
+ private val selectedIconSources: MutableMap<Int, ImageSource> = mutableMapOf()
204
205
  private val drawableCache: MutableMap<ImageSource, Drawable> = mutableMapOf()
205
206
  private val iconRequestTokens: MutableMap<Int, Any> = mutableMapOf()
207
+ private val selectedIconRequestTokens: MutableMap<Int, Any> = mutableMapOf()
206
208
 
207
209
  private var isLayoutEnqueued = false
208
210
  private var selectedItem: String? = null
@@ -233,6 +235,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
233
235
  private var floatingStretch = 0f
234
236
  private var floatingLiftAnimator: ValueAnimator? = null
235
237
  private var floatingSlideAnimator: ValueAnimator? = null
238
+ private var floatingSlideTargetX = Float.NaN
236
239
  private var floatingVisibilityCallback: Choreographer.FrameCallback? = null
237
240
  private var floatingTouchView: View? = null
238
241
  private var floatingTouchItemId = View.NO_ID
@@ -653,7 +656,20 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
653
656
  1f + (FloatingTabBarMetrics.LENS_SCALE_Y - 1f) * floatingLift - floatingStretch * 0.4f
654
657
  }
655
658
 
659
+ private val floatingLiftSettle = Runnable {
660
+ if (floatingTouchItemId == View.NO_ID) {
661
+ animateFloatingLift(0f)
662
+ }
663
+ }
664
+
665
+ private fun cancelFloatingSlideAnimator() {
666
+ floatingSlideAnimator?.cancel()
667
+ floatingSlideAnimator = null
668
+ floatingSlideTargetX = Float.NaN
669
+ }
670
+
656
671
  private fun animateFloatingLift(target: Float) {
672
+ floatingBar.removeCallbacks(floatingLiftSettle)
657
673
  floatingLiftAnimator?.cancel()
658
674
  val start = floatingLift
659
675
  if (start == target) {
@@ -662,8 +678,15 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
662
678
  }
663
679
  val lifting = target > start
664
680
  floatingLiftAnimator = ValueAnimator.ofFloat(start, target).apply {
665
- duration = if (lifting) 320L else 460L
666
- interpolator = SpringInterpolator(dampingRatio = if (lifting) 0.6f else 0.72f)
681
+ duration = if (lifting) {
682
+ FloatingTabBarMetrics.LIFT_UP_DURATION_MS
683
+ } else {
684
+ FloatingTabBarMetrics.LIFT_SETTLE_DURATION_MS
685
+ }
686
+ interpolator = SpringInterpolator(
687
+ dampingRatio = if (lifting) 0.72f else 0.8f,
688
+ angularFrequency = if (lifting) 9f else 7.8f,
689
+ )
667
690
  addUpdateListener {
668
691
  floatingLift = it.animatedValue as Float
669
692
  applyFloatingIndicatorState()
@@ -672,8 +695,40 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
672
695
  }
673
696
  }
674
697
 
675
- private fun animateFloatingIndicatorTo(targetX: Float, durationMs: Long = 440L) {
676
- floatingSlideAnimator?.cancel()
698
+ private fun scheduleFloatingLiftSettle(cancelled: Boolean) {
699
+ floatingBar.removeCallbacks(floatingLiftSettle)
700
+ if (cancelled) {
701
+ animateFloatingLift(0f)
702
+ return
703
+ }
704
+ val slideAnimator = floatingSlideAnimator
705
+ if (slideAnimator != null && slideAnimator.isRunning) {
706
+ val remainingFraction = (1f - slideAnimator.animatedFraction).coerceIn(0f, 1f)
707
+ val delayMs = (FloatingTabBarMetrics.LIFT_HOLD_DURING_SLIDE_MS * remainingFraction)
708
+ .roundToInt()
709
+ .toLong()
710
+ if (delayMs > 16L) {
711
+ floatingBar.postDelayed(floatingLiftSettle, delayMs)
712
+ return
713
+ }
714
+ }
715
+ animateFloatingLift(0f)
716
+ }
717
+
718
+ private fun animateFloatingIndicatorTo(
719
+ targetX: Float,
720
+ durationMs: Long = FloatingTabBarMetrics.SLIDE_DURATION_MS,
721
+ ) {
722
+ val activeAnimator = floatingSlideAnimator
723
+ if (
724
+ activeAnimator != null &&
725
+ activeAnimator.isRunning &&
726
+ !floatingSlideTargetX.isNaN() &&
727
+ abs(floatingSlideTargetX - targetX) < 0.5f
728
+ ) {
729
+ return
730
+ }
731
+ cancelFloatingSlideAnimator()
677
732
  val startX = floatingIndicator.x
678
733
  if (abs(targetX - startX) < 0.5f) {
679
734
  floatingIndicator.x = targetX
@@ -682,23 +737,39 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
682
737
  return
683
738
  }
684
739
  var previousX = startX
685
- floatingSlideAnimator = ValueAnimator.ofFloat(startX, targetX).apply {
740
+ var previousTimeMs = SystemClock.uptimeMillis()
741
+ floatingSlideTargetX = targetX
742
+ val animator = ValueAnimator.ofFloat(startX, targetX)
743
+ floatingSlideAnimator = animator
744
+ animator.apply {
686
745
  duration = durationMs
687
- interpolator = SpringInterpolator(dampingRatio = 0.74f)
746
+ interpolator = SpringInterpolator(
747
+ dampingRatio = FloatingTabBarMetrics.SLIDE_SPRING_DAMPING,
748
+ angularFrequency = FloatingTabBarMetrics.SLIDE_SPRING_FREQUENCY,
749
+ )
688
750
  addUpdateListener {
751
+ val nowMs = SystemClock.uptimeMillis()
752
+ val elapsedMs = (nowMs - previousTimeMs).coerceIn(4L, 32L).toFloat()
753
+ previousTimeMs = nowMs
689
754
  val x = it.animatedValue as Float
690
755
  val frameDelta = abs(x - previousX)
691
756
  previousX = x
692
757
  floatingIndicator.x = x
693
- // The capsule stretches along the travel direction, like a liquid drop.
694
- val rawStretch = (frameDelta / floatingIndicator.width.coerceAtLeast(1) * 1.6f)
758
+ // Normalize velocity to a 16ms reference step so 60Hz and 120Hz displays
759
+ // produce identical liquid stretch during the spring slide.
760
+ val normalizedStepDelta = frameDelta * (16f / elapsedMs)
761
+ val rawStretch = (normalizedStepDelta / floatingIndicator.width.coerceAtLeast(1) * 1.4f)
695
762
  .coerceAtMost(FloatingTabBarMetrics.LENS_MAX_STRETCH)
696
- floatingStretch = floatingStretch * 0.5f + rawStretch * 0.5f
763
+ floatingStretch = floatingStretch * 0.62f + rawStretch * 0.38f
697
764
  applyFloatingIndicatorState()
698
765
  }
699
766
  doOnEnd {
700
- floatingStretch = 0f
701
- applyFloatingIndicatorState()
767
+ if (floatingSlideAnimator === animator) {
768
+ floatingSlideAnimator = null
769
+ floatingSlideTargetX = Float.NaN
770
+ floatingStretch = 0f
771
+ applyFloatingIndicatorState()
772
+ }
702
773
  }
703
774
  start()
704
775
  }
@@ -727,14 +798,32 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
727
798
  val targetX = getFloatingItemX(selectedIndex) ?: return
728
799
  floatingIndicator.visibility = VISIBLE
729
800
 
730
- if (!animate || !floatingIndicatorPositioned) {
731
- floatingSlideAnimator?.cancel()
801
+ if (!floatingIndicatorPositioned) {
802
+ cancelFloatingSlideAnimator()
732
803
  floatingIndicator.x = targetX
733
804
  floatingStretch = 0f
734
805
  floatingIndicatorPositioned = true
735
806
  applyFloatingIndicatorState()
736
807
  return
737
808
  }
809
+ val activeAnimator = floatingSlideAnimator
810
+ if (
811
+ activeAnimator != null &&
812
+ activeAnimator.isRunning &&
813
+ !floatingSlideTargetX.isNaN() &&
814
+ abs(floatingSlideTargetX - targetX) < 0.5f
815
+ ) {
816
+ // Keep an in-flight slide to the same target running smoothly even when
817
+ // a late layout/item sync arrives with animate = false.
818
+ return
819
+ }
820
+ if (!animate) {
821
+ cancelFloatingSlideAnimator()
822
+ floatingIndicator.x = targetX
823
+ floatingStretch = 0f
824
+ applyFloatingIndicatorState()
825
+ return
826
+ }
738
827
  animateFloatingIndicatorTo(targetX)
739
828
  }
740
829
 
@@ -865,7 +954,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
865
954
  updateFloatingIndicatorWidth(itemView.width)
866
955
  floatingIndicator.visibility = VISIBLE
867
956
  if (floatingIndicatorPositioned) {
868
- animateFloatingIndicatorTo(targetX, durationMs = 320L)
957
+ animateFloatingIndicatorTo(targetX, durationMs = FloatingTabBarMetrics.SLIDE_DURATION_MS)
869
958
  } else {
870
959
  floatingIndicator.x = targetX
871
960
  floatingIndicatorPositioned = true
@@ -901,7 +990,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
901
990
  val targetStretch = (velocityDpPerMs * 0.06f).coerceAtMost(FloatingTabBarMetrics.LENS_MAX_STRETCH)
902
991
  floatingStretch = floatingStretch * 0.6f + targetStretch * 0.4f
903
992
 
904
- floatingSlideAnimator?.cancel()
993
+ cancelFloatingSlideAnimator()
905
994
  floatingIndicator.x = centerX - halfWidth
906
995
  applyFloatingIndicatorState()
907
996
  floatingBar.removeCallbacks(floatingStretchDecay)
@@ -938,7 +1027,6 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
938
1027
  val wasDragging = floatingDragging
939
1028
  clearFloatingTouchTracking()
940
1029
  setFloatingItemMagnified(View.NO_ID)
941
- animateFloatingLift(0f)
942
1030
 
943
1031
  if (!cancelled && requestedItemId != View.NO_ID) {
944
1032
  if (!wasDragging) {
@@ -952,6 +1040,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
952
1040
  // Settles on the selected tab, which is the old one for cancelled or
953
1041
  // preventsDefault presses.
954
1042
  updateFloatingIndicator(animate = true)
1043
+ scheduleFloatingLiftSettle(cancelled = cancelled || wasDragging)
955
1044
  }
956
1045
 
957
1046
  private fun clearFloatingTouchTracking() {
@@ -966,8 +1055,9 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
966
1055
 
967
1056
  private fun resetFloatingGesture() {
968
1057
  clearFloatingTouchTracking()
1058
+ floatingBar.removeCallbacks(floatingLiftSettle)
969
1059
  floatingLiftAnimator?.cancel()
970
- floatingSlideAnimator?.cancel()
1060
+ cancelFloatingSlideAnimator()
971
1061
  floatingLift = 0f
972
1062
  floatingStretch = 0f
973
1063
  items.indices.forEach { itemId ->
@@ -1188,7 +1278,13 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1188
1278
  private fun setSelectedIndex(itemId: Int) {
1189
1279
  val selectionChanged = bottomNavigation.selectedItemId != itemId
1190
1280
  bottomNavigation.selectedItemId = itemId
1191
- if (androidTabBarStyle == AndroidTabBarStyle.FLOATING) {
1281
+ if (selectionChanged) {
1282
+ updateMenuItemIconsForSelection()
1283
+ }
1284
+ if (
1285
+ androidTabBarStyle == AndroidTabBarStyle.FLOATING &&
1286
+ (selectionChanged || !floatingIndicatorPositioned)
1287
+ ) {
1192
1288
  post { updateFloatingIndicator(animate = selectionChanged) }
1193
1289
  }
1194
1290
  if (disablePageAnimations) {
@@ -1450,11 +1546,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1450
1546
  }
1451
1547
 
1452
1548
  menuItem.isVisible = !item.hidden
1453
- if (iconSources.containsKey(index)) {
1454
- getDrawable(index, iconSources[index]!!) {
1455
- menuItem.icon = it
1456
- }
1457
- }
1549
+ applyMenuItemIcon(index, menuItem)
1458
1550
 
1459
1551
  if (item.badge?.isNotEmpty() == true) {
1460
1552
  val badge = bottomNavigation.getOrCreateBadge(index)
@@ -1506,6 +1598,49 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1506
1598
  return bottomNavigation.menu.findItem(index) ?: bottomNavigation.menu.add(0, index, 0, title)
1507
1599
  }
1508
1600
 
1601
+ private fun isItemSelected(index: Int): Boolean {
1602
+ val selectedKey = selectedItem
1603
+ return if (selectedKey != null) {
1604
+ items.getOrNull(index)?.key == selectedKey
1605
+ } else {
1606
+ bottomNavigation.selectedItemId == index
1607
+ }
1608
+ }
1609
+
1610
+ private fun activeIconSourceForIndex(index: Int): Pair<ImageSource, Boolean>? {
1611
+ val selected = isItemSelected(index)
1612
+ if (selected) {
1613
+ selectedIconSources[index]?.let { return it to true }
1614
+ }
1615
+ iconSources[index]?.let { return it to false }
1616
+ selectedIconSources[index]?.let { return it to true }
1617
+ return null
1618
+ }
1619
+
1620
+ private fun applyMenuItemIcon(index: Int, menuItem: MenuItem) {
1621
+ val (source, isSelectedSource) = activeIconSourceForIndex(index) ?: return
1622
+ drawableCache[source]?.let { cached ->
1623
+ if (menuItem.icon !== cached) {
1624
+ menuItem.icon = cached
1625
+ }
1626
+ return
1627
+ }
1628
+ loadDrawable(index, source, isSelectedSource) { drawable ->
1629
+ val currentSource = activeIconSourceForIndex(index)?.first
1630
+ if (currentSource == source && drawable != null) {
1631
+ menuItem.icon = drawable
1632
+ }
1633
+ }
1634
+ }
1635
+
1636
+ private fun updateMenuItemIconsForSelection() {
1637
+ items.indices.forEach { index ->
1638
+ bottomNavigation.menu.findItem(index)?.let { menuItem ->
1639
+ applyMenuItemIcon(index, menuItem)
1640
+ }
1641
+ }
1642
+ }
1643
+
1509
1644
  fun setIcons(icons: ReadableArray?) {
1510
1645
  if (icons == null || icons.size() == 0) {
1511
1646
  return
@@ -1521,10 +1656,38 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1521
1656
  val imageSource = ImageSource(context, uri)
1522
1657
  this.iconSources[idx] = imageSource
1523
1658
 
1524
- // Update existing item if exists.
1525
- bottomNavigation.menu.findItem(idx)?.let { menuItem ->
1526
- getDrawable(idx, imageSource) {
1527
- menuItem.icon = it
1659
+ loadDrawable(idx, imageSource, isSelectedIcon = false) {
1660
+ bottomNavigation.menu.findItem(idx)?.let { menuItem ->
1661
+ applyMenuItemIcon(idx, menuItem)
1662
+ }
1663
+ }
1664
+ }
1665
+ }
1666
+
1667
+ fun setSelectedIcons(icons: ReadableArray?) {
1668
+ if (icons == null || icons.size() == 0) {
1669
+ selectedIconRequestTokens.values.forEach { OneKeyNamedSVG.cancel(it) }
1670
+ selectedIconRequestTokens.clear()
1671
+ selectedIconSources.clear()
1672
+ updateMenuItemIconsForSelection()
1673
+ return
1674
+ }
1675
+
1676
+ for (idx in 0 until icons.size()) {
1677
+ val source = icons.getMap(idx)
1678
+ val uri = source?.getString("uri")
1679
+ if (uri.isNullOrEmpty()) {
1680
+ selectedIconSources.remove(idx)
1681
+ continue
1682
+ }
1683
+
1684
+ val imageSource = ImageSource(context, uri)
1685
+ this.selectedIconSources[idx] = imageSource
1686
+
1687
+ // Pre-warm the selected icon into drawableCache so tab switches swap synchronously.
1688
+ loadDrawable(idx, imageSource, isSelectedIcon = true) {
1689
+ bottomNavigation.menu.findItem(idx)?.let { menuItem ->
1690
+ applyMenuItemIcon(idx, menuItem)
1528
1691
  }
1529
1692
  }
1530
1693
  }
@@ -1555,8 +1718,15 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1555
1718
  }
1556
1719
 
1557
1720
  @SuppressLint("CheckResult")
1558
- private fun getDrawable(index: Int, imageSource: ImageSource, onDrawableReady: (Drawable?) -> Unit) {
1559
- iconRequestTokens.remove(index)?.let { OneKeyNamedSVG.cancel(it) }
1721
+ private fun loadDrawable(
1722
+ index: Int,
1723
+ imageSource: ImageSource,
1724
+ isSelectedIcon: Boolean,
1725
+ onDrawableReady: (Drawable?) -> Unit,
1726
+ ) {
1727
+ val tokenMap = if (isSelectedIcon) selectedIconRequestTokens else iconRequestTokens
1728
+ val sourceMap = if (isSelectedIcon) selectedIconSources else iconSources
1729
+ tokenMap.remove(index)?.let { OneKeyNamedSVG.cancel(it) }
1560
1730
  drawableCache[imageSource]?.let {
1561
1731
  onDrawableReady(it)
1562
1732
  return
@@ -1569,7 +1739,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1569
1739
  return
1570
1740
  }
1571
1741
  val token = Any()
1572
- iconRequestTokens[index] = token
1742
+ tokenMap[index] = token
1573
1743
  val iconSizePx = bottomNavigation.itemIconSize.coerceAtLeast(1)
1574
1744
  val density = resources.displayMetrics.density
1575
1745
  OneKeyNamedSVG.request(
@@ -1581,24 +1751,24 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1581
1751
  height = iconSizePx,
1582
1752
  scale = density,
1583
1753
  ) { bitmap ->
1584
- if (iconRequestTokens[index] !== token) {
1754
+ if (tokenMap[index] !== token) {
1585
1755
  return@request
1586
1756
  }
1587
- iconRequestTokens.remove(index)
1757
+ tokenMap.remove(index)
1588
1758
  if (bitmap == null) {
1589
1759
  onDrawableReady(null)
1590
1760
  return@request
1591
1761
  }
1592
1762
  val stateDrawable = BitmapDrawable(context.resources, bitmap)
1593
1763
  drawableCache[imageSource] = stateDrawable
1594
- if (iconSources[index] == imageSource) {
1764
+ if (sourceMap[index] == imageSource) {
1595
1765
  onDrawableReady(stateDrawable)
1596
1766
  }
1597
1767
  }
1598
1768
  return
1599
1769
  }
1600
1770
  val token = Any()
1601
- iconRequestTokens[index] = token
1771
+ tokenMap[index] = token
1602
1772
  val iconSizePx = bottomNavigation.itemIconSize
1603
1773
  val request = ImageRequest.Builder(context)
1604
1774
  .data(imageSource.getUri(context))
@@ -1607,13 +1777,13 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1607
1777
  .precision(Precision.EXACT)
1608
1778
  .target { drawable ->
1609
1779
  post {
1610
- if (iconRequestTokens[index] !== token) {
1780
+ if (tokenMap[index] !== token) {
1611
1781
  return@post
1612
1782
  }
1613
- iconRequestTokens.remove(index)
1783
+ tokenMap.remove(index)
1614
1784
  val stateDrawable = drawable.asDrawable(context.resources)
1615
1785
  drawableCache[imageSource] = stateDrawable
1616
- if (iconSources[index] == imageSource) {
1786
+ if (sourceMap[index] == imageSource) {
1617
1787
  onDrawableReady(stateDrawable)
1618
1788
  }
1619
1789
  }
@@ -1687,6 +1857,8 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
1687
1857
  fun onDropViewInstance() {
1688
1858
  iconRequestTokens.values.forEach { OneKeyNamedSVG.cancel(it) }
1689
1859
  iconRequestTokens.clear()
1860
+ selectedIconRequestTokens.values.forEach { OneKeyNamedSVG.cancel(it) }
1861
+ selectedIconRequestTokens.clear()
1690
1862
  androidBottomBlurEnabled = false
1691
1863
  updateBlurAppearance()
1692
1864
  releaseBottomBlur()
@@ -207,9 +207,10 @@ class BottomTabsViewManager(context: ReactApplicationContext) :
207
207
  }
208
208
 
209
209
  // iOS-only props (no-ops on Android)
210
- // selectedIcons feeds UITabBarItem.selectedImage on iOS; Android keeps
211
- // swapping the icon in JS via the focusedKey-driven `icons` array.
212
- override fun setSelectedIcons(view: BottomTabsView?, value: ReadableArray?) {}
210
+ override fun setSelectedIcons(view: BottomTabsView?, value: ReadableArray?) {
211
+ if (view != null)
212
+ view.setSelectedIcons(value)
213
+ }
213
214
  override fun setTranslucent(view: BottomTabsView?, value: Boolean) {}
214
215
  override fun setSidebarAdaptable(view: BottomTabsView?, value: Boolean) {}
215
216
  override fun setScrollEdgeAppearance(view: BottomTabsView?, value: String?) {}
@@ -24,6 +24,14 @@ internal object FloatingTabBarMetrics {
24
24
  const val LENS_MAX_STRETCH = 0.16f
25
25
  const val ITEM_PRESSED_SCALE = 1.1f
26
26
  const val DRAG_EDGE_RESISTANCE = 0.22f
27
+
28
+ // Motion timings aligned with the iOS 26 Liquid Glass tab bar spring.
29
+ const val SLIDE_DURATION_MS = 520L
30
+ const val SLIDE_SPRING_DAMPING = 0.82f
31
+ const val SLIDE_SPRING_FREQUENCY = 7.5f
32
+ const val LIFT_UP_DURATION_MS = 220L
33
+ const val LIFT_SETTLE_DURATION_MS = 380L
34
+ const val LIFT_HOLD_DURING_SLIDE_MS = 200L
27
35
  }
28
36
 
29
37
  /**
@@ -31,20 +39,28 @@ internal object FloatingTabBarMetrics {
31
39
  * below 1 overshoots slightly before settling, matching UIKit spring motion.
32
40
  */
33
41
  internal class SpringInterpolator(
34
- private val dampingRatio: Float = 0.72f,
35
- private val angularFrequency: Float = 10f,
42
+ private val dampingRatio: Float = FloatingTabBarMetrics.SLIDE_SPRING_DAMPING,
43
+ private val angularFrequency: Float = FloatingTabBarMetrics.SLIDE_SPRING_FREQUENCY,
36
44
  ) : Interpolator {
37
45
  private val dampedFrequency =
38
46
  angularFrequency * sqrt(1f - dampingRatio * dampingRatio)
47
+ private val endValue = rawSpring(1f)
39
48
 
40
- override fun getInterpolation(input: Float): Float {
41
- if (input >= 1f) {
42
- return 1f
43
- }
49
+ private fun rawSpring(input: Float): Float {
44
50
  val decay = exp(-dampingRatio * angularFrequency * input)
45
51
  val phase = dampedFrequency * input
46
52
  return 1f - decay * (
47
53
  cos(phase) + (dampingRatio * angularFrequency / dampedFrequency) * sin(phase)
48
54
  )
49
55
  }
56
+
57
+ override fun getInterpolation(input: Float): Float {
58
+ if (input <= 0f) {
59
+ return 0f
60
+ }
61
+ if (input >= 1f || endValue == 0f) {
62
+ return 1f
63
+ }
64
+ return rawSpring(input) / endValue
65
+ }
50
66
  }
package/docs/SPEC.md CHANGED
@@ -44,9 +44,25 @@ and SF Symbols retain their existing resolution. The shared resolver is used for
44
44
  focused/unfocused icons and the iOS side-accessory icon.
45
45
 
46
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.
47
+ and resolver, both iOS and Android retain normal (`icons`) and selected
48
+ (`selectedIcons`) icon-source arrays across tab selection and unrelated renders,
49
+ and `items` does not recompute solely because `selectedPage` changes. Replacing
50
+ the routes array or supplying a new resolver recomputes both arrays. On Android,
51
+ `BottomTabsView` pre-loads both `icons` and `selectedIcons` into `drawableCache`
52
+ and swaps each `MenuItem`'s icon synchronously on the UI thread when selection
53
+ changes.
54
+
55
+ ## iOS icon completion updates
56
+
57
+ When normal or selected artwork arrives, update the existing `UITabBarItem`
58
+ images without rebuilding controllers or replacing items. Coalesce completed
59
+ indices into one main-queue update; use the current source/token ownership and
60
+ current tints, including SF Symbol and normal-image fallbacks. Item identity,
61
+ selection, labels, badges and accessibility identifiers remain intact. Structural
62
+ item changes retain the existing rebuild path. Android is unchanged.
63
+
64
+ Consumer simulator evidence covers cold launch, tab switching and light/dark
65
+ icon tint. Physical-device and rapid source/reorder acceptance remain pending.
50
66
 
51
67
  ## Native left drawer
52
68
 
@@ -311,9 +327,17 @@ Floating interaction (single finger; motion splitting is disabled):
311
327
  Release after a drag selects the candidate once, only if it differs from the
312
328
  current tab. Cancel selects nothing.
313
329
  4. The lens then settles back into the pill on the selected tab, which stays on
314
- the old tab for cancelled or `preventsDefault` presses.
315
-
316
- JS-driven selection changes slide the pill with a spring and velocity stretch.
330
+ the old tab for cancelled or `preventsDefault` presses. When a stationary tap
331
+ releases while the indicator slide is still in flight, the lifted lens holds
332
+ briefly (proportional to the remaining slide fraction) before settling into
333
+ the resting pill as it arrives at the target tab.
334
+
335
+ Both press-initiated and JS-driven selection changes slide the pill with a
336
+ 520 ms underdamped spring (`dampingRatio = 0.82`, `angularFrequency = 7.5`) and
337
+ frame-rate-normalized velocity stretch (16 ms reference step). An in-flight
338
+ slide animator already targeting the selected tab's X position is preserved
339
+ across touch release and subsequent JS `selectedPage` or `items` syncs instead
340
+ of being restarted or snapped.
317
341
  When `tabBarHidden` changes dynamically while attached and laid out in `floating`
318
342
  style, `BottomTabsView` animates `floatingBar.translationY` across its visible
319
343
  bottom clearance (`DecelerateInterpolator`), preserving in-flight translation on
@@ -139,6 +139,8 @@ class RCTBottomTabsContainerView: UIView {
139
139
  private var lastPressedTabTime: CFTimeInterval = 0
140
140
  /// Cached view controllers keyed by tab key to avoid unnecessary reparenting
141
141
  private var cachedViewControllers: [String: UIViewController] = [:]
142
+ private var pendingIconUpdates = Set<Int>()
143
+ private var isIconUpdateScheduled = false
142
144
  // Vertical tab bar (iPhone Duo side strip): last reported placement and the
143
145
  // round accessory button drawn above the bar.
144
146
  private var reportedTabBarPlacement: String?
@@ -684,6 +686,31 @@ class RCTBottomTabsContainerView: UIView {
684
686
  scheduleSideAccessoryLayout()
685
687
  }
686
688
 
689
+ private func scheduleIconUpdate(at index: Int) {
690
+ pendingIconUpdates.insert(index)
691
+ guard !isIconUpdateScheduled else { return }
692
+ isIconUpdateScheduled = true
693
+ DispatchQueue.main.async { [weak self] in
694
+ guard let self else { return }
695
+ self.isIconUpdateScheduled = false
696
+ let indices = self.pendingIconUpdates
697
+ self.pendingIconUpdates.removeAll()
698
+ let allItems = self.parsedItems
699
+ for index in indices.sorted() {
700
+ guard allItems.indices.contains(index),
701
+ let vc = self.cachedViewControllers[allItems[index].key],
702
+ let item = vc.tabBarItem else { continue }
703
+ let symbol = allItems[index].sfSymbol ?? ""
704
+ let fallback = symbol.isEmpty ? nil : UIImage(systemName: symbol)
705
+ let image = self.loadedIcons[index] ?? fallback
706
+ let selectedImage = self.loadedSelectedIcons[index] ?? fallback ?? image
707
+ // Preserve the item and controller identities while artwork arrives.
708
+ item.image = self.bakeTint(image, self.inactiveTintColor)
709
+ item.selectedImage = self.bakeTint(selectedImage, self.activeTintColor)
710
+ }
711
+ }
712
+ }
713
+
687
714
  // MARK: - Selection
688
715
 
689
716
  private func updateSelectedTab() {
@@ -1039,7 +1066,7 @@ class RCTBottomTabsContainerView: UIView {
1039
1066
  scaledImage = image
1040
1067
  }
1041
1068
  self.loadedIcons[index] = scaledImage
1042
- self.rebuildViewControllers()
1069
+ self.scheduleIconUpdate(at: index)
1043
1070
  }
1044
1071
  continue
1045
1072
  }
@@ -1064,7 +1091,7 @@ class RCTBottomTabsContainerView: UIView {
1064
1091
  DispatchQueue.main.async {
1065
1092
  guard self.iconRequestTokens[index] === token else { return }
1066
1093
  self.loadedIcons[index] = image.resizeImageTo(size: self.iconSize)
1067
- self.rebuildViewControllers()
1094
+ self.scheduleIconUpdate(at: index)
1068
1095
  }
1069
1096
  })
1070
1097
  }
@@ -1112,7 +1139,7 @@ class RCTBottomTabsContainerView: UIView {
1112
1139
  scaledImage = image
1113
1140
  }
1114
1141
  self.loadedSelectedIcons[index] = scaledImage
1115
- self.rebuildViewControllers()
1142
+ self.scheduleIconUpdate(at: index)
1116
1143
  }
1117
1144
  continue
1118
1145
  }
@@ -1137,7 +1164,7 @@ class RCTBottomTabsContainerView: UIView {
1137
1164
  DispatchQueue.main.async {
1138
1165
  guard self.selectedIconRequestTokens[index] === token else { return }
1139
1166
  self.loadedSelectedIcons[index] = image.resizeImageTo(size: self.iconSize)
1140
- self.rebuildViewControllers()
1167
+ self.scheduleIconUpdate(at: index)
1141
1168
  }
1142
1169
  })
1143
1170
  }
@@ -76,6 +76,42 @@ export const resolveTabIconSource = icon => {
76
76
  scale: resolved?.scale ?? 1
77
77
  };
78
78
  };
79
+ const defaultGetBadge = ({
80
+ route
81
+ }) => route.badge;
82
+ const defaultGetBadgeBackgroundColor = ({
83
+ route
84
+ }) => route.badgeBackgroundColor;
85
+ const defaultGetBadgeTextColor = ({
86
+ route
87
+ }) => route.badgeTextColor;
88
+ const defaultGetLazy = ({
89
+ route
90
+ }) => route.lazy;
91
+ const defaultGetLabelText = ({
92
+ route
93
+ }) => route.title;
94
+ const defaultGetHidden = ({
95
+ route
96
+ }) => route.hidden;
97
+ const defaultGetActiveTintColor = ({
98
+ route
99
+ }) => route.activeTintColor;
100
+ const defaultGetTestID = ({
101
+ route
102
+ }) => route.testID;
103
+ const defaultGetRole = ({
104
+ route
105
+ }) => route.role;
106
+ const defaultGetSceneStyle = ({
107
+ route
108
+ }) => route.style;
109
+ const defaultGetPreventsDefault = ({
110
+ route
111
+ }) => route.preventsDefault;
112
+ const defaultGetFreezeOnBlur = ({
113
+ route
114
+ }) => route.freezeOnBlur;
79
115
  const defaultGetIcon = ({
80
116
  route,
81
117
  focused
@@ -94,45 +130,21 @@ const BottomTabs = ({
94
130
  rippleColor,
95
131
  tabBarActiveTintColor: activeTintColor,
96
132
  tabBarInactiveTintColor: inactiveTintColor,
97
- getBadge = ({
98
- route
99
- }) => route.badge,
100
- getBadgeBackgroundColor = ({
101
- route
102
- }) => route.badgeBackgroundColor,
103
- getBadgeTextColor = ({
104
- route
105
- }) => route.badgeTextColor,
106
- getLazy = ({
107
- route
108
- }) => route.lazy,
109
- getLabelText = ({
110
- route
111
- }) => route.title,
133
+ getBadge = defaultGetBadge,
134
+ getBadgeBackgroundColor = defaultGetBadgeBackgroundColor,
135
+ getBadgeTextColor = defaultGetBadgeTextColor,
136
+ getLazy = defaultGetLazy,
137
+ getLabelText = defaultGetLabelText,
112
138
  getIcon = defaultGetIcon,
113
- getHidden = ({
114
- route
115
- }) => route.hidden,
116
- getActiveTintColor = ({
117
- route
118
- }) => route.activeTintColor,
119
- getTestID = ({
120
- route
121
- }) => route.testID,
122
- getRole = ({
123
- route
124
- }) => route.role,
125
- getSceneStyle = ({
126
- route
127
- }) => route.style,
128
- getPreventsDefault = ({
129
- route
130
- }) => route.preventsDefault,
139
+ getHidden = defaultGetHidden,
140
+ getActiveTintColor = defaultGetActiveTintColor,
141
+ getTestID = defaultGetTestID,
142
+ getRole = defaultGetRole,
143
+ getSceneStyle = defaultGetSceneStyle,
144
+ getPreventsDefault = defaultGetPreventsDefault,
131
145
  hapticFeedbackEnabled = false,
132
146
  labeled = Platform.OS !== "android" ? true : undefined,
133
- getFreezeOnBlur = ({
134
- route
135
- }) => route.freezeOnBlur,
147
+ getFreezeOnBlur = defaultGetFreezeOnBlur,
136
148
  tabBar: renderCustomTabBar,
137
149
  tabBarStyle,
138
150
  tabLabelStyle,
@@ -178,24 +190,16 @@ const BottomTabs = ({
178
190
  route,
179
191
  focused: false
180
192
  })), [getIcon, trimmedRoutes]);
181
- // Focused (solid) icons — also stable; handed to iOS as selectedImage.
193
+ // Focused (solid) icons — also stable; handed to native as selectedIcons so
194
+ // both iOS and Android swap focused artwork synchronously on the UI thread
195
+ // without waiting for a JS round-trip.
182
196
  const focusedIcons = React.useMemo(() => trimmedRoutes.map(route => getIcon({
183
197
  route,
184
198
  focused: true
185
199
  })), [getIcon, trimmedRoutes]);
186
- // Legacy single array driven by focusedKey. Android still swaps the icon in
187
- // JS (it has no selectedImage equivalent).
188
- const focusKeyedIcons = React.useMemo(() => trimmedRoutes.map(route => getIcon({
189
- route,
190
- focused: route.key === focusedKey
191
- })), [focusedKey, getIcon, trimmedRoutes]);
192
-
193
- // iOS hands both states to UIKit (image + selectedImage) so the focused
194
- // artwork swaps natively, in sync with the selection animation, instead of
195
- // waiting for a JS round-trip. Android keeps the focusedKey-driven array.
196
- const icons = isIOS ? unfocusedIcons : focusKeyedIcons;
200
+ const icons = unfocusedIcons;
197
201
  const items = React.useMemo(() => trimmedRoutes.map((route, index) => {
198
- const icon = icons[index];
202
+ const icon = unfocusedIcons[index];
199
203
  const isSfSymbol = isAppleSymbol(icon);
200
204
  if (Platform.OS === "android" && isSfSymbol) {
201
205
  console.warn("SF Symbols are not supported on Android. Use require() or pass uri to load an image instead.");
@@ -234,11 +238,8 @@ const BottomTabs = ({
234
238
  route
235
239
  })
236
240
  };
237
- }), [trimmedRoutes, icons, getLabelText, getBadge, getBadgeBackgroundColor, getBadgeTextColor, getActiveTintColor, getHidden, getTestID, getRole, getPreventsDefault]);
241
+ }), [trimmedRoutes, unfocusedIcons, getLabelText, getBadge, getBadgeBackgroundColor, getBadgeTextColor, getActiveTintColor, getHidden, getTestID, getRole, getPreventsDefault]);
238
242
  const resolvedIconAssets = React.useMemo(() => icons.map(icon => resolveTabIconSource(icon)), [icons]);
239
-
240
- // Focused (solid) assets passed to iOS as selectedImage. iOS only — Android
241
- // ignores selectedIcons and keeps swapping via the focusedKey array above.
242
243
  const resolvedSelectedIconAssets = React.useMemo(() => focusedIcons.map(icon => resolveTabIconSource(icon)), [focusedIcons]);
243
244
  const jumpTo = useLatestCallback(key => {
244
245
  const index = trimmedRoutes.findIndex(route => route.key === key);
@@ -327,7 +328,7 @@ const BottomTabs = ({
327
328
  style: styles.fullWidth,
328
329
  items: items,
329
330
  icons: renderCustomTabBar ? undefined : resolvedIconAssets,
330
- selectedIcons: isIOS && !renderCustomTabBar ? resolvedSelectedIconAssets : undefined,
331
+ selectedIcons: !renderCustomTabBar ? resolvedSelectedIconAssets : undefined,
331
332
  selectedPage: focusedKey,
332
333
  tabBarHidden: props.tabBarHidden ?? !!renderCustomTabBar,
333
334
  onTabDoublePress: handleTabDoublePress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-bottom-tabs",
3
- "version": "6.7.0-40",
3
+ "version": "6.7.0-42",
4
4
  "description": "Native bottom tabs (tab bar + scene container) for React Native on iOS and Android",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -335,6 +335,24 @@ interface Props<Route extends BaseRoute> {
335
335
  onSideAccessoryPress?: () => void;
336
336
  }
337
337
 
338
+ const defaultGetBadge = ({ route }: { route: BaseRoute }) => route.badge;
339
+ const defaultGetBadgeBackgroundColor = ({ route }: { route: BaseRoute }) =>
340
+ route.badgeBackgroundColor;
341
+ const defaultGetBadgeTextColor = ({ route }: { route: BaseRoute }) =>
342
+ route.badgeTextColor;
343
+ const defaultGetLazy = ({ route }: { route: BaseRoute }) => route.lazy;
344
+ const defaultGetLabelText = ({ route }: { route: BaseRoute }) => route.title;
345
+ const defaultGetHidden = ({ route }: { route: BaseRoute }) => route.hidden;
346
+ const defaultGetActiveTintColor = ({ route }: { route: BaseRoute }) =>
347
+ route.activeTintColor;
348
+ const defaultGetTestID = ({ route }: { route: BaseRoute }) => route.testID;
349
+ const defaultGetRole = ({ route }: { route: BaseRoute }) => route.role;
350
+ const defaultGetSceneStyle = ({ route }: { route: BaseRoute }) => route.style;
351
+ const defaultGetPreventsDefault = ({ route }: { route: BaseRoute }) =>
352
+ route.preventsDefault;
353
+ const defaultGetFreezeOnBlur = ({ route }: { route: BaseRoute }) =>
354
+ route.freezeOnBlur;
355
+
338
356
  const defaultGetIcon = ({
339
357
  route,
340
358
  focused,
@@ -363,22 +381,21 @@ const BottomTabs = <Route extends BaseRoute>({
363
381
  rippleColor,
364
382
  tabBarActiveTintColor: activeTintColor,
365
383
  tabBarInactiveTintColor: inactiveTintColor,
366
- getBadge = ({ route }: { route: Route }) => route.badge,
367
- getBadgeBackgroundColor = ({ route }: { route: Route }) =>
368
- route.badgeBackgroundColor,
369
- getBadgeTextColor = ({ route }: { route: Route }) => route.badgeTextColor,
370
- getLazy = ({ route }: { route: Route }) => route.lazy,
371
- getLabelText = ({ route }: { route: Route }) => route.title,
384
+ getBadge = defaultGetBadge,
385
+ getBadgeBackgroundColor = defaultGetBadgeBackgroundColor,
386
+ getBadgeTextColor = defaultGetBadgeTextColor,
387
+ getLazy = defaultGetLazy,
388
+ getLabelText = defaultGetLabelText,
372
389
  getIcon = defaultGetIcon,
373
- getHidden = ({ route }: { route: Route }) => route.hidden,
374
- getActiveTintColor = ({ route }: { route: Route }) => route.activeTintColor,
375
- getTestID = ({ route }: { route: Route }) => route.testID,
376
- getRole = ({ route }: { route: Route }) => route.role,
377
- getSceneStyle = ({ route }: { route: Route }) => route.style,
378
- getPreventsDefault = ({ route }: { route: Route }) => route.preventsDefault,
390
+ getHidden = defaultGetHidden,
391
+ getActiveTintColor = defaultGetActiveTintColor,
392
+ getTestID = defaultGetTestID,
393
+ getRole = defaultGetRole,
394
+ getSceneStyle = defaultGetSceneStyle,
395
+ getPreventsDefault = defaultGetPreventsDefault,
379
396
  hapticFeedbackEnabled = false,
380
397
  labeled = Platform.OS !== "android" ? true : undefined,
381
- getFreezeOnBlur = ({ route }: { route: Route }) => route.freezeOnBlur,
398
+ getFreezeOnBlur = defaultGetFreezeOnBlur,
382
399
  tabBar: renderCustomTabBar,
383
400
  tabBarStyle,
384
401
  tabLabelStyle,
@@ -441,33 +458,20 @@ const BottomTabs = <Route extends BaseRoute>({
441
458
  () => trimmedRoutes.map((route) => getIcon({ route, focused: false })),
442
459
  [getIcon, trimmedRoutes]
443
460
  );
444
- // Focused (solid) icons — also stable; handed to iOS as selectedImage.
461
+ // Focused (solid) icons — also stable; handed to native as selectedIcons so
462
+ // both iOS and Android swap focused artwork synchronously on the UI thread
463
+ // without waiting for a JS round-trip.
445
464
  const focusedIcons = React.useMemo(
446
465
  () => trimmedRoutes.map((route) => getIcon({ route, focused: true })),
447
466
  [getIcon, trimmedRoutes]
448
467
  );
449
- // Legacy single array driven by focusedKey. Android still swaps the icon in
450
- // JS (it has no selectedImage equivalent).
451
- const focusKeyedIcons = React.useMemo(
452
- () =>
453
- trimmedRoutes.map((route) =>
454
- getIcon({
455
- route,
456
- focused: route.key === focusedKey,
457
- })
458
- ),
459
- [focusedKey, getIcon, trimmedRoutes]
460
- );
461
468
 
462
- // iOS hands both states to UIKit (image + selectedImage) so the focused
463
- // artwork swaps natively, in sync with the selection animation, instead of
464
- // waiting for a JS round-trip. Android keeps the focusedKey-driven array.
465
- const icons = isIOS ? unfocusedIcons : focusKeyedIcons;
469
+ const icons = unfocusedIcons;
466
470
 
467
471
  const items: BottomTabsItems[number][] = React.useMemo(
468
472
  () =>
469
473
  trimmedRoutes.map((route, index) => {
470
- const icon = icons[index];
474
+ const icon = unfocusedIcons[index];
471
475
  const isSfSymbol = isAppleSymbol(icon);
472
476
 
473
477
  if (Platform.OS === "android" && isSfSymbol) {
@@ -498,7 +502,7 @@ const BottomTabs = <Route extends BaseRoute>({
498
502
  }),
499
503
  [
500
504
  trimmedRoutes,
501
- icons,
505
+ unfocusedIcons,
502
506
  getLabelText,
503
507
  getBadge,
504
508
  getBadgeBackgroundColor,
@@ -516,8 +520,6 @@ const BottomTabs = <Route extends BaseRoute>({
516
520
  [icons]
517
521
  );
518
522
 
519
- // Focused (solid) assets passed to iOS as selectedImage. iOS only — Android
520
- // ignores selectedIcons and keeps swapping via the focusedKey array above.
521
523
  const resolvedSelectedIconAssets = React.useMemo(
522
524
  () => focusedIcons.map((icon) => resolveTabIconSource(icon)),
523
525
  [focusedIcons]
@@ -628,9 +630,7 @@ const BottomTabs = <Route extends BaseRoute>({
628
630
  items={items}
629
631
  icons={renderCustomTabBar ? undefined : resolvedIconAssets}
630
632
  selectedIcons={
631
- isIOS && !renderCustomTabBar
632
- ? resolvedSelectedIconAssets
633
- : undefined
633
+ !renderCustomTabBar ? resolvedSelectedIconAssets : undefined
634
634
  }
635
635
  selectedPage={focusedKey}
636
636
  tabBarHidden={props.tabBarHidden ?? !!renderCustomTabBar}