@momo-kits/native-kits 0.168.1-beta.4-debug → 0.168.1-beta.40-debug

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 (100) hide show
  1. package/CLAUDE.md +15 -10
  2. package/README.md +2 -10
  3. package/build.gradle.kts +1 -3
  4. package/compose/build.gradle.kts +20 -19
  5. package/compose/build.gradle.kts.backup +19 -18
  6. package/compose/compose.podspec +1 -1
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +4 -3
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +1 -1
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -14
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +14 -23
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +84 -82
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -1
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +18 -14
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +20 -13
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +117 -62
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +22 -6
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -26
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +54 -36
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +1 -6
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +35 -29
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +2 -3
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +89 -198
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +1 -1
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +30 -44
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +2 -2
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +32 -40
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +12 -3
  43. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +3 -1
  44. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +2 -6
  45. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -10
  46. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  47. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +60 -10
  48. package/gradle/libs.versions.toml +4 -11
  49. package/gradle/wrapper/gradle-wrapper.properties +1 -3
  50. package/gradle.properties +3 -3
  51. package/ios/Application/ApplicationEnvironment.swift +7 -6
  52. package/ios/Application/DesignSystemKits.swift +163 -0
  53. package/ios/Application/DesignSystemKitsPayload.swift +68 -0
  54. package/ios/Badge/BadgeRibbon.swift +8 -1
  55. package/ios/Extensions/Color++.swift +2 -4
  56. package/ios/Input/Input.swift +16 -4
  57. package/ios/Input/InputPhoneNumber.swift +1 -3
  58. package/ios/Input/InputSearch.swift +1 -2
  59. package/ios/Input/InputTextArea.swift +8 -4
  60. package/ios/InputMoney/InputMoney.swift +6 -7
  61. package/ios/Layout/ModalLayout.swift +152 -0
  62. package/ios/Layout/ScreenLayout.swift +77 -18
  63. package/ios/Navigation/BottomSheet.swift +56 -53
  64. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  65. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  66. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  67. package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
  68. package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
  69. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  70. package/ios/Navigation/Component/HeaderBackground.swift +22 -1
  71. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  72. package/ios/Navigation/Component/SnackBar.swift +4 -0
  73. package/ios/Navigation/ModalScreen.swift +20 -5
  74. package/ios/Navigation/StackScreen.swift +6 -8
  75. package/ios/Popup/PopupDisplay.swift +6 -4
  76. package/ios/Popup/PopupInput.swift +6 -4
  77. package/ios/Popup/PopupLayout.swift +17 -11
  78. package/ios/Popup/PopupNotify.swift +32 -25
  79. package/ios/Stepper/Stepper.swift +1 -2
  80. package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
  81. package/ios/Typography/FontScale.swift +29 -15
  82. package/ios/Typography/Text.swift +88 -14
  83. package/ios/Typography/Typography.swift +2 -2
  84. package/ios/native-kits.podspec +1 -1
  85. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  86. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  87. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  88. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  89. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  90. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  91. package/package.json +1 -1
  92. package/publish.sh +2 -33
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -18
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +0 -37
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -41
  97. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +0 -44
  98. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -62
  99. package/ios/Typography/FontScaleStore.swift +0 -58
  100. package/ios/Typography/KitDesignSystem.swift +0 -17
@@ -1,9 +1,11 @@
1
1
  package vn.momo.kits.navigation
2
2
 
3
3
  import androidx.compose.foundation.layout.Box
4
+ import androidx.compose.foundation.layout.absolutePadding
4
5
  import androidx.compose.foundation.layout.fillMaxSize
5
6
  import androidx.compose.runtime.Composable
6
7
  import androidx.compose.runtime.MutableState
8
+ import androidx.compose.runtime.key
7
9
  import androidx.compose.runtime.mutableStateOf
8
10
  import androidx.compose.runtime.staticCompositionLocalOf
9
11
  import androidx.compose.ui.Alignment
@@ -19,12 +21,11 @@ import kotlinx.coroutines.launch
19
21
  import kotlinx.serialization.Serializable
20
22
  import vn.momo.kits.components.PopupAction
21
23
  import vn.momo.kits.components.PopupNotify
24
+ import vn.momo.kits.layout.getScreenLayout
25
+ import vn.momo.kits.modifier.conditional
22
26
  import vn.momo.kits.navigation.BottomHeader.*
