@momo-kits/native-kits 0.169.15-beta.4-debug → 0.169.15-beta.5

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 (147) hide show
  1. package/ios/Navigation/BottomTab/BottomTab.swift +12 -7
  2. package/ios/Navigation/BottomTab/{LegacyBottomTabBar.swift → Legacy/LegacyBottomTabBar.swift} +54 -85
  3. package/ios/Navigation/BottomTab/Legacy/LegacyCurvedContainer.swift +63 -0
  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 -198
  9. package/compose/compose.podspec +0 -47
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  13. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  14. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
  15. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  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/Context.kt +0 -110
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -61
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -268
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -354
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -130
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -137
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -262
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -237
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -280
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -342
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -362
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -304
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -308
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -218
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -456
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -175
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -208
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -291
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -71
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -315
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -54
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -118
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -206
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -421
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -758
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -152
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -261
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -406
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -111
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -93
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -208
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/LegacyBottomTabBar.kt +0 -262
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/LegacyCurvedContainer.kt +0 -86
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -133
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -446
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -400
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -197
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -7
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -117
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  134. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  135. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  136. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -65
  137. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -217
  138. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  139. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -143
  140. package/gradle/libs.versions.toml +0 -67
  141. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  142. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  143. package/gradle.properties +0 -24
  144. package/gradlew +0 -252
  145. package/gradlew.bat +0 -94
  146. package/ios-demo/README.md +0 -120
  147. package/settings.gradle.kts +0 -64
