@momo-kits/native-kits 0.169.8-beta.4-debug → 0.169.8-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 (142) hide show
  1. package/ios/native-kits.podspec +1 -1
  2. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  3. package/package.json +1 -1
  4. package/build.gradle.kts +0 -11
  5. package/compose/build.gradle.kts +0 -198
  6. package/compose/compose.podspec +0 -47
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  13. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -62
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -267
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -82
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -356
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -195
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -263
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -235
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -280
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -363
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -307
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -306
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -220
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -457
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -120
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -210
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -292
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -63
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -316
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -118
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -205
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -422
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -748
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -148
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -242
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -391
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -100
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -97
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -207
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -132
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -466
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -406
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -204
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -22
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -118
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -218
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  134. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -144
  135. package/gradle/libs.versions.toml +0 -67
  136. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  137. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  138. package/gradle.properties +0 -24
  139. package/gradlew +0 -252
  140. package/gradlew.bat +0 -94
  141. package/ios-demo/README.md +0 -120
  142. 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,242 +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
- private val Hidden = Modifier.layout { measurable, constraints ->
54
- val placeable = measurable.measure(constraints)
55
- layout(placeable.width, placeable.height) {}
56
- }
57
-
58
- private var bottomTabOptionItems : MutableList<NavigationOptions?> = mutableListOf()
59
- internal fun setBottomTabOption(index: Int, options: NavigationOptions){
60
- if (index in bottomTabOptionItems.indices) {
61
- bottomTabOptionItems[index] = options
62
- }
63
- }
64
- internal fun getBottomTabOption(index: Int): NavigationOptions? {
65
- return if (index in bottomTabOptionItems.indices) {
66
- bottomTabOptionItems[index]
67
- } else null
68
- }
69
-
70
- @Composable
71
- fun BottomTab(
72
- items: List<BottomTabItem>,
73
- floatingButton: BottomTabFloatingButton? = null,
74
- // iPhone Duo: when the side bar can't hold both bars, which one starts compressed;
75
- // tapping the compressed one swaps them
76
- compressionBehavior: DuoBarCompressionBehavior = DuoBarCompressionBehavior.TOOLBAR,
77
- initialRouteName: String? = null,
78
- onTabPress: ((index: Int, switchTab: () -> Unit) -> Unit)? = null,
79
- backToInitialTab: Boolean = true,
80
- ) {
81
- val navigation = LocalNavigation.current
82
- val navigator = LocalNavigator.current
83
- val maxApi = LocalMaxApi.current
84
- val startIndex = remember { items.indexOfFirst { it.name == initialRouteName }.coerceAtLeast(0) }
85
-
86
- remember(items) {
87
- bottomTabOptionItems = items.map { it.options ?: NavigationOptions() }.toMutableList()
88
- }
89
-
90
- LaunchedEffect(Unit){
91
- navigation.markAsBottomTabRoot()
92
- navigation.setOptions(
93
- headerType = HeaderType.None,
94
- keyboardOptions = KeyboardOptions(useAvoidKeyboard = false)
95
- )
96
- }
97
-
98
- var selectedIndex by rememberSaveable { mutableIntStateOf(startIndex) }
99
- var loadedTabs by rememberSaveable { mutableStateOf(listOf(startIndex)) }
100
- val tabStateHolder = rememberSaveableStateHolder()
101
- val selectTab: (Int) -> Unit = { index ->
102
- if (index !in loadedTabs) loadedTabs = loadedTabs + index
103
- selectedIndex = index
104
- }
105
-
106
- val onFirstTab = selectedIndex == 0
107
- val isFirstTab = onFirstTab || !backToInitialTab
108
- val backToFirstTab = { selectTab(0) }
109
-
110
- var lastFocusedIndex by rememberSaveable { mutableStateOf<Int?>(null) }
111
- val tabProgress = remember { mutableMapOf<Int, Animatable<Float, AnimationVector1D>>() }
112
- fun progressOf(index: Int) = tabProgress.getOrPut(index) {
113
- Animatable(tabPosition(index, lastFocusedIndex ?: index))
114
- }
115
- LaunchedEffect(selectedIndex) {
116
- val previousIndex = lastFocusedIndex
117
- lastFocusedIndex = selectedIndex
118
- tabProgress.forEach { (index, progress) ->
119
- val target = tabPosition(index, selectedIndex)
120
- launch {
121
- if (index == selectedIndex || index == previousIndex) {
122
- progress.animateTo(target, tabSwitchSpec)
123
- } else {
124
- progress.snapTo(target)
125
- }
126
- }
127
- }
128
- }
129
-
130
- DisposableEffect(isFirstTab) {
131
- reportFloatingArrowBack(!isFirstTab)
132
- navigator.tabBackHandler = if (isFirstTab) null else ({ backToFirstTab() })
133
-
134
- onDispose {
135
- reportFloatingArrowBack(false)
136
- navigator.tabBackHandler = null
137
- }
138
- }
139
-
140
- val layout = getScreenLayout()
141
- val hasQr = floatingButton != null
142
- val compression = rememberDuoBarCompression(compressionBehavior, items.size, hasQr, layout)
143
- val railReserve = layout.sideBar?.takeIf { layout.isIPhoneDuo }?.let {
144
- it.bottom + duoRailHeight(items.size, hasQr, compressed = compression.tabBarCompressed) + DUO_GROUP_GAP
145
- } ?: 0.dp
146
- val onTabSelected: (Int) -> Unit = { index ->
147
- runCatching { maxApi?.triggerEventVibration("light", callback = null) }
148
- val switchTab = {
149
- if (index != selectedIndex) selectTab(index)
150
- }
151
- onTabPress?.invoke(index, switchTab) ?: switchTab()
152
- }
153
-
154
- Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
155
- Box(modifier = Modifier
156
- .fillMaxSize()
157
- .background(AppTheme.current.colors.background.default)
158
- ) {
159
- CompositionLocalProvider(
160
- LocalDuoRailReserve provides railReserve,
161
- LocalDuoBarCompression provides compression,
162
- LocalTabBarHasCenterAction provides hasCenterAction(floatingButton, items.size),
163
- ) {
164
- loadedTabs.forEach { index ->
165
- val item = items.getOrNull(index) ?: return@forEach
166
- val focused = index == selectedIndex
167
- val progress = progressOf(index)
168
- // the leaving tab stays drawn until it has slid off screen
169
- val visible = focused || abs(progress.value) < 1f
170
- key(index) {
171
- Box(
172
- Modifier
173
- .fillMaxSize()
174
- .zIndex(if (focused) 0f else -1f)
175
- .then(if (visible) Modifier.graphicsLayer { translationX = progress.value * size.width } else Hidden)
176
- ) {
177
- CompositionLocalProvider(LocalBottomTabFocused provides focused) {
178
- tabStateHolder.SaveableStateProvider(index) {
179
- StackScreen(
180
- content = item.screen,
181
- navigationOptions = getBottomTabOption(index),
182
- bottomTabIndex = index,
183
- onBackHandler = {
184
- if (backToInitialTab && index != 0) {
185
- backToFirstTab()
186
- } else {
187
- navigator.pop()
188
- }
189
- }
190
- )
191
- }
192
- }
193
- }
194
- }
195
- }
196
- }
197
- }
198
- BackHandler(enabled = !onFirstTab) {
199
- if (backToInitialTab) backToFirstTab() else navigator.pop()
200
- }
201
- ScaleSizeScope(TabBarMetrics.LABEL_MAX_SCALE) {
202
- if (layout.isIPhoneDuo) {
203
- DuoTabBar(
204
- layout = layout,
205
- items = items,
206
- floatingButton = floatingButton,
207
- selectedIndex = selectedIndex,
208
- onTabSelected = onTabSelected,
209
- compression = compression,
210
- )
211
- } else {
212
- BottomTabBar(
213
- items = items,
214
- floatingButton = floatingButton,
215
- selectedIndex = selectedIndex,
216
- onTabSelected = onTabSelected,
217
- )
218
- }
219
- }
220
- }
221
- }
222
-
223
- data class BottomTabItem(
224
- val name: String,
225
- val label: String,
226
- val icon: String,
227
- val showDot: Boolean = false,
228
- val badgeLabel: String? = null,
229
- val screen: @Composable () -> Unit,
230
- val options: NavigationOptions? = null,
231
- val initialParams: Any? = null
232
- )
233
-
234
- data class BottomTabFloatingButton(
235
- val icon: String,
236
- val label: String,
237
- val onPress: () -> Unit,
238
- // replaces the icon inside the 48 button, e.g. the button part of a Lottie; centered, unclipped
239
- val iconContent: (@Composable () -> Unit)? = null,
240
- // drawn over the label text, which stays, e.g. the label part of a Lottie; centered, unclipped
241
- val labelContent: (@Composable () -> Unit)? = null,
242
- )