@momo-kits/native-kits 0.168.1-beta.24 → 0.168.1-beta.25-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 (146) hide show
  1. package/CLAUDE.md +1 -0
  2. package/build.gradle.kts +11 -0
  3. package/compose/build.gradle.kts +198 -0
  4. package/compose/build.gradle.kts.backup +198 -0
  5. package/compose/compose.podspec +47 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +153 -0
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +370 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +321 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +499 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +148 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +116 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +732 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +232 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +237 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +436 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +74 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +20 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +218 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +138 -0
  132. package/gradle/libs.versions.toml +69 -0
  133. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  134. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  135. package/gradle.properties +26 -0
  136. package/gradlew +252 -0
  137. package/gradlew.bat +94 -0
  138. package/ios/Navigation/BottomTab/BottomTab.swift +16 -3
  139. package/ios/Navigation/BottomTab/BottomTabBar.swift +47 -29
  140. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
  141. package/ios/Navigation/BottomTab/DuoTabBar.swift +156 -69
  142. package/ios/native-kits.podspec +1 -1
  143. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  144. package/ios-demo/README.md +120 -0
  145. package/package.json +1 -1
  146. package/settings.gradle.kts +64 -0
@@ -0,0 +1,148 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.animation.AnimatedContentTransitionScope
4
+ import androidx.compose.animation.AnimatedVisibilityScope
5
+ import androidx.compose.animation.EnterExitState
6
+ import androidx.compose.animation.EnterTransition
7
+ import androidx.compose.animation.ExitTransition
8
+ import androidx.compose.animation.core.LinearEasing
9
+ import androidx.compose.animation.core.animateFloat
10
+ import androidx.compose.animation.core.tween
11
+ import androidx.compose.animation.slideInHorizontally
12
+ import androidx.compose.animation.slideOutHorizontally
13
+ import androidx.compose.foundation.layout.Box
14
+ import androidx.compose.foundation.layout.fillMaxSize
15
+ import androidx.compose.runtime.Composable
16
+ import androidx.compose.runtime.DisposableEffect
17
+ import androidx.compose.runtime.Stable
18
+ import androidx.compose.runtime.derivedStateOf
19
+ import androidx.compose.runtime.getValue
20
+ import androidx.compose.runtime.mutableStateMapOf
21
+ import androidx.compose.runtime.remember
22
+ import androidx.compose.runtime.staticCompositionLocalOf
23
+ import androidx.compose.ui.Modifier
24
+ import androidx.compose.ui.draw.drawBehind
25
+ import androidx.compose.ui.geometry.Offset
26
+ import androidx.compose.ui.geometry.Size
27
+ import androidx.compose.ui.graphics.Brush
28
+ import androidx.compose.ui.graphics.Color
29
+ import androidx.compose.ui.platform.LocalDensity
30
+ import androidx.compose.ui.unit.IntOffset
31
+ import androidx.compose.ui.unit.dp
32
+ import androidx.navigation.NavBackStackEntry
33
+ import androidx.navigation.NavDestination.Companion.hasRoute
34
+ import vn.momo.kits.const.Colors
35
+ import kotlin.math.roundToInt
36
+
37
+ internal const val STACK_TRANSITION_DURATION = 300
38
+
39
+ // Ported 1:1 from the RN kit's `forStackTransitionWithOverlay` so both kits look identical.
40
+ private const val PARALLAX_RATIO = 0.3f
41
+ private const val SCRIM_MAX_ALPHA = 0.6f
42
+ private const val EDGE_SHADOW_MAX_ALPHA = 0.3f
43
+ private val EDGE_SHADOW_WIDTH = 8.dp
44
+
45
+ /** Kill switch: `false` restores pre-DS-760 back handling without a kit release. Transitions
46
+ * stay on the new curve either way. */
47
+ object SwipeBackConfig {
48
+ var enabled: Boolean = true
49
+ }
50
+
51
+ // LinearEasing is mandatory: seekTo() maps drag fraction onto the timeline, so a curve would
52
+ // decouple the card from the finger.
53
+ private val stackSpec = tween<IntOffset>(STACK_TRANSITION_DURATION, easing = LinearEasing)
54
+
55
+ internal fun AnimatedContentTransitionScope<NavBackStackEntry>.stackEnter(): EnterTransition =
56
+ slideInHorizontally(stackSpec) { it }
57
+
58
+ internal fun AnimatedContentTransitionScope<NavBackStackEntry>.stackExit(): ExitTransition =
59
+ if (targetState.destination.hasRoute<DynamicDialogRoute>()) ExitTransition.None
60
+ else slideOutHorizontally(stackSpec) { -(it * PARALLAX_RATIO).roundToInt() }
61
+
62
+ internal fun AnimatedContentTransitionScope<NavBackStackEntry>.stackPopEnter(): EnterTransition =
63
+ if (initialState.destination.hasRoute<DynamicDialogRoute>()) EnterTransition.None
64
+ else slideInHorizontally(stackSpec) { -(it * PARALLAX_RATIO).roundToInt() }
65
+
66
+ internal fun AnimatedContentTransitionScope<NavBackStackEntry>.stackPopExit(): ExitTransition =
67
+ slideOutHorizontally(stackSpec) { it }
68
+
69
+ /**
70
+ * Which composed screen is the top card. Ids are monotonic and NavHost keeps both entries composed
71
+ * for the whole segment, so "highest id" is stable both ways. `currentBackStackEntry` is not: it
72
+ * flips at frame 0 of a pop and the scrim would vanish instead of fading.
73
+ */
74
+ @Stable
75
+ internal class StackTransitionCoordinator {
76
+ private val composedRoutes = mutableStateMapOf<Int, Boolean>()
77
+
78
+ val topStackId: Int by derivedStateOf {
79
+ composedRoutes.entries.filter { it.value }.maxOfOrNull { it.key } ?: -1
80
+ }
81
+
82
+ fun attach(id: Int, isStackRoute: Boolean) {
83
+ composedRoutes[id] = isStackRoute
84
+ }
85
+
86
+ fun detach(id: Int) {
87
+ composedRoutes.remove(id)
88
+ }
89
+ }
90
+
91
+ internal val LocalStackTransition = staticCompositionLocalOf { StackTransitionCoordinator() }
92
+
93
+ /** Draws the covered-screen scrim and the top card's left-edge shadow around a stack destination. */
94
+ @Composable
95
+ internal fun AnimatedVisibilityScope.StackTransitionDecor(
96
+ id: Int,
97
+ isStackRoute: Boolean,
98
+ content: @Composable () -> Unit,
99
+ ) {
100
+ val coordinator = LocalStackTransition.current
101
+ coordinator.attach(id, isStackRoute)
102
+ DisposableEffect(coordinator, id) {
103
+ onDispose { coordinator.detach(id) }
104
+ }
105
+
106
+ val isTopCard = isStackRoute && id == coordinator.topStackId
107
+ val isCovered = isStackRoute && !isTopCard
108
+
109
+ val scrimAlpha = transition.animateFloat(
110
+ transitionSpec = { tween(STACK_TRANSITION_DURATION, easing = LinearEasing) },
111
+ label = "stackScrimAlpha",
112
+ ) { state -> if (isCovered && state != EnterExitState.Visible) SCRIM_MAX_ALPHA else 0f }
113
+
114
+ val shadowAlpha = transition.animateFloat(
115
+ transitionSpec = { tween(STACK_TRANSITION_DURATION, easing = LinearEasing) },
116
+ label = "stackEdgeShadowAlpha",
117
+ ) { state -> if (isTopCard && state == EnterExitState.Visible) EDGE_SHADOW_MAX_ALPHA else 0f }
118
+
119
+ val shadowWidthPx = with(LocalDensity.current) { EDGE_SHADOW_WIDTH.toPx() }
120
+ val shadowBrush = remember(shadowWidthPx) {
121
+ Brush.horizontalGradient(
122
+ colors = listOf(Color.Transparent, Colors.black_20),
123
+ startX = -shadowWidthPx,
124
+ endX = 0f,
125
+ )
126
+ }
127
+
128
+ Box(Modifier.fillMaxSize()) {
129
+ content()
130
+
131
+ if (isStackRoute) {
132
+ Box(
133
+ Modifier
134
+ .matchParentSize()
135
+ // read inside drawBehind: in the body this would recompose every gesture frame
136
+ .drawBehind {
137
+ drawRect(
138
+ brush = shadowBrush,
139
+ topLeft = Offset(-shadowWidthPx, 0f),
140
+ size = Size(shadowWidthPx, size.height),
141
+ alpha = shadowAlpha.value,
142
+ )
143
+ drawRect(Colors.pink_09, alpha = scrimAlpha.value)
144
+ }
145
+ )
146
+ }
147
+ }
148
+ }
@@ -0,0 +1,35 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.LaunchedEffect
5
+ import androidx.compose.runtime.snapshotFlow
6
+ import vn.momo.kits.platform.getScreenDimensions
7
+ import vn.momo.kits.platform.rememberBackGestureProgress
8
+ import vn.momo.maxapi.IMaxApi
9
+
10
+ // Unscaled, so the tick lands at the same physical distance on every device.
11
+ private const val SWIPE_BACK_HAPTIC_THRESHOLD_DP = 50f
12
+
13
+ /** One light tick per crossing, re-armed below the threshold. iOS only. */
14
+ @Composable
15
+ internal fun SwipeBackHaptic(maxApi: IMaxApi?) {
16
+ if (maxApi == null) return
17
+
18
+ val progress = rememberBackGestureProgress()
19
+ val screenWidth = getScreenDimensions().width.toFloat()
20
+
21
+ LaunchedEffect(maxApi, screenWidth) {
22
+ if (screenWidth <= 0f) return@LaunchedEffect
23
+ val threshold = SWIPE_BACK_HAPTIC_THRESHOLD_DP / screenWidth
24
+ var isSendHaptic = false
25
+ snapshotFlow { progress.value }.collect { fraction ->
26
+ val travelled = fraction ?: 0f
27
+ if (travelled >= threshold && !isSendHaptic) {
28
+ runCatching { maxApi.triggerEventVibration("light", callback = null) }
29
+ isSendHaptic = true
30
+ } else if (travelled < threshold && isSendHaptic) {
31
+ isSendHaptic = false
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,232 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.animation.core.Animatable
4
+ import androidx.compose.animation.core.AnimationVector1D
5
+ import androidx.compose.animation.core.Easing
6
+ import androidx.compose.animation.core.tween
7
+ import androidx.compose.foundation.background
8
+ import androidx.compose.foundation.layout.*
9
+ import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.CompositionLocalProvider
11
+ import androidx.compose.runtime.DisposableEffect
12
+ import androidx.compose.runtime.LaunchedEffect
13
+ import androidx.compose.runtime.getValue
14
+ import androidx.compose.runtime.key
15
+ import androidx.compose.runtime.mutableIntStateOf
16
+ import androidx.compose.runtime.mutableStateOf
17
+ import androidx.compose.runtime.remember
18
+ import androidx.compose.runtime.saveable.rememberSaveable
19
+ import androidx.compose.runtime.saveable.rememberSaveableStateHolder
20
+ import androidx.compose.runtime.setValue
21
+ import androidx.compose.runtime.staticCompositionLocalOf
22
+ import androidx.compose.ui.Alignment
23
+ import androidx.compose.ui.Modifier
24
+ import androidx.compose.ui.graphics.graphicsLayer
25
+ import androidx.compose.ui.layout.layout
26
+ import androidx.compose.ui.unit.dp
27
+ import androidx.compose.ui.zIndex
28
+ import vn.momo.kits.const.AppNavigationBar
29
+ import vn.momo.kits.const.AppTheme
30
+ import vn.momo.kits.const.Spacing
31
+ import vn.momo.kits.navigation.KeyboardOptions
32
+ import vn.momo.kits.navigation.LocalMaxApi
33
+ import vn.momo.kits.navigation.LocalNavigation
34
+ import vn.momo.kits.navigation.LocalNavigator
35
+ import vn.momo.kits.navigation.NavigationOptions
36
+ import vn.momo.kits.navigation.StackScreen
37
+ import vn.momo.kits.navigation.component.HeaderType
38
+ import vn.momo.kits.platform.BackHandler
39
+ import vn.momo.kits.platform.reportFloatingArrowBack
40
+ import vn.momo.kits.layout.getScreenLayout
41
+ import kotlinx.coroutines.launch
42
+
43
+ private val inOutQuad = Easing { t -> if (t < 0.5f) 2 * t * t else 1 - 2 * (1 - t) * (1 - t) }
44
+ internal val tabTimingSpec = tween<Float>(durationMillis = 200, easing = inOutQuad)
45
+
46
+ internal val LocalBottomTabFocused = staticCompositionLocalOf { true }
47
+
48
+ private val Hidden = Modifier.layout { measurable, constraints ->
49
+ val placeable = measurable.measure(constraints)
50
+ layout(placeable.width, placeable.height) {}
51
+ }
52
+
53
+ private var bottomTabOptionItems : MutableList<NavigationOptions?> = mutableListOf()
54
+ internal fun setBottomTabOption(index: Int, options: NavigationOptions){
55
+ if (index in bottomTabOptionItems.indices) {
56
+ bottomTabOptionItems[index] = options
57
+ }
58
+ }
59
+ internal fun getBottomTabOption(index: Int): NavigationOptions? {
60
+ return if (index in bottomTabOptionItems.indices) {
61
+ bottomTabOptionItems[index]
62
+ } else null
63
+ }
64
+
65
+ @Composable
66
+ fun BottomTab(
67
+ items: List<BottomTabItem>,
68
+ floatingButton: BottomTabFloatingButton? = null,
69
+ // iPhone Duo: when the side bar can't hold both bars, which one starts compressed;
70
+ // tapping the compressed one swaps them
71
+ compressionBehavior: DuoBarCompressionBehavior = DuoBarCompressionBehavior.TOOLBAR,
72
+ initialRouteName: String? = null,
73
+ onTabPress: ((index: Int, switchTab: () -> Unit) -> Unit)? = null,
74
+ backToInitialTab: Boolean = true,
75
+ // RN tabLongPress; on iPhone Duo the held tab is still selected on release
76
+ onTabLongPress: ((index: Int) -> Unit)? = null,
77
+ ) {
78
+ val navigation = LocalNavigation.current
79
+ val navigator = LocalNavigator.current
80
+ val maxApi = LocalMaxApi.current
81
+ val startIndex = remember { items.indexOfFirst { it.name == initialRouteName }.coerceAtLeast(0) }
82
+
83
+ remember(items) {
84
+ bottomTabOptionItems = items.map { it.options ?: NavigationOptions() }.toMutableList()
85
+ }
86
+
87
+ LaunchedEffect(Unit){
88
+ navigation.markAsBottomTabRoot()
89
+ navigation.setOptions(
90
+ headerType = HeaderType.None,
91
+ keyboardOptions = KeyboardOptions(useAvoidKeyboard = false)
92
+ )
93
+ }
94
+
95
+ var selectedIndex by rememberSaveable { mutableIntStateOf(startIndex) }
96
+ var loadedTabs by rememberSaveable { mutableStateOf(listOf(startIndex)) }
97
+ val tabStateHolder = rememberSaveableStateHolder()
98
+ val selectTab: (Int) -> Unit = { index ->
99
+ if (index !in loadedTabs) loadedTabs = loadedTabs + index
100
+ selectedIndex = index
101
+ }
102
+
103
+ val onFirstTab = selectedIndex == 0
104
+ val isFirstTab = onFirstTab || !backToInitialTab
105
+ val backToFirstTab = { selectTab(0) }
106
+
107
+ var lastFocusedIndex by rememberSaveable { mutableStateOf<Int?>(null) }
108
+ val tabProgress = remember { mutableMapOf<Int, Animatable<Float, AnimationVector1D>>() }
109
+ fun progressOf(index: Int) = tabProgress.getOrPut(index) {
110
+ Animatable(if (index == lastFocusedIndex) 1f else 0f)
111
+ }
112
+ LaunchedEffect(selectedIndex) {
113
+ lastFocusedIndex = selectedIndex
114
+ tabProgress.forEach { (index, progress) ->
115
+ if (index != selectedIndex) launch { progress.animateTo(0f, tabTimingSpec) }
116
+ }
117
+ progressOf(selectedIndex).animateTo(1f, tabTimingSpec)
118
+ }
119
+
120
+ DisposableEffect(isFirstTab) {
121
+ reportFloatingArrowBack(!isFirstTab)
122
+ navigator.tabBackHandler = if (isFirstTab) null else ({ backToFirstTab() })
123
+
124
+ onDispose {
125
+ reportFloatingArrowBack(false)
126
+ navigator.tabBackHandler = null
127
+ }
128
+ }
129
+
130
+ val layout = getScreenLayout()
131
+ val hasQr = floatingButton != null
132
+ val compression = rememberDuoBarCompression(compressionBehavior, items.size, hasQr, layout)
133
+ val railReserve = layout.sideBar?.takeIf { layout.isIPhoneDuo }?.let {
134
+ it.bottom + duoRailHeight(items.size, hasQr, compressed = compression.tabBarCompressed) + DUO_GROUP_GAP
135
+ } ?: 0.dp
136
+ val onTabSelected: (Int) -> Unit = { index ->
137
+ runCatching { maxApi?.triggerEventVibration("light", callback = null) }
138
+ val switchTab = {
139
+ if (index != selectedIndex) selectTab(index)
140
+ }
141
+ onTabPress?.invoke(index, switchTab) ?: switchTab()
142
+ }
143
+
144
+ Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
145
+ Box(modifier = Modifier
146
+ .fillMaxSize()
147
+ .background(AppTheme.current.colors.background.default)
148
+ ) {
149
+ CompositionLocalProvider(
150
+ LocalDuoRailReserve provides railReserve,
151
+ LocalDuoBarCompression provides compression,
152
+ ) {
153
+ loadedTabs.forEach { index ->
154
+ val item = items.getOrNull(index) ?: return@forEach
155
+ val focused = index == selectedIndex
156
+ val progress = progressOf(index)
157
+ key(index) {
158
+ Box(
159
+ Modifier
160
+ .fillMaxSize()
161
+ .zIndex(if (focused) 0f else -1f)
162
+ .then(if (focused) Modifier.graphicsLayer {
163
+ alpha = 0.3f + 0.7f * progress.value
164
+ scaleX = 0.97f + 0.03f * progress.value
165
+ scaleY = scaleX
166
+ } else Hidden)
167
+ ) {
168
+ CompositionLocalProvider(LocalBottomTabFocused provides focused) {
169
+ tabStateHolder.SaveableStateProvider(index) {
170
+ StackScreen(
171
+ content = item.screen,
172
+ navigationOptions = getBottomTabOption(index),
173
+ bottomTabIndex = index,
174
+ onBackHandler = {
175
+ if (backToInitialTab && index != 0) {
176
+ backToFirstTab()
177
+ } else {
178
+ navigator.pop()
179
+ }
180
+ }
181
+ )
182
+ }
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ BackHandler(enabled = !onFirstTab) {
190
+ if (backToInitialTab) backToFirstTab() else navigator.pop()
191
+ }
192
+ if (layout.isIPhoneDuo) {
193
+ DuoTabBar(
194
+ layout = layout,
195
+ items = items,
196
+ floatingButton = floatingButton,
197
+ selectedIndex = selectedIndex,
198
+ onTabSelected = onTabSelected,
199
+ compression = compression,
200
+ onTabLongPress = onTabLongPress,
201
+ )
202
+ } else {
203
+ Column {
204
+ BottomTabBar(
205
+ items = items,
206
+ floatingButton = floatingButton,
207
+ selectedIndex = selectedIndex,
208
+ onTabSelected = onTabSelected,
209
+ onTabLongPress = onTabLongPress,
210
+ )
211
+ Spacer(modifier = Modifier.fillMaxWidth().height(AppNavigationBar.current + Spacing.S).background(AppTheme.current.colors.background.surface))
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ data class BottomTabItem(
218
+ val name: String,
219
+ val label: String,
220
+ val icon: String,
221
+ val showDot: Boolean = false,
222
+ val badgeLabel: String? = null,
223
+ val screen: @Composable () -> Unit,
224
+ val options: NavigationOptions? = null,
225
+ val initialParams: Any? = null
226
+ )
227
+
228
+ data class BottomTabFloatingButton(
229
+ val icon: String,
230
+ val label: String,
231
+ val onPress: () -> Unit,
232
+ )
@@ -0,0 +1,237 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.animation.core.Animatable
4
+ import androidx.compose.animation.core.animateFloatAsState
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.border
7
+ import androidx.compose.foundation.combinedClickable
8
+ import androidx.compose.foundation.interaction.MutableInteractionSource
9
+ import androidx.compose.foundation.interaction.collectIsPressedAsState
10
+ import androidx.compose.foundation.layout.*
11
+ import androidx.compose.foundation.shape.CircleShape
12
+ import androidx.compose.foundation.shape.RoundedCornerShape
13
+ import androidx.compose.runtime.Composable
14
+ import androidx.compose.runtime.LaunchedEffect
15
+ import androidx.compose.runtime.getValue
16
+ import androidx.compose.runtime.mutableIntStateOf
17
+ import androidx.compose.runtime.remember
18
+ import androidx.compose.runtime.saveable.rememberSaveable
19
+ import androidx.compose.runtime.setValue
20
+ import androidx.compose.ui.Alignment
21
+ import androidx.compose.ui.Modifier
22
+ import androidx.compose.ui.draw.clip
23
+ import androidx.compose.ui.graphics.Brush
24
+ import androidx.compose.ui.graphics.Color
25
+ import androidx.compose.ui.graphics.graphicsLayer
26
+ import androidx.compose.ui.semantics.Role
27
+ import androidx.compose.ui.text.style.TextAlign
28
+ import androidx.compose.ui.text.style.TextOverflow
29
+ import androidx.compose.ui.unit.Dp
30
+ import androidx.compose.ui.unit.IntOffset
31
+ import androidx.compose.ui.unit.dp
32
+ import vn.momo.kits.application.IsShowBaseLineDebug
33
+ import vn.momo.kits.components.*
34
+ import vn.momo.kits.const.*
35
+ import vn.momo.kits.modifier.InternalApi
36
+ import vn.momo.kits.modifier.conditional
37
+ import vn.momo.kits.modifier.activeOpacityClickable
38
+ import vn.momo.kits.layout.getScreenLayout
39
+ import vn.momo.kits.utils.horizontalSafeAreaPadding
40
+
41
+ @InternalApi
42
+ const val BOTTOM_TAB_BAR_HEIGHT = 64
43
+
44
+ @Composable
45
+ internal fun BottomTabBar(
46
+ items: List<BottomTabItem>,
47
+ floatingButton: BottomTabFloatingButton? = null,
48
+ selectedIndex: Int,
49
+ onTabSelected: (Int) -> Unit,
50
+ onTabLongPress: ((Int) -> Unit)? = null,
51
+ ) {
52
+
53
+ val layout = getScreenLayout()
54
+ val mid = items.size / 2
55
+
56
+ val floating = floatingButton?.takeIf { items.size % 2 == 0 }
57
+ val slotWidth = layout.contentWidth / (items.size + if (floating != null) 1 else 0)
58
+ fun slotOf(index: Int) = if (floating != null && index >= mid) index + 1 else index
59
+
60
+ var indicatorSlot by rememberSaveable { mutableIntStateOf(0) }
61
+ val indicatorX = remember { Animatable(indicatorSlot.toFloat()) }
62
+ LaunchedEffect(selectedIndex) {
63
+ val target = slotOf(selectedIndex)
64
+ indicatorSlot = target
65
+ indicatorX.animateTo(target.toFloat(), tabTimingSpec)
66
+ }
67
+
68
+ Box(
69
+ contentAlignment = Alignment.BottomCenter
70
+ ) {
71
+ Row(
72
+ modifier = Modifier
73
+ .fillMaxWidth()
74
+ .height(BOTTOM_TAB_BAR_HEIGHT.dp)
75
+ .background(AppTheme.current.colors.background.surface)
76
+ .conditional(IsShowBaseLineDebug) {
77
+ border(1.dp, Colors.blue_03)
78
+ }
79
+ .horizontalSafeAreaPadding(),
80
+ horizontalArrangement = Arrangement.SpaceAround,
81
+ ) {
82
+ if (floating == null) {
83
+ RenderTabBarItem(items, 0, items.size, selectedIndex, onTabSelected, onTabLongPress)
84
+ } else {
85
+ RenderTabBarItem(items, 0, mid, selectedIndex, onTabSelected, onTabLongPress)
86
+ Spacer(modifier = Modifier.width(slotWidth))
87
+ RenderTabBarItem(items, mid, items.size, selectedIndex, onTabSelected, onTabLongPress)
88
+ }
89
+ }
90
+
91
+ Box(modifier = Modifier
92
+ .offset { IntOffset((layout.insetLeft + slotWidth * (indicatorX.value + 0.5f) - layout.width / 2).roundToPx(), (-BOTTOM_TAB_BAR_HEIGHT + 2).dp.roundToPx()) }
93
+ .height(2.dp)
94
+ .width(44.dp)
95
+ .background(
96
+ color = AppTheme.current.colors.primary ,
97
+ shape = RoundedCornerShape(bottomStart = 2.dp, bottomEnd = 2.dp)
98
+ )
99
+ )
100
+
101
+ Box(modifier = Modifier
102
+ .fillMaxWidth()
103
+ .height(6.dp)
104
+ .offset(x = 0.dp, y = (-BOTTOM_TAB_BAR_HEIGHT).dp)
105
+ .background(
106
+ brush = Brush.verticalGradient(
107
+ colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
108
+ )
109
+ )
110
+ )
111
+ floating?.let {
112
+ Box(Modifier.offset(x = (layout.insetLeft - layout.insetRight) / 2)) {
113
+ FloatingButton(it, slotWidth)
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ @Composable
120
+ internal fun RowScope.RenderTabBarItem(
121
+ items: List<BottomTabItem>,
122
+ fromIndex: Int,
123
+ toIndex: Int,
124
+ selectedIndex: Int,
125
+ onTabSelected: (Int) -> Unit,
126
+ onTabLongPress: ((Int) -> Unit)? = null,
127
+ ){
128
+ for (index in fromIndex until toIndex) {
129
+ Box(modifier = Modifier.weight(1f)) {
130
+ TabBarItem(
131
+ item = items[index],
132
+ selected = index == selectedIndex,
133
+ onClick = { onTabSelected(index) },
134
+ onLongClick = onTabLongPress?.let { { it(index) } },
135
+ )
136
+ }
137
+ }
138
+ }
139
+
140
+ @Composable
141
+ internal fun TabBarItem(item: BottomTabItem, selected: Boolean, onClick: () -> Unit, onLongClick: (() -> Unit)? = null) {
142
+ // RN parity: "0" hides the badge, "" renders a dot.
143
+ val badgeLabel = item.badgeLabel?.takeUnless { it.toIntOrNull() == 0 }
144
+ val showDot = badgeLabel?.isEmpty() ?: item.showDot
145
+ val interactionSource = remember { MutableInteractionSource() }
146
+ val pressed by interactionSource.collectIsPressedAsState()
147
+ val alpha by animateFloatAsState(if (pressed) 0.2f else 1f, label = "TabBarItemOpacity")
148
+
149
+ BoxWithConstraints(modifier = Modifier
150
+ .fillMaxSize()
151
+ .padding(horizontal = Spacing.XXS)
152
+ .conditional(IsShowBaseLineDebug) {
153
+ border(1.dp, Colors.blue_03)
154
+ }
155
+ .graphicsLayer { this.alpha = alpha }
156
+ .combinedClickable(
157
+ interactionSource = interactionSource,
158
+ indication = null,
159
+ role = Role.Tab,
160
+ onLongClick = onLongClick,
161
+ onClick = onClick,
162
+ ),
163
+ contentAlignment = Alignment.BottomStart
164
+ ){
165
+ // from the icon's center to the cell's end edge
166
+ val badgeMaxWidth = (maxWidth / 2 - Spacing.XXS).coerceAtLeast(0.dp)
167
+ Column(
168
+ modifier = Modifier
169
+ .fillMaxSize()
170
+ .padding(horizontal = Spacing.S, vertical = Spacing.S),
171
+ horizontalAlignment = Alignment.CenterHorizontally,
172
+ verticalArrangement = Arrangement.Center
173
+ ) {
174
+ Box(modifier = Modifier.padding(Spacing.XS)) {
175
+ Icon(
176
+ source = item.icon,
177
+ size = 28.dp,
178
+ color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint)
179
+ if (showDot) {
180
+ val dotAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopEnd, unbounded = true)
181
+ BadgeDot(size = DotSize.Small, modifier = dotAnchor.offset(x = 4.dp, y = (-4).dp))
182
+ } else if (!badgeLabel.isNullOrEmpty()) {
183
+ // starts at the icon's center and grows toward the cell's end edge, ellipsized past it
184
+ val badgeAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopStart, unbounded = true)
185
+ Badge(badgeLabel, modifier = badgeAnchor.offset(x = 14.dp, y = (-8).dp).widthIn(max = badgeMaxWidth))
186
+ }
187
+ }
188
+ Text(
189
+ text = item.label,
190
+ color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint,
191
+ style = if (selected) Typography.labelXsMedium else Typography.descriptionXsRegular,
192
+ maxLines = 1,
193
+ overflow = TextOverflow.Ellipsis
194
+ )
195
+ }
196
+ }
197
+ }
198
+
199
+ @Composable
200
+ internal fun FloatingButton(data: BottomTabFloatingButton, width: Dp) {
201
+ Column(
202
+ modifier = Modifier
203
+ .width(width)
204
+ .padding(horizontal = Spacing.XXS, vertical = Spacing.S)
205
+ .conditional(IsShowBaseLineDebug) {
206
+ border(1.dp, Colors.blue_03)
207
+ }
208
+ .activeOpacityClickable {
209
+ data.onPress()
210
+ },
211
+ verticalArrangement = Arrangement.Bottom,
212
+ horizontalAlignment = Alignment.CenterHorizontally
213
+
214
+ ){
215
+ CurvedContainer()
216
+ Box(
217
+ modifier = Modifier
218
+ .size(48.dp)
219
+ .clip(CircleShape)
220
+ .background(AppTheme.current.colors.primary),
221
+ contentAlignment = Alignment.Center
222
+ ) {
223
+ Icon(source = data.icon, color = Color.White, size = 28.dp)
224
+ }
225
+ Spacer(modifier = Modifier.height(4.dp))
226
+ Text(
227
+ text = data.label,
228
+ style = Typography.labelXsMedium,
229
+ color = Colors.black_01,
230
+ textAlign = TextAlign.Center,
231
+ modifier = Modifier
232
+ .height(14.dp)
233
+ .fillMaxWidth()
234
+ .background(AppTheme.current.colors.primary, shape = RoundedCornerShape(size = Radius.XL))
235
+ )
236
+ }
237
+ }