@momo-kits/native-kits 0.167.1-duo.14-debug → 0.167.1-duo.15

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 (153) hide show
  1. package/CLAUDE.md +1 -1
  2. package/ios/Layout/ScreenLayout.swift +52 -30
  3. package/ios/Navigation/StackScreen.swift +22 -8
  4. package/ios/native-kits.podspec +1 -1
  5. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  6. package/package.json +1 -1
  7. package/build.gradle.kts +0 -11
  8. package/compose/build.gradle.kts +0 -204
  9. package/compose/build.gradle.kts.backup +0 -204
  10. package/compose/compose.podspec +0 -47
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  13. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  14. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  15. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -153
  16. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +0 -52
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -124
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +0 -183
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +0 -207
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +0 -39
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +0 -86
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +0 -76
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +0 -76
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +0 -293
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +0 -33
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -831
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -269
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +0 -110
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -378
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +0 -69
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -357
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -542
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -76
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -231
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -189
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -478
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -114
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -265
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -235
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -223
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -265
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -185
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -41
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -84
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -40
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -361
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -308
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -90
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -330
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -220
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -473
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -207
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -92
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -560
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -125
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -207
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -501
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -236
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -16
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -18
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -188
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -297
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -232
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -338
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -137
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -106
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -205
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -393
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -708
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -148
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -218
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -231
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -98
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -312
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -169
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -408
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -92
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -366
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -37
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -185
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -91
  132. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  133. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -74
  134. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -13
  135. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  136. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  137. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  138. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -118
  139. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -40
  140. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  141. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  142. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  143. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  144. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -217
  145. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -86
  146. package/gradle/libs.versions.toml +0 -69
  147. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  148. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  149. package/gradle.properties +0 -26
  150. package/gradlew +0 -252
  151. package/gradlew.bat +0 -94
  152. package/ios-demo/README.md +0 -120
  153. package/settings.gradle.kts +0 -64
