@momo-kits/native-kits 0.163.1-beta.5-debug → 0.163.1-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 (143) hide show
  1. package/package.json +1 -1
  2. package/build.gradle.kts +0 -11
  3. package/compose/build.gradle.kts +0 -190
  4. package/compose/build.gradle.kts.backup +0 -190
  5. package/compose/compose.podspec +0 -47
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -123
  9. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  10. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  11. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  12. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  13. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  14. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  21. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  22. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +0 -52
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -106
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +0 -183
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +0 -207
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +0 -39
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +0 -86
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +0 -76
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +0 -76
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +0 -294
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +0 -33
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -826
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -269
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +0 -110
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -378
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +0 -69
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -82
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -356
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -113
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -543
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -23
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -76
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -231
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -112
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -477
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -114
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -214
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -240
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -216
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -259
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -182
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -41
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -84
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -40
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -328
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -97
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -310
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -90
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -323
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -217
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -473
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -199
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -91
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -470
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -88
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -131
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -203
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -175
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -234
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -188
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -306
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -188
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -276
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -2
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -35
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -2
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -253
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -129
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -98
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -172
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -360
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -562
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -154
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -225
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -169
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -320
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -81
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -309
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -34
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -360
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -132
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -128
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -70
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -58
  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 -105
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  134. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -184
  135. package/gradle/libs.versions.toml +0 -69
  136. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  137. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  138. package/gradle.properties +0 -26
  139. package/gradlew +0 -252
  140. package/gradlew.bat +0 -94
  141. package/ios-demo/README.md +0 -120
  142. package/local.properties +0 -8
  143. package/settings.gradle.kts +0 -64
@@ -1,234 +0,0 @@
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
- }
@@ -1,188 +0,0 @@
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
- }