@@ -1,152 +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
- return slideInHorizontally(stackSpec) { it }
57
- }
58
-
59
- internal fun AnimatedContentTransitionScope<NavBackStackEntry>.stackExit(): ExitTransition {
60
- if (targetState.destination.hasRoute<DynamicDialogRoute>()) return ExitTransition.None
61
- return slideOutHorizontally(stackSpec) { -(it * PARALLAX_RATIO).roundToInt() }
62
- }
63
-
64
- internal fun AnimatedContentTransitionScope<NavBackStackEntry>.stackPopEnter(): EnterTransition {
65
- if (initialState.destination.hasRoute<DynamicDialogRoute>()) return EnterTransition.None
66
- return slideInHorizontally(stackSpec) { -(it * PARALLAX_RATIO).roundToInt() }
67
- }
68
-
69
- internal fun AnimatedContentTransitionScope<NavBackStackEntry>.stackPopExit(): ExitTransition {
70
- return slideOutHorizontally(stackSpec) { it }
71
- }
72
-
73
- /**
74
- * Which composed screen is the top card. Ids are monotonic and NavHost keeps both entries composed
75
- * for the whole segment, so "highest id" is stable both ways. `currentBackStackEntry` is not: it
76
- * flips at frame 0 of a pop and the scrim would vanish instead of fading.
77
- */
78
- @Stable
79
- internal class StackTransitionCoordinator {
80
- private val composedRoutes = mutableStateMapOf<Int, Boolean>()
81
-
82
- val topStackId: Int by derivedStateOf {
83
- composedRoutes.entries.filter { it.value }.maxOfOrNull { it.key } ?: -1
84
- }
85
-
86
- fun attach(id: Int, isStackRoute: Boolean) {
87
- composedRoutes[id] = isStackRoute
88
- }
89
-
90
- fun detach(id: Int) {
91
- composedRoutes.remove(id)
92
- }
93
- }
94
-
95
- internal val LocalStackTransition = staticCompositionLocalOf { StackTransitionCoordinator() }
96
-
97
- /** Draws the covered-screen scrim and the top card's left-edge shadow around a stack destination. */
98
- @Composable
99
- internal fun AnimatedVisibilityScope.StackTransitionDecor(
100
- id: Int,
101
- isStackRoute: Boolean,
102
- content: @Composable () -> Unit,
103
- ) {
104
- val coordinator = LocalStackTransition.current
105
- coordinator.attach(id, isStackRoute)
106
- DisposableEffect(coordinator, id) {
107
- onDispose { coordinator.detach(id) }
108
- }
109
-
110
- val isTopCard = isStackRoute && id == coordinator.topStackId
111
- val isCovered = isStackRoute && !isTopCard
112
-
113
- val scrimAlpha = transition.animateFloat(
114
- transitionSpec = { tween(STACK_TRANSITION_DURATION, easing = LinearEasing) },
115
- label = "stackScrimAlpha",
116
- ) { state -> if (isCovered && state != EnterExitState.Visible) SCRIM_MAX_ALPHA else 0f }
117
-
118
- val shadowAlpha = transition.animateFloat(
119
- transitionSpec = { tween(STACK_TRANSITION_DURATION, easing = LinearEasing) },
120
- label = "stackEdgeShadowAlpha",
121
- ) { state -> if (isTopCard && state == EnterExitState.Visible) EDGE_SHADOW_MAX_ALPHA else 0f }
122
-
123
- val shadowWidthPx = with(LocalDensity.current) { EDGE_SHADOW_WIDTH.toPx() }
124
- val shadowBrush = remember(shadowWidthPx) {
125
- Brush.horizontalGradient(
126
- colors = listOf(Color.Transparent, Colors.black_20),
127
- startX = -shadowWidthPx,
128
- endX = 0f,
129
- )
130
- }
131
-
132
- Box(Modifier.fillMaxSize()) {
133
- content()
134
-
135
- if (isStackRoute) {
136
- Box(
137
- Modifier
138
- .matchParentSize()
139
- // read inside drawBehind: in the body this would recompose every gesture frame
140
- .drawBehind {
141
- drawRect(
142
- brush = shadowBrush,
143
- topLeft = Offset(-shadowWidthPx, 0f),
144
- size = Size(shadowWidthPx, size.height),
145
- alpha = shadowAlpha.value,
146
- )
147
- drawRect(Colors.pink_09, alpha = scrimAlpha.value)
148
- }
149
- )
150
- }
151
- }
152
- }
@@ -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,261 +0,0 @@
1
- package vn.momo.kits.navigation.bottomtab
2
-
3
- import androidx.compose.runtime.getValue
4
- import androidx.compose.runtime.setValue
5
- import androidx.compose.animation.core.Animatable
6
- import androidx.compose.animation.core.AnimationVector1D
7
- import androidx.compose.animation.core.CubicBezierEasing
8
- import androidx.compose.animation.core.Easing
9
- import androidx.compose.animation.core.tween
10
- import androidx.compose.foundation.background
11
- import androidx.compose.foundation.layout.*
12
- import androidx.compose.runtime.Composable
13
- import androidx.compose.runtime.CompositionLocalProvider
14
- import androidx.compose.runtime.DisposableEffect
15
- import androidx.compose.runtime.LaunchedEffect
16
- import androidx.compose.runtime.key
17
- import androidx.compose.runtime.mutableIntStateOf
18
- import androidx.compose.runtime.mutableStateOf
19
- import androidx.compose.runtime.remember
20
- import androidx.compose.runtime.saveable.rememberSaveable
21
- import androidx.compose.runtime.saveable.rememberSaveableStateHolder
22
- import androidx.compose.runtime.staticCompositionLocalOf
23
- import androidx.compose.ui.Alignment
24
- import androidx.compose.ui.Modifier
25
- import androidx.compose.ui.graphics.graphicsLayer
26
- import androidx.compose.ui.layout.layout
27
- import androidx.compose.ui.unit.dp
28
- import androidx.compose.ui.zIndex
29
- import kotlin.math.abs
30
- import vn.momo.kits.components.ScaleSizeScope
31
- import vn.momo.kits.const.AppTheme
32
- import vn.momo.kits.navigation.KeyboardOptions
33
- import vn.momo.kits.navigation.LocalMaxApi
34
- import vn.momo.kits.navigation.LocalNavigation
35
- import vn.momo.kits.navigation.LocalNavigator
36
- import vn.momo.kits.navigation.NavigationOptions
37
- import vn.momo.kits.navigation.StackScreen
38
- import vn.momo.kits.navigation.component.HeaderType
39
- import vn.momo.kits.platform.BackHandler
40
- import vn.momo.kits.platform.reportFloatingArrowBack
41
- import vn.momo.kits.layout.getScreenLayout
42
- import kotlinx.coroutines.launch
43
-
44
- internal val inOutQuad = Easing { t -> if (t < 0.5f) 2 * t * t else 1 - 2 * (1 - t) * (1 - t) }
45
- // the tab screens slide in index order over 280ms, CSS `ease`
46
- private val tabSwitchSpec = tween<Float>(durationMillis = 280, easing = CubicBezierEasing(0.25f, 0.1f, 0.25f, 1f))
47
-
48
- // -1 for tabs before the selected one, 1 for tabs after it: they wait a full width off screen on their side
49
- private fun tabPosition(index: Int, selected: Int) = (index - selected).coerceIn(-1, 1).toFloat()
50
-
51
- internal val LocalBottomTabFocused = staticCompositionLocalOf { true }
52
-
53
- // True under a BottomTab(useLegacy = true): tab content reserves the old docked bar instead of the floating one
54
- internal val LocalBottomTabLegacy = staticCompositionLocalOf { false }
55
-
56
- private val Hidden = Modifier.layout { measurable, constraints ->
57
- val placeable = measurable.measure(constraints)
58
- layout(placeable.width, placeable.height) {}
59
- }
60
-
61
- private var bottomTabOptionItems : MutableList<NavigationOptions?> = mutableListOf()
62
- internal fun setBottomTabOption(index: Int, options: NavigationOptions){
63
- if (index in bottomTabOptionItems.indices) {
64
- bottomTabOptionItems[index] = options
65
- }
66
- }
67
- internal fun getBottomTabOption(index: Int): NavigationOptions? {
68
- return if (index in bottomTabOptionItems.indices) {
69
- bottomTabOptionItems[index]
70
- } else null
71
- }
72
-
73
- /**
74
- * Tab container: one [StackScreen] per tab plus the tab bar (floating pill on phones, rail / floating
75
- * bar on iPhone Duo). [useLegacy] renders the pre-redesign docked phone bar instead (DS-984 not rolled out yet).
76
- */
77
- @Composable
78
- fun BottomTab(
79
- items: List<BottomTabItem>,
80
- floatingButton: BottomTabFloatingButton? = null,
81
- // iPhone Duo: when the side bar can't hold both bars, which one starts compressed;
82
- // tapping the compressed one swaps them
83
- compressionBehavior: DuoBarCompressionBehavior = DuoBarCompressionBehavior.TOOLBAR,
84
- initialRouteName: String? = null,
85
- onTabPress: ((index: Int, switchTab: () -> Unit) -> Unit)? = null,
86
- backToInitialTab: Boolean = true,
87
- // phone only: the pre-redesign docked bar (64dp, top indicator, curved center button) and its content
88
- // inset; floatingTabBarContentPadding() is then 0 and content keeps reserving the bar. Duo is unchanged.
89
- // On by default until the redesign rolls out; pass false for the floating bar.
90
- useLegacy: Boolean = true,
91
- ) {
92
- val navigation = LocalNavigation.current
93
- val navigator = LocalNavigator.current
94
- val maxApi = LocalMaxApi.current
95
- val startIndex = remember { items.indexOfFirst { it.name == initialRouteName }.coerceAtLeast(0) }
96
-
97
- remember(items) {
98
- bottomTabOptionItems = items.map { it.options ?: NavigationOptions() }.toMutableList()
99
- }
100
-
101
- LaunchedEffect(Unit){
102
- navigation.markAsBottomTabRoot()
103
- navigation.setOptions(
104
- headerType = HeaderType.None,
105
- keyboardOptions = KeyboardOptions(useAvoidKeyboard = false)
106
- )
107
- }
108
-
109
- var selectedIndex by rememberSaveable { mutableIntStateOf(startIndex) }
110
- var loadedTabs by rememberSaveable { mutableStateOf(listOf(startIndex)) }
111
- val tabStateHolder = rememberSaveableStateHolder()
112
- val selectTab: (Int) -> Unit = { index ->
113
- if (index !in loadedTabs) loadedTabs = loadedTabs + index
114
- selectedIndex = index
115
- }
116
-
117
- val onFirstTab = selectedIndex == 0
118
- val isFirstTab = onFirstTab || !backToInitialTab
119
- val backToFirstTab = { selectTab(0) }
120
-
121
- var lastFocusedIndex by rememberSaveable { mutableStateOf<Int?>(null) }
122
- val tabProgress = remember { mutableMapOf<Int, Animatable<Float, AnimationVector1D>>() }
123
- fun progressOf(index: Int) = tabProgress.getOrPut(index) {
124
- Animatable(tabPosition(index, lastFocusedIndex ?: index))
125
- }
126
- LaunchedEffect(selectedIndex) {
127
- val previousIndex = lastFocusedIndex
128
- lastFocusedIndex = selectedIndex
129
- tabProgress.forEach { (index, progress) ->
130
- val target = tabPosition(index, selectedIndex)
131
- launch {
132
- if (index == selectedIndex || index == previousIndex) {
133
- progress.animateTo(target, tabSwitchSpec)
134
- } else {
135
- progress.snapTo(target)
136
- }
137
- }
138
- }
139
- }
140
-
141
- DisposableEffect(isFirstTab) {
142
- reportFloatingArrowBack(!isFirstTab)
143
- navigator.tabBackHandler = if (isFirstTab) null else ({ backToFirstTab() })
144
-
145
- onDispose {
146
- reportFloatingArrowBack(false)
147
- navigator.tabBackHandler = null
148
- }
149
- }
150
-
151
- val layout = getScreenLayout()
152
- val hasQr = floatingButton != null
153
- val compression = rememberDuoBarCompression(compressionBehavior, items.size, hasQr, layout)
154
- val railReserve = layout.sideBar?.takeIf { layout.isIPhoneDuo }?.let {
155
- it.bottom + duoRailHeight(items.size, hasQr, compressed = compression.tabBarCompressed) + DUO_GROUP_GAP
156
- } ?: 0.dp
157
- val onTabSelected: (Int) -> Unit = { index ->
158
- runCatching { maxApi?.triggerEventVibration("light", callback = null) }
159
- val switchTab = {
160
- if (index != selectedIndex) selectTab(index)
161
- }
162
- onTabPress?.invoke(index, switchTab) ?: switchTab()
163
- }
164
-
165
- Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
166
- Box(modifier = Modifier
167
- .fillMaxSize()
168
- .background(AppTheme.current.colors.background.default)
169
- ) {
170
- CompositionLocalProvider(
171
- LocalDuoRailReserve provides railReserve,
172
- LocalDuoBarCompression provides compression,
173
- LocalTabBarHasCenterAction provides hasCenterAction(floatingButton, items.size),
174
- LocalBottomTabLegacy provides useLegacy,
175
- ) {
176
- loadedTabs.forEach { index ->
177
- val item = items.getOrNull(index) ?: return@forEach
178
- val focused = index == selectedIndex
179
- val progress = progressOf(index)
180
- // the leaving tab stays drawn until it has slid off screen
181
- val visible = focused || abs(progress.value) < 1f
182
- key(index) {
183
- Box(
184
- Modifier
185
- .fillMaxSize()
186
- .zIndex(if (focused) 0f else -1f)
187
- .then(if (visible) Modifier.graphicsLayer { translationX = progress.value * size.width } else Hidden)
188
- ) {
189
- CompositionLocalProvider(LocalBottomTabFocused provides focused) {
190
- tabStateHolder.SaveableStateProvider(index) {
191
- StackScreen(
192
- content = item.screen,
193
- navigationOptions = getBottomTabOption(index),
194
- bottomTabIndex = index,
195
- onBackHandler = {
196
- if (backToInitialTab && index != 0) {
197
- backToFirstTab()
198
- } else {
199
- navigator.pop()
200
- }
201
- }
202
- )
203
- }
204
- }
205
- }
206
- }
207
- }
208
- }
209
- }
210
- BackHandler(enabled = !onFirstTab) {
211
- if (backToInitialTab) backToFirstTab() else navigator.pop()
212
- }
213
- if (useLegacy && !layout.isIPhoneDuo) {
214
- LegacyBottomTabBarWithFiller(
215
- items = items,
216
- floatingButton = floatingButton,
217
- selectedIndex = selectedIndex,
218
- onTabSelected = onTabSelected,
219
- )
220
- } else ScaleSizeScope(TabBarMetrics.LABEL_MAX_SCALE) {
221
- if (layout.isIPhoneDuo) {
222
- DuoTabBar(
223
- layout = layout,
224
- items = items,
225
- floatingButton = floatingButton,
226
- selectedIndex = selectedIndex,
227
- onTabSelected = onTabSelected,
228
- compression = compression,
229
- )
230
- } else {
231
- BottomTabBar(
232
- items = items,
233
- floatingButton = floatingButton,
234
- selectedIndex = selectedIndex,
235
- onTabSelected = onTabSelected,
236
- )
237
- }
238
- }
239
- }
240
- }
241
-
242
- data class BottomTabItem(
243
- val name: String,
244
- val label: String,
245
- val icon: String,
246
- val showDot: Boolean = false,
247
- val badgeLabel: String? = null,
248
- val screen: @Composable () -> Unit,
249
- val options: NavigationOptions? = null,
250
- val initialParams: Any? = null
251
- )
252
-
253
- data class BottomTabFloatingButton(
254
- val icon: String,
255
- val label: String,
256
- val onPress: () -> Unit,
257
- // replaces the icon inside the 48 button, e.g. the button part of a Lottie; centered, unclipped
258
- val iconContent: (@Composable () -> Unit)? = null,
259
- // drawn over the label text, which stays, e.g. the label part of a Lottie; centered, unclipped
260
- val labelContent: (@Composable () -> Unit)? = null,
261
- )