23
27
  import vn.momo.kits.navigation.component.SnackBar
24
28
  import vn.momo.maxapi.IMaxApi
25
- // AI-GENERATED START: dismiss through the typed navigator target
26
- import vn.momo.maxapi.contract.navigation.model.DismissTarget
27
- // AI-GENERATED END: dismiss through the typed navigator target
28
29
  import kotlin.time.Duration.Companion.milliseconds
29
30
 
30
31
  class Navigator(
@@ -116,9 +117,10 @@ class Navigator(
116
117
  }
117
118
  }
118
119
  private suspend fun dismissOverplay(isDelay: Boolean = true) {
120
+ val dismissing = OverplayComponentRegistry.current()
119
121
  OverplayComponentRegistry.clear()
120
122
  if (isDelay) delay(300L.milliseconds)
121
- OverplayComponentRegistry.hardClearAfterDismiss()
123
+ OverplayComponentRegistry.hardClearAfterDismiss(dismissing)
122
124
  }
123
125
 
124
126
  private suspend fun dismissScreen() {
@@ -128,9 +130,7 @@ class Navigator(
128
130
  delay(STACK_TRANSITION_DURATION.milliseconds)
129
131
  dismissing?.let { registry.unregisterScreen(it.id) }
130
132
  } else {
131
- // AI-GENERATED START: preserve root-screen dismissal
132
- maxApi?.dismiss(DismissTarget.Current()) {}
133
- // AI-GENERATED END: preserve root-screen dismissal
133
+ maxApi?.dismiss { }
134
134
  }
135
135
  }
136
136
 
