@momo-kits/native-kits 0.114.2-beta.1 → 0.114.2-beta.3

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 (29) hide show
  1. package/compose/build.gradle.kts +1 -0
  2. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +1 -1
  3. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +28 -30
  4. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +1 -1
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +29 -9
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +1 -1
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +4 -4
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +1 -1
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +3 -3
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +3 -3
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +3 -3
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +1 -1
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +3 -3
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +1 -1
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +4 -4
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +1 -1
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +1 -1
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +3 -2
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/dateTimePicker/DateTimePicker.kt +178 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/dateTimePicker/DateTimePickerExample.kt +90 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/dateTimePicker/DateTimePickerTypes.kt +15 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/dateTimePicker/DateTimePickerUtils.kt +226 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/dateTimePicker/WheelPicker.kt +201 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +84 -124
  25. package/ios/Application/ApplicationEnvironment.swift +17 -9
  26. package/ios/Application/HeaderRight.swift +29 -30
  27. package/ios/Template/TrustBanner/TrustBanner.swift +75 -144
  28. package/local.properties +2 -2
  29. package/package.json +1 -1
@@ -0,0 +1,90 @@
1
+ package vn.momo.kits.components.dateTimePicker
2
+
3
+ import androidx.compose.foundation.layout.Column
4
+ import androidx.compose.foundation.layout.Spacer
5
+ import androidx.compose.foundation.layout.fillMaxWidth
6
+ import androidx.compose.foundation.layout.height
7
+ import androidx.compose.foundation.layout.padding
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.runtime.getValue
10
+ import androidx.compose.runtime.mutableStateOf
11
+ import androidx.compose.runtime.remember
12
+ import androidx.compose.runtime.setValue
13
+ import androidx.compose.ui.Modifier
14
+ import vn.momo.kits.components.Text
15
+ import vn.momo.kits.const.Spacing
16
+ import vn.momo.kits.const.Typography
17
+
18
+ /**
19
+ * Example usage of DateTimePicker component
20
+ */
21
+ @Composable
22
+ fun DateTimePickerExample() {
23
+ // The current date and time
24
+ val now = remember { getCurrentDateTime() }
25
+
26
+ // State to hold the selected date
27
+ var selectedDate by remember { mutableStateOf(now) }
28
+
29
+ Column(
30
+ modifier = Modifier
31
+ .fillMaxWidth()
32
+ .padding(Spacing.M)
33
+ ) {
34
+ // Display the current selected date
35
+ Text(
36
+ text = "Selected Date: ${formatLocalDateTime(selectedDate)}",
37
+ style = Typography.bodyDefaultRegular
38
+ )
39
+
40
+ Spacer(modifier = Modifier.height(Spacing.L))
41
+
42
+ // Date Picker (DD-MM-YYYY)
43
+ Text(
44
+ text = "Date Picker",
45
+ style = Typography.descriptionDefaultRegular
46
+ )
47
+
48
+ Spacer(modifier = Modifier.height(Spacing.S))
49
+
50
+ DateTimePicker(
51
+ selectedValue = selectedDate,
52
+ onChange = { selectedDate = it },
53
+ format = "DD-MM-YYYY"
54
+ )
55
+
56
+ Spacer(modifier = Modifier.height(Spacing.L))
57
+
58
+ // Date and Time Picker (DD-MM-YYYY HH:mm)
59
+ Text(
60
+ text = "Date and Time Picker",
61
+ style = Typography.descriptionDefaultRegular
62
+ )
63
+
64
+ Spacer(modifier = Modifier.height(Spacing.S))
65
+
66
+ DateTimePicker(
67
+ selectedValue = selectedDate,
68
+ onChange = { selectedDate = it },
69
+ format = "DD-MM-YYYY-HH-mm",
70
+ arrayLabelTime = listOf("Day", "Month", "Year", "Hour", "Minute")
71
+ )
72
+
73
+ Spacer(modifier = Modifier.height(Spacing.L))
74
+
75
+ // Time Picker (HH:mm)
76
+ Text(
77
+ text = "Time Picker",
78
+ style = Typography.descriptionDefaultRegular
79
+ )
80
+
81
+ Spacer(modifier = Modifier.height(Spacing.S))
82
+
83
+ DateTimePicker(
84
+ selectedValue = selectedDate,
85
+ onChange = { selectedDate = it },
86
+ format = "HH-mm",
87
+ arrayLabelTime = listOf("Hour", "Minute")
88
+ )
89
+ }
90
+ }
@@ -0,0 +1,15 @@
1
+ package vn.momo.kits.components.dateTimePicker
2
+
3
+ data class PickerData(
4
+ var day: Int,
5
+ var month: Int,
6
+ var year: Int,
7
+ var hour: Int = 0,
8
+ var minute: Int = 0,
9
+ var timeMode: String = ""
10
+ )
11
+
12
+ data class DateComponent(
13
+ val name: String,
14
+ val data: List<String>
15
+ )
@@ -0,0 +1,226 @@
1
+ package vn.momo.kits.components.dateTimePicker
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.remember
5
+ import kotlinx.datetime.Clock
6
+ import kotlinx.datetime.DatePeriod
7
+ import kotlinx.datetime.LocalDateTime
8
+ import kotlinx.datetime.TimeZone
9
+ import kotlinx.datetime.minus
10
+ import kotlinx.datetime.number
11
+ import kotlinx.datetime.plus
12
+ import kotlinx.datetime.toLocalDateTime
13
+
14
+ /**
15
+ * Format a LocalDateTime object into a string
16
+ */
17
+ fun formatLocalDateTime(dateTime: LocalDateTime, format: String = "yyyy-MM-dd HH:mm"): String {
18
+ return when (format) {
19
+ "yyyy-MM-dd HH:mm" -> "${dateTime.year}-${paddingNum(dateTime.month.number)}-${paddingNum(dateTime.dayOfMonth)} ${paddingNum(dateTime.hour)}:${paddingNum(dateTime.minute)}"
20
+ "dd-MM-yyyy" -> "${paddingNum(dateTime.dayOfMonth)}-${paddingNum(dateTime.month.number)}-${dateTime.year}"
21
+ "HH:mm" -> "${paddingNum(dateTime.hour)}:${paddingNum(dateTime.minute)}"
22
+ else -> "${dateTime.year}-${paddingNum(dateTime.month.number)}-${paddingNum(dateTime.dayOfMonth)} ${paddingNum(dateTime.hour)}:${paddingNum(dateTime.minute)}"
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Pad a number with a leading zero if it's less than 10
28
+ */
29
+ fun paddingNum(num: Int): String {
30
+ return if (num > 9) num.toString() else "0$num"
31
+ }
32
+
33
+ /**
34
+ * Get a list of days in a month
35
+ */
36
+ fun getDaysInMonth(
37
+ year: Int,
38
+ month: Int,
39
+ minDate: LocalDateTime,
40
+ maxDate: LocalDateTime
41
+ ): List<String> {
42
+ val daysInMonth = when (month) {
43
+ 1, 3, 5, 7, 8, 10, 12 -> 31
44
+ 4, 6, 9, 11 -> 30
45
+ 2 -> if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) 29 else 28
46
+ else -> throw IllegalArgumentException("Invalid month: $month")
47
+ }
48
+
49
+ var startDay = 1
50
+ var endDay = daysInMonth
51
+
52
+ if (year == minDate.year && month == minDate.month.number) {
53
+ startDay = minDate.dayOfMonth
54
+ }
55
+
56
+ if (year == maxDate.year && month == maxDate.month.number) {
57
+ endDay = maxDate.dayOfMonth
58
+ }
59
+
60
+ val days = mutableListOf<String>()
61
+ for (day in startDay..endDay) {
62
+ days.add(paddingNum(day))
63
+ }
64
+
65
+ return days
66
+ }
67
+
68
+ /**
69
+ * Get a list of months
70
+ */
71
+ fun getMonths(
72
+ minDate: LocalDateTime,
73
+ maxDate: LocalDateTime,
74
+ currentYear: Int
75
+ ): List<String> {
76
+ var startMonth = 1
77
+ var endMonth = 12
78
+
79
+ if (currentYear == minDate.year) {
80
+ startMonth = minDate.month.number
81
+ }
82
+
83
+ if (currentYear == maxDate.year) {
84
+ endMonth = maxDate.month.number
85
+ }
86
+
87
+ val months = mutableListOf<String>()
88
+ for (month in startMonth..endMonth) {
89
+ months.add(paddingNum(month))
90
+ }
91
+
92
+ return months
93
+ }
94
+
95
+ /**
96
+ * Get a list of years
97
+ */
98
+ fun getYears(minDate: LocalDateTime, maxDate: LocalDateTime): List<String> {
99
+ val startYear = minDate.year
100
+ val endYear = maxDate.year
101
+ val years = mutableListOf<String>()
102
+
103
+ for (year in startYear..endYear) {
104
+ years.add(year.toString())
105
+ }
106
+
107
+ return years
108
+ }
109
+
110
+ /**
111
+ * Get a list of hours
112
+ */
113
+ fun getHours(hourMode: Int): List<String> {
114
+ val hours = mutableListOf<String>()
115
+ for (i in 0 until hourMode) {
116
+ val hour = if (hourMode == 12) i + 1 else i
117
+ hours.add(paddingNum(hour))
118
+ }
119
+ return hours
120
+ }
121
+
122
+ /**
123
+ * Get a list of minutes
124
+ */
125
+ fun getMinutes(interval: Int): List<String> {
126
+ val minutes = mutableListOf<String>()
127
+ var min = 0
128
+ while (min < 60) {
129
+ minutes.add(paddingNum(min))
130
+ min += interval
131
+ }
132
+ return minutes
133
+ }
134
+
135
+ /**
136
+ * Time mode for 12-hour clock
137
+ */
138
+ val timeMode = listOf("AM", "PM")
139
+
140
+ /**
141
+ * Get today's date
142
+ */
143
+ fun getCurrentDateTime(): LocalDateTime {
144
+ return Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
145
+ }
146
+
147
+ /**
148
+ * Create a date that's a certain number of years before or after the current date
149
+ */
150
+ fun createRelativeDate(years: Int): LocalDateTime {
151
+ val currentDateTime = getCurrentDateTime()
152
+ val period = DatePeriod(years = if (years < 0) -years else years)
153
+
154
+ val adjustedDate = if (years < 0) {
155
+ currentDateTime.date.minus(period)
156
+ } else {
157
+ currentDateTime.date.plus(period)
158
+ }
159
+
160
+ return LocalDateTime(
161
+ adjustedDate.year,
162
+ adjustedDate.monthNumber,
163
+ adjustedDate.dayOfMonth,
164
+ currentDateTime.hour,
165
+ currentDateTime.minute
166
+ )
167
+ }
168
+
169
+ @Composable
170
+ internal fun getDateComponents(
171
+ format: String,
172
+ currentDate: PickerData,
173
+ effectiveMinDate: LocalDateTime,
174
+ effectiveMaxDate: LocalDateTime,
175
+ minuteInterval: Int,
176
+ ): List<DateComponent> {
177
+ val formatParts = remember(format) {
178
+ format.split(Regex("[^A-Za-z]+"))
179
+ }
180
+
181
+ val isOnlyHour = remember(formatParts) {
182
+ formatParts.size == 1 && formatParts[0] == "HH"
183
+ }
184
+
185
+ val dayData = remember(currentDate.year, currentDate.month, effectiveMinDate, effectiveMaxDate) {
186
+ getDaysInMonth(currentDate.year, currentDate.month, effectiveMinDate, effectiveMaxDate)
187
+ }
188
+
189
+ val monthData = remember(currentDate.year, effectiveMinDate, effectiveMaxDate) {
190
+ getMonths(effectiveMinDate, effectiveMaxDate, currentDate.year)
191
+ }
192
+
193
+ val yearData = remember(effectiveMinDate, effectiveMaxDate) {
194
+ getYears(effectiveMinDate, effectiveMaxDate)
195
+ }
196
+
197
+ val hourData = remember(isOnlyHour) {
198
+ getHours(if (isOnlyHour) 12 else 24)
199
+ }
200
+
201
+ val minData = remember(minuteInterval) {
202
+ getMinutes(minuteInterval)
203
+ }
204
+
205
+ val dateComponents = remember(formatParts, dayData, monthData, yearData, hourData, minData, isOnlyHour) {
206
+ val components = mutableListOf<DateComponent>()
207
+
208
+ formatParts.forEach { part ->
209
+ when (part) {
210
+ "DD" -> components.add(DateComponent("day", dayData))
211
+ "MM" -> components.add(DateComponent("month", monthData))
212
+ "YYYY" -> components.add(DateComponent("year", yearData))
213
+ "HH" -> components.add(DateComponent("hour", hourData))
214
+ "mm" -> components.add(DateComponent("minute", minData))
215
+ }
216
+ }
217
+
218
+ if (isOnlyHour) {
219
+ components.add(DateComponent("timeMode", timeMode))
220
+ }
221
+
222
+ components
223
+ }
224
+
225
+ return dateComponents
226
+ }
@@ -0,0 +1,201 @@
1
+ package vn.momo.kits.components.dateTimePicker
2
+
3
+ import androidx.compose.animation.core.tween
4
+ import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.border
6
+ import androidx.compose.foundation.gestures.Orientation
7
+ import androidx.compose.foundation.gestures.animateScrollBy
8
+ import androidx.compose.foundation.gestures.draggable
9
+ import androidx.compose.foundation.gestures.rememberDraggableState
10
+ import androidx.compose.foundation.gestures.scrollBy
11
+ import androidx.compose.foundation.layout.Box
12
+ import androidx.compose.foundation.layout.fillMaxWidth
13
+ import androidx.compose.foundation.layout.height
14
+ import androidx.compose.foundation.lazy.LazyColumn
15
+ import androidx.compose.foundation.lazy.rememberLazyListState
16
+ import androidx.compose.foundation.shape.RoundedCornerShape
17
+ import androidx.compose.runtime.Composable
18
+ import androidx.compose.runtime.LaunchedEffect
19
+ import androidx.compose.runtime.derivedStateOf
20
+ import androidx.compose.runtime.getValue
21
+ import androidx.compose.runtime.remember
22
+ import androidx.compose.runtime.rememberCoroutineScope
23
+ import androidx.compose.ui.Alignment
24
+ import androidx.compose.ui.Modifier
25
+ import androidx.compose.ui.draw.alpha
26
+ import androidx.compose.ui.draw.scale
27
+ import androidx.compose.ui.platform.LocalDensity
28
+ import androidx.compose.ui.unit.Dp
29
+ import androidx.compose.ui.unit.dp
30
+ import androidx.compose.ui.zIndex
31
+ import kotlinx.coroutines.CoroutineScope
32
+ import kotlinx.coroutines.launch
33
+ import vn.momo.kits.components.Text
34
+ import vn.momo.kits.const.AppTheme
35
+ import vn.momo.kits.const.Colors
36
+ import vn.momo.kits.const.Radius
37
+ import vn.momo.kits.const.Typography
38
+ import kotlin.math.abs
39
+ import kotlin.math.roundToInt
40
+
41
+ private val wheelItemHeight = 42.dp
42
+ private val wheelPickerBorderWidth = 1.dp
43
+
44
+ private fun onDragStopped(
45
+ listState: androidx.compose.foundation.lazy.LazyListState,
46
+ itemHeight: Float,
47
+ coroutineScope: CoroutineScope
48
+ ) {
49
+
50
+ coroutineScope.launch {
51
+ val targetPosition = listState.firstVisibleItemScrollOffset / itemHeight
52
+ val targetOffset = if (targetPosition.roundToInt() == targetPosition.toInt()) {
53
+ 0f
54
+ } else {
55
+ if (targetPosition - targetPosition.toInt() > 0.5f) {
56
+ (1 - (targetPosition - targetPosition.toInt())) * itemHeight
57
+ } else {
58
+ -(targetPosition - targetPosition.toInt()) * itemHeight
59
+ }
60
+ }
61
+
62
+ listState.animateScrollBy(targetOffset, tween(150))
63
+ }
64
+ }
65
+
66
+ @Composable
67
+ fun WheelPicker(
68
+ name: String,
69
+ data: List<String>,
70
+ selectedData: String,
71
+ onChange: (String, String) -> Unit,
72
+ modifier: Modifier = Modifier
73
+ ) {
74
+ val coroutineScope = rememberCoroutineScope()
75
+ val listState = rememberLazyListState()
76
+ val itemHeightPx = with(LocalDensity.current) { wheelItemHeight.toPx() }
77
+
78
+ val paddedData = remember(data) {
79
+ listOf("", "") + data + listOf("", "")
80
+ }
81
+
82
+ val initialIndex = remember(selectedData, paddedData) {
83
+ paddedData.indexOf(selectedData).coerceAtLeast(2)
84
+ }
85
+
86
+ LaunchedEffect(initialIndex) {
87
+ listState.scrollToItem(initialIndex - 2)
88
+ }
89
+
90
+ val selectedIndex by remember {
91
+ derivedStateOf {
92
+ (listState.firstVisibleItemIndex + 2).coerceIn(2, paddedData.size - 3)
93
+ }
94
+ }
95
+
96
+ LaunchedEffect(listState.isScrollInProgress) {
97
+ if (!listState.isScrollInProgress) {
98
+ val centeredIndex = selectedIndex
99
+ if (centeredIndex in 2 until paddedData.size - 2) {
100
+ onChange(name, paddedData[centeredIndex])
101
+ }
102
+ }
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
+ .draggable(
121
+ orientation = Orientation.Vertical,
122
+ state = rememberDraggableState { delta ->
123
+ coroutineScope.launch {
124
+ listState.scrollBy(-delta)
125
+ }
126
+ },
127
+ onDragStopped = {
128
+ onDragStopped(
129
+ listState = listState,
130
+ itemHeight = itemHeightPx,
131
+ coroutineScope = coroutineScope
132
+ )
133
+ }
134
+ )
135
+ ) {
136
+ items(paddedData.size) { index ->
137
+ WheelPickerItem(
138
+ text = paddedData[index],
139
+ isSelected = index == selectedIndex,
140
+ index = index,
141
+ listState = listState,
142
+ itemHeight = wheelItemHeight
143
+ )
144
+ }
145
+ }
146
+
147
+ Box(
148
+ modifier = Modifier
149
+ .fillMaxWidth()
150
+ .height(wheelItemHeight)
151
+ .background(Colors.blue_10)
152
+ .align(Alignment.Center)
153
+ .alpha(0.2f)
154
+ .zIndex(-2f)
155
+ )
156
+ }
157
+ }
158
+
159
+ @Composable
160
+ fun WheelPickerItem(
161
+ text: String,
162
+ isSelected: Boolean,
163
+ index: Int,
164
+ listState: androidx.compose.foundation.lazy.LazyListState,
165
+ itemHeight: Dp
166
+ ) {
167
+ val firstVisibleIndex = listState.firstVisibleItemIndex
168
+ val visibleItemOffset = listState.firstVisibleItemScrollOffset
169
+
170
+ val viewportHeight = 5 * itemHeight.value
171
+ val itemHeightValue = itemHeight.value
172
+
173
+ val absoluteOffset =
174
+ (index - firstVisibleIndex) * itemHeightValue - (visibleItemOffset / itemHeightValue)
175
+ val relativePosition = absoluteOffset / viewportHeight
176
+
177
+ val distance = abs(2 - relativePosition)
178
+
179
+ val opacity = when {
180
+ distance <= 1 -> 1f
181
+ distance <= 2 -> 0.8f
182
+ distance <= 3 -> 0.4f
183
+ else -> 0.4f
184
+ }
185
+
186
+ val scale = if (isSelected) 1f else 0.87f
187
+
188
+ Box(
189
+ modifier = Modifier
190
+ .fillMaxWidth()
191
+ .height(itemHeight)
192
+ .alpha(opacity),
193
+ contentAlignment = Alignment.Center
194
+ ) {
195
+ Text(
196
+ text = text,
197
+ style = Typography.actionS,
198
+ modifier = Modifier.scale(scale)
199
+ )
200
+ }
201
+ }