@momo-kits/native-kits 0.163.1-beta.2 → 0.163.1-beta.3-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 (136) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +189 -0
  3. package/compose/build.gradle.kts.backup +189 -0
  4. package/compose/compose.podspec +47 -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/Platform.android.kt +123 -0
  7. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  8. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  9. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  10. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  11. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  12. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  13. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  14. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +108 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +294 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +826 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +107 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +82 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +140 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +188 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +112 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +477 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +214 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +216 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +259 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +180 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +328 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +97 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +217 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +470 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +134 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +203 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +175 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +269 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +253 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +94 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +175 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +360 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +557 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +155 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +223 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +319 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +81 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +309 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +34 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +360 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +128 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +70 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +58 -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 +105 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +184 -0
  128. package/gradle/libs.versions.toml +67 -0
  129. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  130. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  131. package/gradle.properties +26 -0
  132. package/gradlew +252 -0
  133. package/gradlew.bat +94 -0
  134. package/local.properties +8 -0
  135. package/package.json +1 -1
  136. package/settings.gradle.kts +64 -0
@@ -0,0 +1,234 @@
1
+ package vn.momo.kits.components.datetimepicker
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.remember
5
+ import kotlinx.datetime.*
6
+ import kotlinx.datetime.number
7
+ import kotlin.time.Clock
8
+ import kotlin.time.ExperimentalTime
9
+
10
+ /**
11
+ * Format a LocalDateTime object into a string
12
+ */
13
+ fun formatLocalDateTime(dateTime: LocalDateTime, format: String = "yyyy-MM-dd HH:mm"): String {
14
+ return when (format) {
15
+ "yyyy-MM-dd HH:mm" -> "${dateTime.year}-${paddingNum(dateTime.month.number)}-${
16
+ paddingNum(
17
+ dateTime.day
18
+ )
19
+ } ${paddingNum(dateTime.hour)}:${paddingNum(dateTime.minute)}"
20
+
21
+ "dd-MM-yyyy" -> "${paddingNum(dateTime.day)}-${paddingNum(dateTime.month.number)}-${dateTime.year}"
22
+ "HH:mm" -> "${paddingNum(dateTime.hour)}:${paddingNum(dateTime.minute)}"
23
+ else -> "${dateTime.year}-${paddingNum(dateTime.month.number)}-${paddingNum(dateTime.day)} ${
24
+ paddingNum(
25
+ dateTime.hour
26
+ )
27
+ }:${paddingNum(dateTime.minute)}"
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Pad a number with a leading zero if it's less than 10
33
+ */
34
+ fun paddingNum(num: Int): String {
35
+ return if (num > 9) num.toString() else "0$num"
36
+ }
37
+
38
+ /**
39
+ * Get a list of days in a month
40
+ */
41
+ fun getDaysInMonth(
42
+ year: Int,
43
+ month: Int,
44
+ minDate: LocalDateTime,
45
+ maxDate: LocalDateTime
46
+ ): List<String> {
47
+ val daysInMonth = when (month) {
48
+ 1, 3, 5, 7, 8, 10, 12 -> 31
49
+ 4, 6, 9, 11 -> 30
50
+ 2 -> if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) 29 else 28
51
+ else -> throw IllegalArgumentException("Invalid month: $month")
52
+ }
53
+
54
+ var startDay = 1
55
+ var endDay = daysInMonth
56
+
57
+ if (year == minDate.year && month == minDate.month.number) {
58
+ startDay = minDate.day
59
+ }
60
+
61
+ if (year == maxDate.year && month == maxDate.month.number) {
62
+ endDay = maxDate.day
63
+ }
64
+
65
+ val days = mutableListOf<String>()
66
+ for (day in startDay..endDay) {
67
+ days.add(paddingNum(day))
68
+ }
69
+
70
+ return days
71
+ }
72
+
73
+ /**
74
+ * Get a list of months
75
+ */
76
+ fun getMonths(
77
+ minDate: LocalDateTime,
78
+ maxDate: LocalDateTime,
79
+ currentYear: Int
80
+ ): List<String> {
81
+ var startMonth = 1
82
+ var endMonth = 12
83
+
84
+ if (currentYear == minDate.year) {
85
+ startMonth = minDate.month.number
86
+ }
87
+
88
+ if (currentYear == maxDate.year) {
89
+ endMonth = maxDate.month.number
90
+ }
91
+
92
+ val months = mutableListOf<String>()
93
+ for (month in startMonth..endMonth) {
94
+ months.add(paddingNum(month))
95
+ }
96
+
97
+ return months
98
+ }
99
+
100
+ /**
101
+ * Get a list of years
102
+ */
103
+ fun getYears(minDate: LocalDateTime, maxDate: LocalDateTime): List<String> {
104
+ val startYear = minDate.year
105
+ val endYear = maxDate.year
106
+ val years = mutableListOf<String>()
107
+
108
+ for (year in startYear..endYear) {
109
+ years.add(year.toString())
110
+ }
111
+
112
+ return years
113
+ }
114
+
115
+ /**
116
+ * Get a list of hours
117
+ */
118
+ fun getHours(hourMode: Int): List<String> {
119
+ val hours = mutableListOf<String>()
120
+ for (i in 0 until hourMode) {
121
+ val hour = if (hourMode == 12) i + 1 else i
122
+ hours.add(paddingNum(hour))
123
+ }
124
+ return hours
125
+ }
126
+
127
+ /**
128
+ * Get a list of minutes
129
+ */
130
+ fun getMinutes(interval: Int): List<String> {
131
+ val minutes = mutableListOf<String>()
132
+ var min = 0
133
+ while (min < 60) {
134
+ minutes.add(paddingNum(min))
135
+ min += interval
136
+ }
137
+ return minutes
138
+ }
139
+
140
+ /**
141
+ * Time mode for 12-hour clock
142
+ */
143
+ val timeMode = listOf("AM", "PM")
144
+
145
+ /**
146
+ * Get today's date
147
+ */
148
+ @OptIn(ExperimentalTime::class)
149
+ fun getCurrentDateTime(): LocalDateTime {
150
+ return Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
151
+ }
152
+
153
+ /**
154
+ * Create a date that's a certain number of years before or after the current date
155
+ */
156
+ fun createRelativeDate(years: Int): LocalDateTime {
157
+ val currentDateTime = getCurrentDateTime()
158
+ val period = DatePeriod(years = if (years < 0) -years else years)
159
+
160
+ val adjustedDate = if (years < 0) {
161
+ currentDateTime.date.minus(period)
162
+ } else {
163
+ currentDateTime.date.plus(period)
164
+ }
165
+
166
+ return LocalDateTime(
167
+ adjustedDate.year,
168
+ adjustedDate.month.number,
169
+ adjustedDate.day,
170
+ currentDateTime.hour,
171
+ currentDateTime.minute
172
+ )
173
+ }
174
+
175
+ @Composable
176
+ internal fun getDateComponents(
177
+ format: String,
178
+ currentDate: PickerData,
179
+ effectiveMinDate: LocalDateTime,
180
+ effectiveMaxDate: LocalDateTime,
181
+ minuteInterval: Int,
182
+ ): List<DateComponent> {
183
+ val formatParts = remember(format) {
184
+ format.split(Regex("[^A-Za-z]+"))
185
+ }
186
+
187
+ val isOnlyHour = remember(formatParts) {
188
+ formatParts.size == 1 && formatParts[0] == "HH"
189
+ }
190
+
191
+ val dayData =
192
+ remember(currentDate.year, currentDate.month, effectiveMinDate, effectiveMaxDate) {
193
+ getDaysInMonth(currentDate.year, currentDate.month, effectiveMinDate, effectiveMaxDate)
194
+ }
195
+
196
+ val monthData = remember(currentDate.year, effectiveMinDate, effectiveMaxDate) {
197
+ getMonths(effectiveMinDate, effectiveMaxDate, currentDate.year)
198
+ }
199
+
200
+ val yearData = remember(effectiveMinDate, effectiveMaxDate) {
201
+ getYears(effectiveMinDate, effectiveMaxDate)
202
+ }
203
+
204
+ val hourData = remember(isOnlyHour) {
205
+ getHours(if (isOnlyHour) 12 else 24)
206
+ }
207
+
208
+ val minData = remember(minuteInterval) {
209
+ getMinutes(minuteInterval)
210
+ }
211
+
212
+ val dateComponents =
213
+ remember(formatParts, dayData, monthData, yearData, hourData, minData, isOnlyHour) {
214
+ val components = mutableListOf<DateComponent>()
215
+
216
+ formatParts.forEach { part ->
217
+ when (part) {
218
+ "DD" -> components.add(DateComponent("day", dayData))
219
+ "MM" -> components.add(DateComponent("month", monthData))
220
+ "YYYY" -> components.add(DateComponent("year", yearData))
221
+ "HH" -> components.add(DateComponent("hour", hourData))
222
+ "mm" -> components.add(DateComponent("minute", minData))
223
+ }
224
+ }
225
+
226
+ if (isOnlyHour) {
227
+ components.add(DateComponent("timeMode", timeMode))
228
+ }
229
+
230
+ components
231
+ }
232
+
233
+ return dateComponents
234
+ }
@@ -0,0 +1,188 @@
1
+ package vn.momo.kits.components.datetimepicker
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.gestures.animateScrollBy
6
+ import androidx.compose.foundation.layout.Box
7
+ import androidx.compose.foundation.layout.fillMaxWidth
8
+ import androidx.compose.foundation.layout.height
9
+ import androidx.compose.foundation.lazy.LazyColumn
10
+ import androidx.compose.foundation.lazy.LazyListState
11
+ import androidx.compose.foundation.lazy.rememberLazyListState
12
+ import androidx.compose.foundation.shape.RoundedCornerShape
13
+ import androidx.compose.runtime.*
14
+ import androidx.compose.ui.Alignment
15
+ import androidx.compose.ui.Modifier
16
+ import androidx.compose.ui.draw.alpha
17
+ import androidx.compose.ui.graphics.graphicsLayer
18
+ import androidx.compose.ui.platform.LocalDensity
19
+ import androidx.compose.ui.unit.Dp
20
+ import androidx.compose.ui.unit.dp
21
+ import androidx.compose.ui.zIndex
22
+ import kotlinx.coroutines.FlowPreview
23
+ import kotlinx.coroutines.delay
24
+ import kotlinx.coroutines.flow.collect
25
+ import kotlinx.coroutines.flow.debounce
26
+ import kotlinx.coroutines.flow.distinctUntilChanged
27
+ import kotlinx.coroutines.flow.onEach
28
+ import vn.momo.kits.components.Text
29
+ import vn.momo.kits.const.AppTheme
30
+ import vn.momo.kits.const.Colors
31
+ import vn.momo.kits.const.Radius
32
+ import vn.momo.kits.const.Typography
33
+ import kotlin.math.abs
34
+ import kotlin.time.Duration.Companion.milliseconds
35
+
36
+ private val wheelItemHeight = 42.dp
37
+ private val wheelPickerBorderWidth = 1.dp
38
+
39
+ @OptIn(FlowPreview::class)
40
+ @Composable
41
+ internal fun WheelPicker(
42
+ name: String,
43
+ data: List<String>,
44
+ selectedData: String,
45
+ onChange: (String, String) -> Unit,
46
+ modifier: Modifier = Modifier
47
+ ) {
48
+ val listState = rememberLazyListState()
49
+ val itemHeightPx = with(LocalDensity.current) { wheelItemHeight.toPx() }
50
+
51
+ val paddedData = remember(data) {
52
+ listOf("", "") + data + listOf("", "")
53
+ }
54
+
55
+ val initialIndex = remember(selectedData, paddedData) {
56
+ paddedData.indexOf(selectedData).coerceAtLeast(2)
57
+ }
58
+
59
+ LaunchedEffect(initialIndex) {
60
+ listState.scrollToItem(initialIndex - 2)
61
+ }
62
+
63
+ var selectedIndex by remember { mutableStateOf(0) }
64
+
65
+ LaunchedEffect(paddedData) {
66
+ snapshotFlow { selectedIndex }
67
+ .distinctUntilChanged()
68
+ .debounce(50.milliseconds)
69
+ .onEach {
70
+ val value = paddedData.getOrNull(it)
71
+ if (!value.isNullOrEmpty()) {
72
+ onChange(name, value)
73
+ }
74
+ }
75
+ .collect()
76
+ }
77
+
78
+ LaunchedEffect(paddedData) {
79
+ snapshotFlow { listState.isScrollInProgress }
80
+ .onEach {
81
+ if (it) return@onEach
82
+ val firstItem = listState.layoutInfo.visibleItemsInfo.firstOrNull() ?: return@onEach
83
+ val firstItemIdx = firstItem.index
84
+ val firstItemOffset = firstItem.offset
85
+ if (firstItemOffset == 0) {
86
+ selectedIndex = firstItemIdx + 2
87
+ return@onEach
88
+ }
89
+ val isScrollUp = abs(firstItemOffset) > itemHeightPx / 2
90
+ val offset = if (isScrollUp) {
91
+ itemHeightPx - abs(firstItemOffset)
92
+ } else {
93
+ -abs(firstItemOffset)
94
+ }
95
+ delay(50.milliseconds)
96
+ listState.animateScrollBy(offset.toFloat())
97
+ val centeredIndex = firstItemIdx + (if (isScrollUp) 1 else 0) + 2
98
+ if (centeredIndex in 2 until paddedData.size - 2) {
99
+ selectedIndex = centeredIndex
100
+ }
101
+ }
102
+ .collect()
103
+ }
104
+
105
+ Box(
106
+ modifier = modifier
107
+ .border(
108
+ width = wheelPickerBorderWidth,
109
+ color = AppTheme.current.colors.border.default,
110
+ shape = RoundedCornerShape(Radius.S)
111
+ )
112
+ .background(
113
+ color = AppTheme.current.colors.background.surface,
114
+ )
115
+ ) {
116
+ LazyColumn(
117
+ state = listState,
118
+ modifier = Modifier
119
+ .fillMaxWidth()
120
+ ) {
121
+ items(paddedData.size) { index ->
122
+ WheelPickerItem(
123
+ text = paddedData[index],
124
+ isSelected = index == selectedIndex,
125
+ index = index,
126
+ listState = listState,
127
+ itemHeight = wheelItemHeight
128
+ )
129
+ }
130
+ }
131
+
132
+ Box(
133
+ modifier = Modifier
134
+ .fillMaxWidth()
135
+ .height(wheelItemHeight)
136
+ .background(Colors.blue_10)
137
+ .align(Alignment.Center)
138
+ .alpha(0.2f)
139
+ .zIndex(-2f)
140
+ )
141
+ }
142
+ }
143
+
144
+ @Composable
145
+ internal fun WheelPickerItem(
146
+ text: String,
147
+ isSelected: Boolean,
148
+ index: Int,
149
+ listState: LazyListState,
150
+ itemHeight: Dp
151
+ ) {
152
+ Box(
153
+ modifier = Modifier
154
+ .fillMaxWidth()
155
+ .height(itemHeight)
156
+ .graphicsLayer {
157
+ val firstVisibleIndex = listState.firstVisibleItemIndex
158
+ val visibleItemOffset = listState.firstVisibleItemScrollOffset
159
+
160
+ val viewportHeight = 5 * itemHeight.value
161
+ val itemHeightValue = itemHeight.value
162
+
163
+ val absoluteOffset =
164
+ (index - firstVisibleIndex) * itemHeightValue - (visibleItemOffset / itemHeightValue)
165
+ val relativePosition = absoluteOffset / viewportHeight
166
+
167
+ val distance = abs(2 - relativePosition)
168
+
169
+ alpha = when {
170
+ distance <= 1 -> 1f
171
+ distance <= 2 -> 0.8f
172
+ distance <= 3 -> 0.4f
173
+ else -> 0.4f
174
+ }
175
+ },
176
+ contentAlignment = Alignment.Center
177
+ ) {
178
+ Text(
179
+ text = text,
180
+ style = Typography.actionSBold,
181
+ modifier = Modifier.graphicsLayer {
182
+ val scale = if (isSelected) 1f else 0.87f
183
+ scaleX = scale
184
+ scaleY = scale
185
+ }
186
+ )
187
+ }
188
+ }