@@ -1,148 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
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
- }
@@ -1,218 +0,0 @@
1
- package vn.momo.kits.navigation.bottomtab
2
-
3
- import androidx.compose.animation.core.tween
4
- import androidx.compose.animation.fadeIn
5
- import androidx.compose.animation.fadeOut
6
- import androidx.compose.animation.scaleIn
7
- import androidx.compose.animation.scaleOut
8
- import androidx.compose.foundation.background
9
- import androidx.compose.foundation.layout.*
10
- import androidx.compose.runtime.Composable
11
- import androidx.compose.runtime.CompositionLocalProvider
12
- import androidx.compose.runtime.DisposableEffect
13
- import androidx.compose.runtime.LaunchedEffect
14
- import androidx.compose.runtime.remember
15
- import androidx.compose.ui.Alignment
16
- import androidx.compose.ui.Modifier
17
- import androidx.compose.ui.unit.dp
18
- import androidx.navigation.compose.NavHost
19
- import androidx.navigation.compose.composable
20
- import androidx.navigation.compose.currentBackStackEntryAsState
21
- import androidx.navigation.compose.rememberNavController
22
- import vn.momo.kits.const.AppNavigationBar
23
- import vn.momo.kits.const.AppTheme
24
- import vn.momo.kits.const.Spacing
25
- import vn.momo.kits.navigation.KeyboardOptions
26
- import vn.momo.kits.navigation.LocalNavigation
27
- import vn.momo.kits.navigation.LocalNavigator
28
- import vn.momo.kits.navigation.NavigationOptions
29
- import vn.momo.kits.navigation.StackScreen
30
- import vn.momo.kits.navigation.component.HeaderType
31
- import vn.momo.kits.platform.BackHandler
32
- import vn.momo.kits.platform.reportFloatingArrowBack
33
- import vn.momo.kits.layout.getScreenLayout
34
-
35
- private var bottomTabOptionItems : MutableList<NavigationOptions?> = mutableListOf()
36
- internal fun setBottomTabOption(index: Int, options: NavigationOptions){
37
- if (index in bottomTabOptionItems.indices) {
38
- bottomTabOptionItems[index] = options
39
- }
40
- }
41
- internal fun getBottomTabOption(index: Int): NavigationOptions? {
42
- return if (index in bottomTabOptionItems.indices) {
43
- bottomTabOptionItems[index]
44
- } else null
45
- }
46
-
47
- @Composable
48
- fun BottomTab(
49
- items: List<BottomTabItem>,
50
- floatingButton: BottomTabFloatingButton? = null,
51
- // iPhone Duo: when the side bar can't hold both bars, which one starts compressed;
52
- // tapping the compressed one swaps them
53
- compressionBehavior: DuoBarCompressionBehavior = DuoBarCompressionBehavior.TOOLBAR,
54
- initialRouteName: String? = null,
55
- onTabPress: ((index: Int, switchTab: () -> Unit) -> Unit)? = null,
56
- backToInitialTab: Boolean = true,
57
- ) {
58
- val navigation = LocalNavigation.current
59
- val navigator = LocalNavigator.current
60
- val navController = rememberNavController()
61
- val startRoute = remember {
62
- "option${items.indexOfFirst { it.name == initialRouteName }.coerceAtLeast(0)}"
63
- }
64
-
65
- // Only on new items: this recomposes on every tab switch and would drop options a tab set at runtime.
66
- remember(items) {
67
- bottomTabOptionItems = items.map { it.options ?: NavigationOptions() }.toMutableList()
68
- }
69
-
70
- LaunchedEffect(Unit){
71
- navigation.markAsBottomTabRoot()
72
- navigation.setOptions(
73
- headerType = HeaderType.None,
74
- keyboardOptions = KeyboardOptions(useAvoidKeyboard = false)
75
- )
76
- }
77
-
78
- val currentRoute = navController.currentBackStackEntryAsState().value?.destination?.route
79
- val onStartTab = currentRoute == null || currentRoute == startRoute
80
- val isFirstTab = onStartTab || !backToInitialTab
81
- val backToStartTab = { navController.popBackStack(startRoute, inclusive = false) }
82
-
83
- DisposableEffect(isFirstTab) {
84
- reportFloatingArrowBack(!isFirstTab)
85
- navigator.tabBackHandler = if (isFirstTab) null else ({ backToStartTab() })
86
- // both live outside this composition
87
- onDispose {
88
- reportFloatingArrowBack(false)
89
- navigator.tabBackHandler = null
90
- }
91
- }
92
-
93
- val layout = getScreenLayout()
94
- val hasQr = floatingButton != null
95
- val compression = rememberDuoBarCompression(compressionBehavior, items.size, hasQr, layout)
96
- val railReserve = layout.sideBar?.takeIf { layout.isIPhoneDuo }?.let {
97
- it.bottom + duoRailHeight(items.size, hasQr, compressed = compression.tabBarCompressed) + DUO_GROUP_GAP
98
- } ?: 0.dp
99
- val onTabSelected: (Int) -> Unit = { index ->
100
- val switchTab = {
101
- val targetRoute = "option$index"
102
- if (navController.currentBackStackEntry?.destination?.route != targetRoute) {
103
- // one entry per tab above the start tab, so switching never grows the back stack
104
- navController.navigate(targetRoute) {
105
- popUpTo(startRoute) { saveState = true }
106
- launchSingleTop = true
107
- restoreState = true
108
- }
109
- }
110
- }
111
- onTabPress?.invoke(index, switchTab) ?: switchTab()
112
- }
113
-
114
- Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
115
- Box(modifier = Modifier
116
- .fillMaxSize()
117
- ) {
118
- CompositionLocalProvider(
119
- LocalDuoRailReserve provides railReserve,
120
- LocalDuoBarCompression provides compression,
121
- ) {
122
- NavHost(
123
- navController = navController,
124
- startDestination = startRoute
125
- ) {
126
- items.forEachIndexed { index, item ->
127
- composable(
128
- route = "option$index",
129
- enterTransition = {
130
- fadeIn(animationSpec = tween(200)) +
131
- scaleIn(
132
- initialScale = 0.97f,
133
- animationSpec = tween(200)
134
- )
135
- },
136
- exitTransition = {
137
- fadeOut(animationSpec = tween(200)) +
138
- scaleOut(
139
- targetScale = 0.97f,
140
- animationSpec = tween(200)
141
- )
142
- },
143
- popEnterTransition = {
144
- fadeIn(animationSpec = tween(200)) +
145
- scaleIn(
146
- initialScale = 0.97f,
147
- animationSpec = tween(200)
148
- )
149
- },
150
- popExitTransition = {
151
- fadeOut(animationSpec = tween(200)) +
152
- scaleOut(
153
- targetScale = 0.97f,
154
- animationSpec = tween(200)
155
- )
156
- }
157
- ) {
158
- val option = getBottomTabOption(index)
159
-
160
- StackScreen(
161
- content = item.screen,
162
- navigationOptions = option,
163
- bottomTabIndex = index,
164
- onBackHandler = {
165
- if (backToInitialTab && "option$index" != startRoute) {
166
- backToStartTab()
167
- } else {
168
- navigator.pop()
169
- }
170
- }
171
- )
172
- }
173
- }
174
- }
175
- }
176
- }
177
- BackHandler(enabled = !onStartTab) {
178
- if (backToInitialTab) backToStartTab() else navigator.pop()
179
- }
180
- if (layout.isIPhoneDuo) {
181
- DuoTabBar(
182
- layout = layout,
183
- items = items,
184
- floatingButton = floatingButton,
185
- selectedIndex = items.indices.firstOrNull { "option$it" == currentRoute } ?: 0,
186
- onTabSelected = onTabSelected,
187
- compression = compression,
188
- )
189
- } else {
190
- Column {
191
- BottomTabBar(
192
- items = items,
193
- floatingButton = floatingButton,
194
- navController = navController,
195
- onTabSelected = onTabSelected,
196
- )
197
- Spacer(modifier = Modifier.fillMaxWidth().height(AppNavigationBar.current + Spacing.S).background(AppTheme.current.colors.background.surface))
198
- }
199
- }
200
- }
201
- }
202
-
203
- data class BottomTabItem(
204
- val name: String,
205
- val label: String,
206
- val icon: String,
207
- val showDot: Boolean = false,
208
- val badgeLabel: String? = null,
209
- val screen: @Composable () -> Unit,
210
- val options: NavigationOptions? = null,
211
- val initialParams: Any? = null
212
- )
213
-
214
- data class BottomTabFloatingButton(
215
- val icon: String,
216
- val label: String,
217
- val onPress: () -> Unit,
218
- )
@@ -1,231 +0,0 @@
1
- package vn.momo.kits.navigation.bottomtab
2
-
3
- import androidx.compose.animation.core.FastOutSlowInEasing
4
- import androidx.compose.animation.core.animateDpAsState
5
- import androidx.compose.animation.core.tween
6
- import androidx.compose.foundation.background
7
- import androidx.compose.foundation.border
8
- import androidx.compose.foundation.layout.*
9
- import androidx.compose.foundation.shape.CircleShape
10
- import androidx.compose.foundation.shape.RoundedCornerShape
11
- import androidx.compose.runtime.Composable
12
- import androidx.compose.runtime.getValue
13
- import androidx.compose.ui.Alignment
14
- import androidx.compose.ui.Modifier
15
- import androidx.compose.ui.draw.clip
16
- import androidx.compose.ui.graphics.Brush
17
- import androidx.compose.ui.graphics.Color
18
- import androidx.compose.ui.text.style.TextAlign
19
- import androidx.compose.ui.text.style.TextOverflow
20
- import androidx.compose.ui.unit.dp
21
- import androidx.navigation.NavController
22
- import androidx.navigation.compose.currentBackStackEntryAsState
23
- import vn.momo.kits.application.IsShowBaseLineDebug
24
- import vn.momo.kits.components.*
25
- import vn.momo.kits.const.*
26
- import vn.momo.kits.modifier.InternalApi
27
- import vn.momo.kits.modifier.conditional
28
- import vn.momo.kits.modifier.noFeedbackClickable
29
- import vn.momo.kits.layout.getScreenLayout
30
- import vn.momo.kits.utils.horizontalSafeAreaPadding
31
-
32
- internal val floatingButtonWidth = 75.dp
33
- @InternalApi
34
- const val BOTTOM_TAB_BAR_HEIGHT = 64
35
-
36
- @Composable
37
- internal fun BottomTabBar(
38
- items: List<BottomTabItem>,
39
- floatingButton: BottomTabFloatingButton? = null,
40
- navController: NavController,
41
- onTabSelected: (Int) -> Unit,
42
- ) {
43
- val currentRoute = navController.currentBackStackEntryAsState().value?.destination?.route
44
- val selectedIndex = items.indices.firstOrNull { "option$it" == currentRoute } ?: 0
45
-
46
- val layout = getScreenLayout()
47
- val mid = items.size / 2
48
-
49
- val tabWidth = if (floatingButton != null) {
50
- (layout.contentWidth - floatingButtonWidth) / items.size
51
- } else {
52
- layout.contentWidth / items.size
53
- }
54
- val adjustSize = if(floatingButton != null && selectedIndex >= mid) floatingButtonWidth else 0.dp
55
- // offsets are from the bar center; tabs live between the side safe areas
56
- val targetOffset = layout.insetLeft + tabWidth * selectedIndex + tabWidth / 2 - layout.width / 2 + adjustSize
57
-
58
- val indicatorOffsetX by animateDpAsState(
59
- targetValue = targetOffset,
60
- animationSpec = tween(durationMillis = 250, easing = FastOutSlowInEasing),
61
- label = "IndicatorX"
62
- )
63
-
64
- Box(
65
- contentAlignment = Alignment.BottomCenter
66
- ) {
67
- Row(
68
- modifier = Modifier
69
- .fillMaxWidth()
70
- .height(BOTTOM_TAB_BAR_HEIGHT.dp)
71
- .background(AppTheme.current.colors.background.surface)
72
- .conditional(IsShowBaseLineDebug) {
73
- border(1.dp, Colors.blue_03)
74
- }
75
- .horizontalSafeAreaPadding(),
76
- horizontalArrangement = Arrangement.SpaceAround,
77
- ) {
78
- if (floatingButton == null) {
79
- RenderTabBarItem(items, 0, items.size, selectedIndex, onTabSelected)
80
- } else {
81
- RenderTabBarItem(items, 0, mid, selectedIndex, onTabSelected)
82
- Spacer(modifier = Modifier.width(floatingButtonWidth).padding(horizontal = Spacing.XXS))
83
- RenderTabBarItem(items, mid, items.size, selectedIndex, onTabSelected)
84
- }
85
- }
86
-
87
- Box(modifier = Modifier
88
- .offset(x = indicatorOffsetX, y = (-BOTTOM_TAB_BAR_HEIGHT + 2).dp)
89
- .height(2.dp)
90
- .width(44.dp)
91
- .background(
92
- color = AppTheme.current.colors.primary ,
93
- shape = RoundedCornerShape(bottomStart = 2.dp, bottomEnd = 2.dp)
94
- )
95
- )
96
-
97
- Box(modifier = Modifier
98
- .fillMaxWidth()
99
- .height(6.dp)
100
- .offset(x = 0.dp, y = (-BOTTOM_TAB_BAR_HEIGHT).dp)
101
- .background(
102
- brush = Brush.verticalGradient(
103
- colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
104
- )
105
- )
106
- )
107
- floatingButton?.let {
108
- Box(Modifier.offset(x = (layout.insetLeft - layout.insetRight) / 2)) {
109
- FloatingButton(it)
110
- }
111
- }
112
- }
113
- }
114
-
115
- @Composable
116
- internal fun RowScope.RenderTabBarItem(
117
- items: List<BottomTabItem>,
118
- fromIndex: Int,
119
- toIndex: Int,
120
- selectedIndex: Int,
121
- onTabSelected: (Int) -> Unit
122
- ){
123
- for (index in fromIndex until toIndex) {
124
- Box(modifier = Modifier.weight(1f)) {
125
- TabBarItem(
126
- item = items[index],
127
- selected = index == selectedIndex,
128
- onClick = { onTabSelected(index) }
129
- )
130
- }
131
- }
132
- }
133
-
134
- @Composable
135
- internal fun TabBarItem(item: BottomTabItem, selected: Boolean, onClick: () -> Unit) {
136
- fun isNumber(label: String): Boolean {
137
- val numberRegex = "^\\d+$".toRegex()
138
- return numberRegex.matches(label)
139
- }
140
- fun formatLabel(label: String): String? {
141
- if (isNumber(label) && label.toInt() == 0) {
142
- return null
143
- }
144
- return label
145
- }
146
- val badgeLabel = item.badgeLabel?.let { formatLabel(it) }
147
-
148
- Box(modifier = Modifier
149
- .fillMaxSize()
150
- .padding(horizontal = Spacing.XXS)
151
- .conditional(IsShowBaseLineDebug) {
152
- border(1.dp, Colors.blue_03)
153
- }
154
- .noFeedbackClickable {
155
- onClick()
156
- },
157
- contentAlignment = Alignment.BottomStart
158
- ){
159
- Column(
160
- modifier = Modifier
161
- .fillMaxSize()
162
- .padding(horizontal = Spacing.S, vertical = Spacing.S)
163
- .noFeedbackClickable {
164
- onClick()
165
- },
166
- horizontalAlignment = Alignment.CenterHorizontally,
167
- verticalArrangement = Arrangement.Center
168
- ) {
169
- Icon(
170
- source = item.icon,
171
- size = 28.dp,
172
- modifier = Modifier.padding(Spacing.XS),
173
- color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint)
174
- Text(
175
- text = item.label,
176
- color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint,
177
- style = if (selected) Typography.labelXsMedium else Typography.descriptionXsRegular,
178
- maxLines = 1,
179
- overflow = TextOverflow.Ellipsis
180
- )
181
- }
182
- if (badgeLabel != null && badgeLabel.isNotEmpty()) {
183
- Badge(badgeLabel, modifier = Modifier.offset(x = 44.dp, y = (-42).dp))
184
- } else if (badgeLabel != null || item.showDot) {
185
- BadgeDot(
186
- size = DotSize.Small,
187
- modifier = Modifier.offset(x = 50.dp, y = (-48).dp)
188
- )
189
- }
190
- }
191
- }
192
-
193
- @Composable
194
- internal fun FloatingButton(data: BottomTabFloatingButton) {
195
- Column(
196
- modifier = Modifier
197
- .width(floatingButtonWidth)
198
- .padding(horizontal = Spacing.XXS, vertical = Spacing.S)
199
- .conditional(IsShowBaseLineDebug) {
200
- border(1.dp, Colors.blue_03)
201
- }
202
- .noFeedbackClickable {
203
- data.onPress()
204
- },
205
- verticalArrangement = Arrangement.Bottom,
206
- horizontalAlignment = Alignment.CenterHorizontally
207
-
208
- ){
209
- CurvedContainer()
210
- Box(
211
- modifier = Modifier
212
- .size(48.dp)
213
- .clip(CircleShape)
214
- .background(AppTheme.current.colors.primary),
215
- contentAlignment = Alignment.Center
216
- ) {
217
- Icon(source = data.icon, color = Color.White, size = 28.dp)
218
- }
219
- Spacer(modifier = Modifier.height(4.dp))
220
- Text(
221
- text = data.label,
222
- style = Typography.labelXsMedium,
223
- color = Colors.black_01,
224
- textAlign = TextAlign.Center,
225
- modifier = Modifier
226
- .height(14.dp)
227
- .fillMaxWidth()
228
- .background(AppTheme.current.colors.primary, shape = RoundedCornerShape(size = Radius.XL))
229
- )
230
- }
231
- }