@momo-kits/native-kits 0.169.14-beta.2 → 0.169.14-beta.2-debug

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +198 -0
  3. package/compose/compose.podspec +47 -0
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +130 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +208 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +315 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +206 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +421 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +758 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +260 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +406 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +111 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/LegacyBottomTabBar.kt +260 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/LegacyCurvedContainer.kt +86 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +400 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +65 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +143 -0
  134. package/gradle/libs.versions.toml +67 -0
  135. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  136. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  137. package/gradle.properties +24 -0
  138. package/gradlew +252 -0
  139. package/gradlew.bat +94 -0
  140. package/ios-demo/README.md +120 -0
  141. package/package.json +1 -1
  142. package/settings.gradle.kts +64 -0
@@ -0,0 +1,342 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.animation.core.*
4
+ import androidx.compose.foundation.Canvas
5
+ import androidx.compose.foundation.OverscrollEffect
6
+ import androidx.compose.foundation.background
7
+ import androidx.compose.foundation.gestures.FlingBehavior
8
+ import androidx.compose.foundation.gestures.ScrollableDefaults
9
+ import androidx.compose.foundation.layout.*
10
+ import androidx.compose.foundation.lazy.*
11
+ import androidx.compose.material.ExperimentalMaterialApi
12
+ import androidx.compose.material.pullrefresh.PullRefreshIndicator
13
+ import androidx.compose.material.pullrefresh.pullRefresh
14
+ import androidx.compose.material.pullrefresh.rememberPullRefreshState
15
+ import androidx.compose.runtime.*
16
+ import androidx.compose.ui.Alignment
17
+ import androidx.compose.ui.Modifier
18
+ import androidx.compose.ui.composed
19
+ import androidx.compose.ui.geometry.CornerRadius
20
+ import androidx.compose.ui.geometry.Offset
21
+ import androidx.compose.ui.geometry.Size
22
+ import androidx.compose.ui.graphics.Color
23
+ import androidx.compose.ui.graphics.drawscope.rotate
24
+ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
25
+ import androidx.compose.ui.layout.Measurable
26
+ import androidx.compose.ui.layout.MeasureResult
27
+ import androidx.compose.ui.layout.MeasureScope
28
+ import androidx.compose.ui.layout.layout
29
+ import androidx.compose.ui.platform.LocalDensity
30
+ import androidx.compose.ui.platform.LocalHapticFeedback
31
+ import androidx.compose.ui.unit.Constraints
32
+ import androidx.compose.ui.unit.IntOffset
33
+ import androidx.compose.ui.unit.dp
34
+ import kotlinx.coroutines.flow.collect
35
+ import kotlinx.coroutines.flow.combine
36
+ import kotlinx.coroutines.flow.distinctUntilChanged
37
+ import vn.momo.kits.const.Spacing
38
+ import vn.momo.kits.modifier.conditional
39
+ import vn.momo.kits.platform.getPlatformName
40
+
41
+ private const val BOX_KEY = "LazyColumnWithBouncing_BOX_KEY"
42
+
43
+
44
+ @OptIn(ExperimentalMaterialApi::class)
45
+ @Composable
46
+ internal fun overScrollWithPullToRefresh(
47
+ pullRefreshState: PullToRefreshCustomState?,
48
+ ): OverscrollEffect {
49
+ val density = LocalDensity.current
50
+ val hapticFeedback = LocalHapticFeedback.current
51
+
52
+ return remember(density) {
53
+ CupertinoOverscrollEffect(
54
+ pullRefreshState = if (pullRefreshState != null && pullRefreshState.sendHaptic != null) pullRefreshState
55
+ else pullRefreshState?.copy(
56
+ sendHaptic = {
57
+ hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
58
+ }),
59
+ density = density.density,
60
+ applyClip = false,
61
+ )
62
+ }
63
+ }
64
+
65
+ @OptIn(ExperimentalMaterialApi::class)
66
+ @Composable
67
+ fun LazyColumnWithBouncing(
68
+ modifier: Modifier = Modifier,
69
+ modifierIndicator: Modifier = Modifier,
70
+ state: LazyListState = rememberLazyListState(),
71
+ contentPadding: PaddingValues = PaddingValues(0.dp),
72
+ reverseLayout: Boolean = false,
73
+ verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
74
+ horizontalAlignment: Alignment.Horizontal = Alignment.Start,
75
+ flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
76
+ userScrollEnabled: Boolean = true,
77
+ pullRefreshState: PullToRefreshCustomState? = null,
78
+ content: LazyListScope.() -> Unit,
79
+ ) {
80
+ val height = remember { mutableIntStateOf(0) }
81
+ val maxConstraint = remember { mutableIntStateOf(0) }
82
+
83
+ LaunchedEffect(Unit) {
84
+ val addOn = 1
85
+ combine(
86
+ snapshotFlow { maxConstraint.value }.distinctUntilChanged(),
87
+ snapshotFlow { state.layoutInfo }
88
+ ) { cHeight, layoutInfo ->
89
+ height.value = when {
90
+ height.value == 0 && (state.canScrollForward || state.canScrollBackward) -> 0
91
+ layoutInfo.viewportSize.height >= cHeight && height.value == 0 -> 0
92
+ layoutInfo.visibleItemsInfo.lastOrNull()?.key != BOX_KEY -> 0
93
+ else -> {
94
+ val vH = layoutInfo.totalHeight
95
+ (cHeight - (vH - height.value) + addOn).coerceIn(0, cHeight)
96
+ }
97
+ }
98
+ }.collect()
99
+ }
100
+
101
+ val measureLayout = remember<MeasureScope.(Measurable, Constraints) -> MeasureResult>(maxConstraint) {
102
+ { m, c ->
103
+ val p = m.measure(c.copy(minHeight = 0))
104
+ maxConstraint.value = c.maxHeight
105
+ layout(p.width, p.height) {
106
+ p.place(IntOffset.Zero)
107
+ }
108
+ }
109
+ }
110
+
111
+ if (getPlatformName() == "iOS") {
112
+
113
+ val overscroll = overScrollWithPullToRefresh(
114
+ pullRefreshState = remember {
115
+ pullRefreshState
116
+ })
117
+
118
+ Box {
119
+ IosIndicator(
120
+ effect = overscroll,
121
+ modifier = modifierIndicator.align(Alignment.TopCenter).padding(top = Spacing.L).size(24.dp),
122
+ )
123
+ LazyColumn(
124
+ modifier = modifier
125
+ .layout(measure = measureLayout),
126
+ state = state,
127
+ contentPadding = contentPadding,
128
+ flingBehavior = flingBehavior,
129
+ horizontalAlignment = horizontalAlignment,
130
+ verticalArrangement = verticalArrangement,
131
+ reverseLayout = reverseLayout,
132
+ userScrollEnabled = userScrollEnabled,
133
+ overscrollEffect = overscroll,
134
+ ) {
135
+ content()
136
+ item(key = BOX_KEY) {
137
+ FakeBox(height)
138
+ }
139
+ }
140
+ }
141
+ } else {
142
+ val pullState = rememberPullRefreshState(
143
+ refreshing = pullRefreshState?.refreshingState?.value ?: false,
144
+ onRefresh = {
145
+ pullRefreshState?.onRefresh()
146
+ },
147
+ )
148
+
149
+ Box(
150
+ contentAlignment = Alignment.TopCenter,
151
+ modifier = Modifier.conditional(pullRefreshState != null) {
152
+ pullRefresh(pullState)
153
+ }) {
154
+ LazyColumn(
155
+ modifier = modifier.calculateHeight(height),
156
+ state = state,
157
+ contentPadding = contentPadding,
158
+ flingBehavior = flingBehavior,
159
+ horizontalAlignment = horizontalAlignment,
160
+ verticalArrangement = verticalArrangement,
161
+ reverseLayout = reverseLayout,
162
+ userScrollEnabled = userScrollEnabled,
163
+ ) {
164
+ content()
165
+ }
166
+ if (pullRefreshState != null) {
167
+ PullRefreshIndicator(
168
+ pullRefreshState.refreshingState.value,
169
+ pullState,
170
+ modifierIndicator.align(Alignment.TopCenter)
171
+ )
172
+ }
173
+
174
+ }
175
+ }
176
+ }
177
+
178
+ @Composable
179
+ private fun IosIndicator(
180
+ effect: OverscrollEffect?,
181
+ modifier: Modifier = Modifier,
182
+ ) {
183
+ if (effect !is CupertinoOverscrollEffect) return
184
+ if (effect.pullRefreshState == null) return
185
+ val state = effect.pullRefreshState
186
+
187
+
188
+ SpinningProgressBarLoading(
189
+ progress = state.position, modifier = modifier
190
+ )
191
+ }
192
+
193
+ @Composable
194
+ private fun SpinningProgressBarLoading(
195
+ progress: State<Float>, modifier: Modifier = Modifier
196
+ ) {
197
+ if (progress.value <= 0) {
198
+ return
199
+ }
200
+
201
+ val hapticFeedback = LocalHapticFeedback.current
202
+ val isSendHaptic = remember { mutableStateOf(false) }
203
+
204
+ val totalStep = 8
205
+ val stepAngle = 360f / totalStep
206
+ val baseOpacity = 1.0f / (totalStep + 2)
207
+ val minAlpha = 0.2f
208
+
209
+ val infiniteTransition = rememberInfiniteTransition()
210
+ val angle = infiniteTransition.animateFloat(
211
+ initialValue = 0f, targetValue = totalStep.toFloat(), animationSpec = infiniteRepeatable(
212
+ animation = tween(totalStep * 100, easing = LinearEasing),
213
+ repeatMode = RepeatMode.Restart
214
+ )
215
+ )
216
+
217
+ LaunchedEffect(Unit) {
218
+ snapshotFlow { progress.value }.collect {
219
+ if (it >= 1.0f && !isSendHaptic.value) {
220
+ hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
221
+ isSendHaptic.value = true
222
+ } else if (progress.value < 1.0f && isSendHaptic.value) {
223
+ isSendHaptic.value = false
224
+ }
225
+ }
226
+
227
+ }
228
+
229
+ Canvas(modifier = modifier) {
230
+ val percentage = progress.value
231
+ val clampedProgress = percentage.coerceIn(0f, 1f)
232
+ val value = (totalStep * clampedProgress).coerceIn(0f, totalStep.toFloat())
233
+ val integerPart = value.toInt()
234
+ val decimalPart = value - integerPart
235
+
236
+ if (integerPart <= 0) return@Canvas
237
+
238
+ val canvasWidth = size.width
239
+ val canvasHeight = size.height
240
+ val width = size.width * 0.3f
241
+ val height = size.height / 8
242
+ val cornerRadius = (width.coerceAtMost(height) / 2)
243
+
244
+ if (percentage >= 1f) {
245
+ for (i in 0..360 step 360 / totalStep) {
246
+ rotate(i.toFloat()) {
247
+ drawRoundRect(
248
+ color = Color.LightGray.copy(alpha = .7f),
249
+ topLeft = Offset(canvasWidth - width, (canvasHeight - height) / 2),
250
+ size = Size(width, height),
251
+ cornerRadius = CornerRadius(cornerRadius, cornerRadius)
252
+ )
253
+ }
254
+ }
255
+
256
+ val coefficient = 360f / totalStep
257
+
258
+ for (i in 1..4) {
259
+ rotate((angle.value.toInt() + i) * coefficient) {
260
+ drawRoundRect(
261
+ color = Color.Gray.copy(alpha = (0.2f + 0.2f * i).coerceIn(0f, 1f)),
262
+ topLeft = Offset(canvasWidth - width, (canvasHeight - height) / 2),
263
+ size = Size(width, height),
264
+ cornerRadius = CornerRadius(cornerRadius, cornerRadius)
265
+ )
266
+ }
267
+ }
268
+ return@Canvas
269
+ }
270
+
271
+ val topLeft = Offset(canvasWidth - width, (canvasHeight - height) / 2)
272
+ val rectSize = Size(width, height)
273
+ val cornerRadiusValue = CornerRadius(cornerRadius, cornerRadius)
274
+ repeat(integerPart) { i ->
275
+ val angle = i * stepAngle - 90f
276
+ val stepOpacity = 1f - (baseOpacity * i)
277
+
278
+ val alpha = if (i == integerPart - 1) {
279
+ (decimalPart * stepOpacity).coerceIn(minAlpha, 1f)
280
+ } else {
281
+ stepOpacity.coerceIn(minAlpha, 1f)
282
+ }
283
+
284
+ rotate(angle) {
285
+ drawRoundRect(
286
+ color = Color.Gray.copy(alpha = alpha),
287
+ topLeft = topLeft,
288
+ size = rectSize,
289
+ cornerRadius = cornerRadiusValue
290
+ )
291
+ }
292
+ }
293
+ }
294
+ }
295
+
296
+ @Composable
297
+ private fun FakeBox(height: MutableState<Int>) {
298
+ Box(
299
+ modifier = Modifier
300
+ .dynamicHeight(height).fillMaxWidth().background(Color.Red),
301
+ )
302
+ }
303
+
304
+ private fun Modifier.calculateHeight(
305
+ height: MutableState<Int>,
306
+ ) = this.layout { m, c ->
307
+ val p = m.measure(
308
+ constraints = c.copy(
309
+ minHeight = 0
310
+ )
311
+ )
312
+ val vH = p.height
313
+ val cMaxHeight = c.maxHeight
314
+ val addOn = 0.5.dp.roundToPx()
315
+ var extraSpace = addOn + height.value
316
+ if (height.value == 0) {
317
+ extraSpace = 0
318
+ }
319
+ if (vH - extraSpace >= cMaxHeight && height.value != 0) {
320
+ height.value = 0
321
+ } else if (vH - extraSpace < cMaxHeight) {
322
+ height.value = cMaxHeight - (vH - extraSpace) + addOn
323
+ }
324
+
325
+ layout(c.maxWidth, cMaxHeight) {
326
+ p.place(IntOffset.Zero)
327
+ }
328
+ }
329
+
330
+
331
+ private fun Modifier.dynamicHeight(height: MutableState<Int>) = composed {
332
+ val measure = remember<MeasureScope.(Measurable, Constraints) -> MeasureResult>(this, height) {
333
+ { m, c ->
334
+ val p = m.measure(c)
335
+ layout(c.maxWidth, height.value) { p.place(IntOffset.Zero) }
336
+ }
337
+ }
338
+ this.layout(measure = measure)
339
+ }
340
+
341
+ private val LazyListLayoutInfo.totalHeight: Int
342
+ get() = visibleItemsInfo.sumOf { it.size }
@@ -0,0 +1,108 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.animation.core.FastOutSlowInEasing
4
+ import androidx.compose.animation.core.animateFloatAsState
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.Box
9
+ import androidx.compose.foundation.layout.fillMaxWidth
10
+ import androidx.compose.foundation.layout.height
11
+ import androidx.compose.foundation.layout.size
12
+ import androidx.compose.foundation.shape.RoundedCornerShape
13
+ import androidx.compose.runtime.Composable
14
+ import androidx.compose.runtime.getValue
15
+ import androidx.compose.ui.Modifier
16
+ import androidx.compose.ui.draw.clip
17
+ import androidx.compose.ui.graphics.Color
18
+ import androidx.compose.ui.unit.dp
19
+ import vn.momo.kits.application.IsShowBaseLineDebug
20
+ import vn.momo.kits.const.AppTheme
21
+ import vn.momo.kits.const.Colors
22
+ import vn.momo.kits.const.Radius
23
+ import vn.momo.kits.modifier.conditional
24
+ import vn.momo.kits.platform.LottieAnimation
25
+
26
+ enum class LoaderType {
27
+ DOT, SPINNER
28
+ }
29
+
30
+ @Composable
31
+ fun Loader(
32
+ type: LoaderType = LoaderType.DOT,
33
+ tintColor: Color? = null,
34
+ modifier: Modifier = Modifier
35
+ ) {
36
+ when (type) {
37
+ LoaderType.DOT -> DotLoader(tintColor = tintColor, modifier = modifier)
38
+ LoaderType.SPINNER -> SpinnerLoader(tintColor = tintColor, modifier = modifier)
39
+ }
40
+ }
41
+
42
+ @Composable
43
+ fun DotLoader(
44
+ tintColor: Color? = null,
45
+ modifier: Modifier = Modifier
46
+ ) {
47
+ LottieAnimation(
48
+ path = "files/dot_loading",
49
+ tintColor = tintColor,
50
+ modifier = modifier
51
+ .size(width = 52.dp, height = 18.dp)
52
+ .conditional(IsShowBaseLineDebug) {
53
+ border(1.dp, Colors.blue_03)
54
+ }
55
+ )
56
+ }
57
+
58
+ @Composable
59
+ fun SpinnerLoader(
60
+ tintColor: Color? = null,
61
+ modifier: Modifier = Modifier
62
+ ) {
63
+ LottieAnimation(
64
+ path = "files/lottie_circle_loader",
65
+ tintColor = tintColor,
66
+ modifier = modifier
67
+ .size(24.dp)
68
+ .conditional(IsShowBaseLineDebug) {
69
+ border(1.dp, Colors.blue_03)
70
+ }
71
+ )
72
+ }
73
+
74
+ @Composable
75
+ fun ProgressBar(
76
+ percent: Float = 0f,
77
+ color: Color? = null,
78
+ modifier: Modifier = Modifier
79
+ ) {
80
+ val clampedPercent = percent.coerceIn(0f, 100f)
81
+ val animatedProgress by animateFloatAsState(
82
+ targetValue = clampedPercent / 100f,
83
+ animationSpec = tween(durationMillis = 200, easing = FastOutSlowInEasing),
84
+ label = "progressAnimation"
85
+ )
86
+
87
+ val trackColor = AppTheme.current.colors.background.default
88
+ val fillColor = color ?: AppTheme.current.colors.primary
89
+
90
+ Box(
91
+ modifier = modifier
92
+ .fillMaxWidth()
93
+ .height(4.dp)
94
+ .clip(RoundedCornerShape(Radius.XXS))
95
+ .background(trackColor)
96
+ .conditional(IsShowBaseLineDebug) {
97
+ border(1.dp, Colors.blue_03)
98
+ }
99
+ ) {
100
+ Box(
101
+ modifier = Modifier
102
+ .fillMaxWidth(animatedProgress)
103
+ .height(4.dp)
104
+ .clip(RoundedCornerShape(Radius.XXS))
105
+ .background(fillColor)
106
+ )
107
+ }
108
+ }
@@ -0,0 +1,56 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.Row
7
+ import androidx.compose.foundation.layout.padding
8
+ import androidx.compose.foundation.layout.size
9
+ import androidx.compose.foundation.shape.RoundedCornerShape
10
+ import androidx.compose.runtime.Composable
11
+ import androidx.compose.ui.Modifier
12
+ import androidx.compose.ui.graphics.Color
13
+ import androidx.compose.ui.unit.dp
14
+ import vn.momo.kits.application.IsShowBaseLineDebug
15
+ import vn.momo.kits.const.AppTheme
16
+ import vn.momo.kits.const.Colors
17
+ import vn.momo.kits.const.Spacing
18
+ import vn.momo.kits.modifier.conditional
19
+
20
+ @Composable
21
+ internal fun Dot(active: Boolean = false, activeColor: Color, modifier: Modifier = Modifier) {
22
+ return if (active) {
23
+ Box(
24
+ modifier = modifier.size(width = 12.dp, height = 4.dp).background(
25
+ color = activeColor,
26
+ shape = RoundedCornerShape(4.dp)
27
+ )
28
+ )
29
+ } else {
30
+ Box(
31
+ modifier = modifier.size(4.dp)
32
+ .background(
33
+ color = AppTheme.current.colors.background.pressed,
34
+ shape = RoundedCornerShape(4.dp)
35
+ )
36
+ )
37
+ }
38
+ }
39
+
40
+ @Composable
41
+ fun PaginationDot(
42
+ activeIndex: Int = 0,
43
+ dataLength: Int = 3
44
+ ) {
45
+ Row(modifier = Modifier.conditional(IsShowBaseLineDebug) {
46
+ border(1.dp, Colors.blue_03)
47
+ }) {
48
+ for (i in 0 until dataLength) {
49
+ Dot(
50
+ i == activeIndex,
51
+ AppTheme.current.colors.primary,
52
+ modifier = Modifier.padding(end = if (i != dataLength - 1) Spacing.XS else 0.dp)
53
+ )
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,40 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.layout.BoxWithConstraints
6
+ import androidx.compose.foundation.layout.padding
7
+ import androidx.compose.foundation.shape.RoundedCornerShape
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.ui.Alignment
10
+ import androidx.compose.ui.Modifier
11
+ import androidx.compose.ui.unit.dp
12
+ import vn.momo.kits.application.IsShowBaseLineDebug
13
+ import vn.momo.kits.const.Colors
14
+ import vn.momo.kits.const.Spacing
15
+ import vn.momo.kits.const.Typography
16
+ import vn.momo.kits.modifier.conditional
17
+
18
+ @Composable
19
+ fun PaginationNumber(
20
+ activeIndex: Int = 0,
21
+ dataLength: Int = 2
22
+ ) {
23
+ BoxWithConstraints(
24
+ modifier = Modifier.background(
25
+ color = Colors.opacity_black_20,
26
+ shape = RoundedCornerShape(Spacing.L)
27
+ )
28
+ .conditional(IsShowBaseLineDebug) {
29
+ border(1.dp, Colors.blue_03)
30
+ },
31
+ contentAlignment = Alignment.Center
32
+ ) {
33
+ Text(
34
+ modifier = Modifier.padding(horizontal = Spacing.S),
35
+ text = "${1 + activeIndex}/$dataLength",
36
+ color = Colors.black_01,
37
+ style = Typography.labelDefaultMedium
38
+ )
39
+ }
40
+ }
@@ -0,0 +1,82 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.horizontalScroll
6
+ import androidx.compose.foundation.layout.*
7
+ import androidx.compose.foundation.rememberScrollState
8
+ import androidx.compose.foundation.shape.RoundedCornerShape
9
+ import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.derivedStateOf
11
+ import androidx.compose.runtime.getValue
12
+ import androidx.compose.runtime.remember
13
+ import androidx.compose.ui.Alignment
14
+ import androidx.compose.ui.Modifier
15
+ import androidx.compose.ui.draw.clip
16
+ import androidx.compose.ui.unit.Dp
17
+ import androidx.compose.ui.unit.dp
18
+ import vn.momo.kits.application.IsShowBaseLineDebug
19
+ import vn.momo.kits.const.AppTheme
20
+ import vn.momo.kits.const.Colors
21
+ import vn.momo.kits.const.Spacing
22
+ import vn.momo.kits.modifier.conditional
23
+
24
+ private val INDICATOR_WIDTH = 24.dp
25
+ private val PROGRESS_WIDTH = 72.dp
26
+
27
+ private fun calculateOffset(currentPosition: Int, maxBound: Int): Dp {
28
+ return if (maxBound == 0) 0.dp else {
29
+ (PROGRESS_WIDTH - INDICATOR_WIDTH) * (currentPosition / maxBound.toFloat())
30
+ }
31
+ }
32
+
33
+ @Composable
34
+ fun PaginationScroll(
35
+ modifier: Modifier = Modifier,
36
+ content: @Composable () -> Unit
37
+ ) {
38
+ val scrollState = rememberScrollState()
39
+ val theme = AppTheme.current
40
+
41
+ val indicatorOffset by remember {
42
+ derivedStateOf {
43
+ calculateOffset(scrollState.value, scrollState.maxValue)
44
+ }
45
+ }
46
+
47
+ val (progressBackground, indicatorColor) = remember(theme) {
48
+ theme.colors.background.pressed to theme.colors.primary
49
+ }
50
+
51
+ Column(horizontalAlignment = Alignment.CenterHorizontally) {
52
+ Row(
53
+ modifier = modifier
54
+ .fillMaxWidth()
55
+ .conditional(IsShowBaseLineDebug) {
56
+ border(1.dp, Colors.blue_03)
57
+ }
58
+ .padding(bottom = Spacing.L)
59
+ .horizontalScroll(scrollState)
60
+ ) {
61
+ content()
62
+ }
63
+
64
+ // Progress indicator
65
+ Box(
66
+ modifier = Modifier
67
+ .clip(RoundedCornerShape(Spacing.XS))
68
+ .width(PROGRESS_WIDTH)
69
+ .height(4.dp)
70
+ .background(color = progressBackground)
71
+ ) {
72
+ Box(
73
+ modifier = Modifier
74
+ .offset(x = indicatorOffset)
75
+ .clip(RoundedCornerShape(Spacing.XS))
76
+ .width(INDICATOR_WIDTH)
77
+ .height(4.dp)
78
+ .background(color = indicatorColor)
79
+ )
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,39 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.layout.Row
6
+ import androidx.compose.foundation.layout.padding
7
+ import androidx.compose.foundation.shape.RoundedCornerShape
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.ui.Modifier
10
+ import androidx.compose.ui.unit.dp
11
+ import vn.momo.kits.application.IsShowBaseLineDebug
12
+ import vn.momo.kits.const.Colors
13
+ import vn.momo.kits.const.Spacing
14
+ import vn.momo.kits.modifier.conditional
15
+
16
+ @Composable
17
+ fun PaginationWhiteDot(
18
+ activeIndex: Int = 0,
19
+ dataLength: Int = 3
20
+ ) {
21
+ Row(
22
+ modifier = Modifier.background(
23
+ color = Colors.opacity_black_20,
24
+ shape = RoundedCornerShape(Spacing.S)
25
+ )
26
+ .conditional(IsShowBaseLineDebug) {
27
+ border(1.dp, Colors.blue_03)
28
+ }
29
+ .padding(Spacing.XS)
30
+ ) {
31
+ for (i in 0 until dataLength) {
32
+ Dot(
33
+ i == activeIndex,
34
+ Colors.black_01,
35
+ modifier = Modifier.padding(end = if (i != dataLength - 1) Spacing.XS else 0.dp)
36
+ )
37
+ }
38
+ }
39
+ }