@@ -187,9 +187,10 @@ class Navigator(
187
187
 
188
188
  fun hideSnackBar() {
189
189
  scope.launch {
190
+ val dismissing = OverplayComponentRegistry.current()
190
191
  OverplayComponentRegistry.clear()
191
192
  delay(250L.milliseconds)
192
- OverplayComponentRegistry.hardClearAfterDismiss()
193
+ OverplayComponentRegistry.hardClearAfterDismiss(dismissing)
193
194
  }
194
195
  }
195
196
 
@@ -363,42 +364,59 @@ object OverplayComponentRegistry {
363
364
  requestClose = null
364
365
  }
365
366
 
367
+ internal fun current(): OverplayComponent? = currentOverlayComponent.value
368
+
369
+ // An overlay shown from the dismissed one's onDismiss, before the delayed clear, stays.
370
+ internal fun hardClearAfterDismiss(dismissing: OverplayComponent?) {
371
+ if (currentOverlayComponent.value === dismissing) hardClearAfterDismiss()
372
+ }
373
+
366
374
  @Composable
367
375
  internal fun OverlayComponent(){
368
376
  val overplay = currentOverlayComponent.value ?: return
369
377
 
370
- when (val params = overplay.params) {
371
- is OverplayComponentParams.BottomSheet -> {
372
- BottomSheet(
373
- content = overplay.content,
374
- header = params.bottomSheetHeader ?: Title(),
375
- isSurface = params.isSurface,
376
- barrierDismissible = params.barrierDismissible,
377
- draggable = params.draggable,
378
- useBottomInset = params.useBottomInset,
379
- footerComponent = params.footerComponent,
380
- onDismiss = params.onDismiss
381
- )
382
- }
378
+ // every registration is its own composition (params are new instances), as SwiftUI's `.id(item.id)`:
379
+ // a sheet shown from another one's close must not inherit its finished animation and effects
380
+ key(overplay) {
381
+ when (val params = overplay.params) {
382
+ is OverplayComponentParams.BottomSheet -> {
383
+ BottomSheet(
384
+ content = overplay.content,
385
+ header = params.bottomSheetHeader ?: Title(),
386
+ isSurface = params.isSurface,
387
+ barrierDismissible = params.barrierDismissible,
388
+ draggable = params.draggable,
389
+ useBottomInset = params.useBottomInset,
390
+ footerComponent = params.footerComponent,
391
+ onDismiss = params.onDismiss
392
+ )
393
+ }
383
394
 
384
- is OverplayComponentParams.Modal -> {
385
- ModalScreen(
386
- content = overplay.content,
387
- barrierDismissible = params.barrierDismissible,
388
- onDismiss = params.onDismiss
389
- )
390
- }
395
+ is OverplayComponentParams.Modal -> {
396
+ ModalScreen(
397
+ content = overplay.content,
398
+ barrierDismissible = params.barrierDismissible,
399
+ onDismiss = params.onDismiss
400
+ )
401
+ }
391
402
 
392
- is OverplayComponentParams.SnackBar -> {
393
- Box(
394
- modifier = Modifier.fillMaxSize(),
395
- contentAlignment = Alignment.BottomCenter
396
- ) {
397
- overplay.content()
403
+ is OverplayComponentParams.SnackBar -> {
404
+ val layout = getScreenLayout()
405
+ Box(
406
+ modifier = Modifier
407
+ .fillMaxSize()
408
+ // iPhone Duo: clear of the side toolbar strip, like the screen content
409
+ .conditional(layout.isIPhoneDuo) {
410
+ absolutePadding(left = layout.insetLeft, right = layout.insetRight)
411
+ },
412
+ contentAlignment = Alignment.BottomCenter
413
+ ) {
414
+ overplay.content()
415
+ }
398
416
  }
399
- }
400
417
 
401
- null -> {}
418
+ null -> {}
419
+ }
402
420
  }
403
421
  }
404
422
  }
@@ -29,6 +29,7 @@ import androidx.compose.foundation.verticalScroll
29
29
  import androidx.compose.material.ExperimentalMaterialApi
30
30
  import androidx.compose.runtime.Composable
31
31
  import androidx.compose.runtime.CompositionLocalProvider
32
+ import androidx.compose.foundation.layout.PaddingValues
32
33
  import androidx.compose.runtime.LaunchedEffect
33
34
  import androidx.compose.runtime.State
34
35
  import androidx.compose.runtime.getValue
@@ -61,7 +62,6 @@ import vn.momo.kits.const.Colors
61
62
  import vn.momo.kits.const.Spacing
62
63
  import vn.momo.kits.modifier.conditional
63
64
  import vn.momo.kits.modifier.hideKeyboardOnTap
64
- import vn.momo.kits.navigation.bottomtab.BOTTOM_TAB_BAR_HEIGHT
65
65
  import vn.momo.kits.navigation.component.FABPosition
66
66
  import vn.momo.kits.navigation.component.FloatingButton
67
67
  import vn.momo.kits.navigation.component.HEADER_HEIGHT
@@ -70,6 +70,7 @@ import vn.momo.kits.navigation.component.HeaderBackground
70
70
  import vn.momo.kits.navigation.component.HeaderRight
71
71
  import vn.momo.kits.navigation.component.HeaderSideBar
72
72
  import vn.momo.kits.navigation.bottomtab.LocalDuoRailReserve
73
+ import vn.momo.kits.navigation.bottomtab.LocalTabBarHasCenterAction
73
74
  import vn.momo.kits.navigation.bottomtab.duoFloatingTabBarInset
74
75
  import vn.momo.kits.navigation.component.HeaderType
75
76
  import vn.momo.kits.navigation.component.InputSearchType
@@ -90,21 +91,27 @@ import kotlin.time.Clock
90
91
  import kotlin.time.Duration.Companion.milliseconds
91
92
  import kotlin.time.ExperimentalTime
92
93
 
94
+ @Composable
95
+ fun floatingTabBarContentPadding(): PaddingValues {
96
+ val navigation = LocalNavigation.current
97
+ LaunchedEffect(navigation) { navigation.bottomTabEdgeToEdge = true }
98
+ val reserve = navigation.bottomTabIndex != -1 && navigation.bottomTabEdgeToEdge
99
+ return PaddingValues(bottom = if (reserve) bottomTabChildInset() else 0.dp)
100
+ }
101
+
93
102
  internal val LocalFooterHeightPx = staticCompositionLocalOf { mutableIntStateOf(0) }
94
103
  internal val LocalHeaderRightWidthPx = staticCompositionLocalOf { mutableIntStateOf(0) }
95
104
 
96
- // Space a tab's content leaves for the tab bar and home indicator. On iPhone Duo the floating bar
97
- // overlays the content and the rail lives in the side strip, so only their own inset applies.
105
+ // Space a tab's content leaves for the tab bar and home indicator: the horizontal bar floats over the
106
+ // content (phone and unfolded Duo); the Duo rail lives in the side strip, so only the home indicator.
98
107
  @Composable
99
108
  private fun bottomTabChildInset(): Dp {
100
109
  val keyboard = keyboardSizeState().value
101
110
  val navigationBar = AppNavigationBar.current
102
111
  val layout = getScreenLayout()
103
112
  return when {
104
- layout.isIPhoneDuo && layout.sideBar == null -> (duoFloatingTabBarInset(layout) - keyboard).coerceAtLeast(0.dp)
105
- layout.isIPhoneDuo -> (navigationBar - keyboard).coerceAtLeast(0.dp)
106
- else -> (BOTTOM_TAB_BAR_HEIGHT.dp + Spacing.S - keyboard).coerceAtLeast(0.dp) +
107
- (navigationBar - keyboard).coerceAtLeast(0.dp)
113
+ layout.isIPhoneDuo && layout.sideBar != null -> (navigationBar - keyboard).coerceAtLeast(0.dp)
114
+ else -> (duoFloatingTabBarInset(layout, LocalTabBarHasCenterAction.current) - keyboard).coerceAtLeast(0.dp)
108
115
  }
109
116
  }
110
117
 
@@ -333,7 +340,6 @@ internal fun ColumnScope.MainContent(content: @Composable () -> Unit, isBottomTa
333
340
 
334
341
  Spacer(Modifier.height((HEADER_HEIGHT.dp - scrollDp).coerceIn(0.dp, HEADER_HEIGHT.dp)))
335
342
  }
336
- // a bottom tab root stays full width: the tab bar and each tab's own StackScreen handle the insets
337
343
  val insetContent = !isBottomTabRoot
338
344
  Column(
339
345
  Modifier
@@ -351,7 +357,8 @@ internal fun ColumnScope.MainContent(content: @Composable () -> Unit, isBottomTa
351
357
  .padding(
352
358
  bottom = when {
353
359
  options.hasFooter() || isBottomTabRoot -> 0.dp
354
- isBottomTabChild -> bottomTabChildInset()
360
+ // 0 when the tab pads itself via floatingTabBarContentPadding(), else the kit reserves the bar space
361
+ isBottomTabChild -> if (LocalNavigation.current.bottomTabEdgeToEdge) 0.dp else bottomTabChildInset()
355
362
  !options.scrollData.scrollable && options.scrollData.scrollState == null -> 0.dp
356
363
  else -> navigationBar
357
364
  }
@@ -401,8 +408,8 @@ internal fun FooterContent() {
401
408
  val options = LocalOptions.current
402
409
  if (options.hasFooter()) {
403
410
  val keyboardSize = keyboardSizeState()
404
- // the Duo floating tab bar overlays tab content, so a tab's footer sits above it
405
- val duoTabInset = if (LocalNavigation.current.bottomTabIndex != -1) duoFloatingTabBarInset(getScreenLayout()) else 0.dp
411
+ // the floating tab bar overlays tab content, so a tab's footer sits above it
412
+ val duoTabInset = if (LocalNavigation.current.bottomTabIndex != -1) duoFloatingTabBarInset(getScreenLayout(), LocalTabBarHasCenterAction.current) else 0.dp
406
413
  val bottomPadding = (maxOf(AppNavigationBar.current, duoTabInset) - keyboardSize.value).coerceAtLeast(0.dp)
407
414
  Footer(
408
415
  footerComponent = options.footerComponent,
@@ -6,9 +6,6 @@ import androidx.compose.runtime.snapshotFlow
6
6
  import vn.momo.kits.platform.getScreenDimensions
7
7
  import vn.momo.kits.platform.rememberBackGestureProgress
8
8
  import vn.momo.maxapi.IMaxApi
9
- // AI-GENERATED START: use the typed light vibration pattern
10
- import vn.momo.maxapi.contract.device.vibration.model.VibrateStyle
11
- // AI-GENERATED END: use the typed light vibration pattern
12
9
 
13
10
  // Unscaled, so the tick lands at the same physical distance on every device.
14
11
  private const val SWIPE_BACK_HAPTIC_THRESHOLD_DP = 50f
@@ -28,9 +25,7 @@ internal fun SwipeBackHaptic(maxApi: IMaxApi?) {
28
25
  snapshotFlow { progress.value }.collect { fraction ->
29
26
  val travelled = fraction ?: 0f
30
27
  if (travelled >= threshold && !isSendHaptic) {
31
- // AI-GENERATED START: keep one light tick per threshold crossing
32
- runCatching { maxApi.vibrate(VibrateStyle.LIGHT) }
33
- // AI-GENERATED END: keep one light tick per threshold crossing
28
+ runCatching { maxApi.triggerEventVibration("light", callback = null) }
34
29
  isSendHaptic = true
35
30
  } else if (travelled < threshold && isSendHaptic) {
36
31
  isSendHaptic = false
@@ -1,7 +1,10 @@
1
1
  package vn.momo.kits.navigation.bottomtab
2
2
 
3
+ import androidx.compose.runtime.getValue
4
+ import androidx.compose.runtime.setValue
3
5
  import androidx.compose.animation.core.Animatable
4
6
  import androidx.compose.animation.core.AnimationVector1D
7
+ import androidx.compose.animation.core.CubicBezierEasing
5
8
  import androidx.compose.animation.core.Easing
6
9
  import androidx.compose.animation.core.tween
7
10
  import androidx.compose.foundation.background
@@ -10,14 +13,12 @@ import androidx.compose.runtime.Composable
10
13
  import androidx.compose.runtime.CompositionLocalProvider
11
14
  import androidx.compose.runtime.DisposableEffect
12
15
  import androidx.compose.runtime.LaunchedEffect
13
- import androidx.compose.runtime.getValue
14
16
  import androidx.compose.runtime.key
15
17
  import androidx.compose.runtime.mutableIntStateOf
16
18
  import androidx.compose.runtime.mutableStateOf
17
19
  import androidx.compose.runtime.remember
18
20
  import androidx.compose.runtime.saveable.rememberSaveable
19
21
  import androidx.compose.runtime.saveable.rememberSaveableStateHolder
20
- import androidx.compose.runtime.setValue
21
22
  import androidx.compose.runtime.staticCompositionLocalOf
22
23
  import androidx.compose.ui.Alignment
23
24
  import androidx.compose.ui.Modifier
@@ -25,9 +26,8 @@ import androidx.compose.ui.graphics.graphicsLayer
25
26
  import androidx.compose.ui.layout.layout
26
27
  import androidx.compose.ui.unit.dp
27
28
  import androidx.compose.ui.zIndex
28
- import vn.momo.kits.const.AppNavigationBar
29
+ import kotlin.math.abs
29
30
  import vn.momo.kits.const.AppTheme
30
- import vn.momo.kits.const.Spacing
31
31
  import vn.momo.kits.navigation.KeyboardOptions
32
32
  import vn.momo.kits.navigation.LocalMaxApi
33
33
  import vn.momo.kits.navigation.LocalNavigation
@@ -39,12 +39,13 @@ import vn.momo.kits.platform.BackHandler
39
39
  import vn.momo.kits.platform.reportFloatingArrowBack
40
40
  import vn.momo.kits.layout.getScreenLayout
41
41
  import kotlinx.coroutines.launch
42
- // AI-GENERATED START: use the typed tab haptic pattern
43
- import vn.momo.maxapi.contract.device.vibration.model.VibrateStyle
44
- // AI-GENERATED END: use the typed tab haptic pattern
45
42
 
46
- private val inOutQuad = Easing { t -> if (t < 0.5f) 2 * t * t else 1 - 2 * (1 - t) * (1 - t) }
47
- internal val tabTimingSpec = tween<Float>(durationMillis = 200, easing = inOutQuad)
43
+ internal val inOutQuad = Easing { t -> if (t < 0.5f) 2 * t * t else 1 - 2 * (1 - t) * (1 - t) }
44
+ // the tab screens slide in index order over 280ms, CSS `ease`
45
+ private val tabSwitchSpec = tween<Float>(durationMillis = 280, easing = CubicBezierEasing(0.25f, 0.1f, 0.25f, 1f))
46
+
47
+ // -1 for tabs before the selected one, 1 for tabs after it: they wait a full width off screen on their side
48
+ private fun tabPosition(index: Int, selected: Int) = (index - selected).coerceIn(-1, 1).toFloat()
48
49
 
49
50
  internal val LocalBottomTabFocused = staticCompositionLocalOf { true }
50
51
 
@@ -108,14 +109,21 @@ fun BottomTab(
108
109
  var lastFocusedIndex by rememberSaveable { mutableStateOf<Int?>(null) }
109
110
  val tabProgress = remember { mutableMapOf<Int, Animatable<Float, AnimationVector1D>>() }
110
111
  fun progressOf(index: Int) = tabProgress.getOrPut(index) {
111
- Animatable(if (index == lastFocusedIndex) 1f else 0f)
112
+ Animatable(tabPosition(index, lastFocusedIndex ?: index))
112
113
  }
113
114
  LaunchedEffect(selectedIndex) {
115
+ val previousIndex = lastFocusedIndex
114
116
  lastFocusedIndex = selectedIndex
115
117
  tabProgress.forEach { (index, progress) ->
116
- if (index != selectedIndex) launch { progress.animateTo(0f, tabTimingSpec) }
118
+ val target = tabPosition(index, selectedIndex)
119
+ launch {
120
+ if (index == selectedIndex || index == previousIndex) {
121
+ progress.animateTo(target, tabSwitchSpec)
122
+ } else {
123
+ progress.snapTo(target)
124
+ }
125
+ }
117
126
  }
118
- progressOf(selectedIndex).animateTo(1f, tabTimingSpec)
119
127
  }
120
128
 
121
129
  DisposableEffect(isFirstTab) {
@@ -135,9 +143,7 @@ fun BottomTab(
135
143
  it.bottom + duoRailHeight(items.size, hasQr, compressed = compression.tabBarCompressed) + DUO_GROUP_GAP
136
144
  } ?: 0.dp
137
145
  val onTabSelected: (Int) -> Unit = { index ->
138
- // AI-GENERATED START: preserve the light haptic on tab selection
139
- runCatching { maxApi?.vibrate(VibrateStyle.LIGHT) }
140
- // AI-GENERATED END: preserve the light haptic on tab selection
146
+ runCatching { maxApi?.triggerEventVibration("light", callback = null) }
141
147
  val switchTab = {
142
148
  if (index != selectedIndex) selectTab(index)
143
149
  }
@@ -152,21 +158,20 @@ fun BottomTab(
152
158
  CompositionLocalProvider(
153
159
  LocalDuoRailReserve provides railReserve,
154
160
  LocalDuoBarCompression provides compression,
161
+ LocalTabBarHasCenterAction provides hasCenterAction(floatingButton, items.size),
155
162
  ) {
156
163
  loadedTabs.forEach { index ->
157
164
  val item = items.getOrNull(index) ?: return@forEach
158
165
  val focused = index == selectedIndex
159
166
  val progress = progressOf(index)
167
+ // the leaving tab stays drawn until it has slid off screen
168
+ val visible = focused || abs(progress.value) < 1f
160
169
  key(index) {
161
170
  Box(
162
171
  Modifier
163
172
  .fillMaxSize()
164
173
  .zIndex(if (focused) 0f else -1f)
165
- .then(if (focused) Modifier.graphicsLayer {
166
- alpha = 0.3f + 0.7f * progress.value
167
- scaleX = 0.97f + 0.03f * progress.value
168
- scaleY = scaleX
169
- } else Hidden)
174
+ .then(if (visible) Modifier.graphicsLayer { translationX = progress.value * size.width } else Hidden)
170
175
  ) {
171
176
  CompositionLocalProvider(LocalBottomTabFocused provides focused) {
172
177
  tabStateHolder.SaveableStateProvider(index) {
@@ -202,15 +207,12 @@ fun BottomTab(
202
207
  compression = compression,
203
208
  )
204
209
  } else {
205
- Column {
206
- BottomTabBar(
207
- items = items,
208
- floatingButton = floatingButton,
209
- selectedIndex = selectedIndex,
210
- onTabSelected = onTabSelected,
211
- )
212
- Spacer(modifier = Modifier.fillMaxWidth().height(AppNavigationBar.current + Spacing.S).background(AppTheme.current.colors.background.surface))
213
- }
210
+ BottomTabBar(
211
+ items = items,
212
+ floatingButton = floatingButton,
213
+ selectedIndex = selectedIndex,
214
+ onTabSelected = onTabSelected,
215
+ )
214
216
  }
215
217
  }
216
218
  }
@@ -230,4 +232,8 @@ data class BottomTabFloatingButton(
230
232
  val icon: String,
231
233
  val label: String,
232
234
  val onPress: () -> Unit,
235
+ // replaces the icon inside the 48 button, e.g. the button part of a Lottie; centered, unclipped
236
+ val iconContent: (@Composable () -> Unit)? = null,
237
+ // drawn over the label text, which stays, e.g. the label part of a Lottie; centered, unclipped
238
+ val labelContent: (@Composable () -> Unit)? = null,
233
239
  )