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

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.
@@ -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
+ }
@@ -75,183 +75,143 @@ fun getFontFamily(fontFamily: String, fontWeight: FontWeight? = FontWeight.Norma
75
75
 
76
76
  @Immutable
77
77
  class AppTypography internal constructor(
78
- val headlineDefault: TextStyle,
79
- val headlineS: TextStyle,
80
- val headlineL: TextStyle,
81
- val headlineXl: TextStyle,
82
- val titleDefault: TextStyle,
83
- val titleXs: TextStyle,
84
- val titleS: TextStyle,
85
- val headerDefault: TextStyle,
86
- val headerXs: TextStyle,
87
- val headerS: TextStyle,
88
- val paragraphDefault: TextStyle,
89
- val paragraphBold: TextStyle,
90
- val paragraphItalic: TextStyle,
91
- val descriptionDefault: TextStyle,
92
- val descriptionXs: TextStyle,
93
- val descriptionS: TextStyle,
94
- val labelDefault: TextStyle,
95
- val labelXxs: TextStyle,
96
- val labelXs: TextStyle,
97
- val labelS: TextStyle,
98
- val actionDefault: TextStyle,
99
- val actionXxs: TextStyle,
100
- val actionXs: TextStyle,
101
- val actionS: TextStyle,
78
+ val headlineDefaultBold: TextStyle,
79
+ val headerMBold: TextStyle,
80
+ val headerDefaultBold: TextStyle,
81
+ val headerSSemibold: TextStyle,
82
+ val headerXsSemibold: TextStyle,
83
+ val bodyDefaultRegular: TextStyle,
84
+ val bodyDefaultRegularStrikethrough: TextStyle,
85
+ val descriptionDefaultRegular: TextStyle,
86
+ val descriptionDefaultRegularStrikethrough: TextStyle,
87
+ val descriptionXsRegular: TextStyle,
88
+ val descriptionXsRegularStrikethrough: TextStyle,
89
+ val labelDefaultMedium: TextStyle,
90
+ val labelSMedium: TextStyle,
91
+ val labelXsMedium: TextStyle,
92
+ val actionDefaultBold: TextStyle,
93
+ val actionSBold: TextStyle,
94
+ val actionXsBold: TextStyle,
95
+ val actionXxsBold: TextStyle,
102
96
  ) {
103
97
  constructor(
104
98
  default: TextStyle = TextStyle(
105
- fontSize = 15.sp,
106
- lineHeight = 22.sp,
99
+ fontSize = 14.sp,
100
+ lineHeight = 20.sp,
107
101
  fontWeight = FontWeight.Normal
108
102
  ),
109
- headlineDefault: TextStyle = TextStyle(
110
- fontSize = 28.sp,
111
- lineHeight = 34.sp,
112
- fontWeight = FontWeight.SemiBold
113
- ),
114
- headlineS: TextStyle = TextStyle(
103
+ headlineDefaultBold: TextStyle = TextStyle(
115
104
  fontSize = 24.sp,
116
- lineHeight = 32.sp,
117
- fontWeight = FontWeight.SemiBold
118
- ),
119
- headlineL: TextStyle = TextStyle(
120
- fontSize = 32.sp,
121
- lineHeight = 36.sp,
122
- fontWeight = FontWeight.SemiBold
123
- ),
124
- headlineXl: TextStyle = TextStyle(
125
- fontSize = 36.sp,
126
- lineHeight = 44.sp,
127
- fontWeight = FontWeight.SemiBold
105
+ lineHeight = 34.sp,
106
+ fontWeight = FontWeight.Bold
128
107
  ),
129
- titleDefault: TextStyle = TextStyle(
130
- fontSize = 20.sp,
131
- lineHeight = 28.sp,
108
+ headerMBold: TextStyle = TextStyle(
109
+ fontSize = 18.sp,
110
+ lineHeight = 26.sp,
132
111
  fontWeight = FontWeight.Bold
133
112
  ),
134
- titleXs: TextStyle = TextStyle(
113
+ headerDefaultBold: TextStyle = TextStyle(
135
114
  fontSize = 16.sp,
136
115
  lineHeight = 22.sp,
137
116
  fontWeight = FontWeight.Bold
138
117
  ),
139
- titleS: TextStyle = TextStyle(
140
- fontSize = 18.sp,
141
- lineHeight = 28.sp,
142
- fontWeight = FontWeight.Bold
143
- ),
144
- headerDefault: TextStyle = TextStyle(
145
- fontSize = 15.sp,
146
- lineHeight = 22.sp,
118
+ headerSSemibold: TextStyle = TextStyle(
119
+ fontSize = 14.sp,
120
+ lineHeight = 20.sp,
147
121
  fontWeight = FontWeight.SemiBold
148
122
  ),
149
- headerXs: TextStyle = TextStyle(
123
+ headerXsSemibold: TextStyle = TextStyle(
150
124
  fontSize = 12.sp,
151
- lineHeight = 16.sp,
125
+ lineHeight = 18.sp,
152
126
  fontWeight = FontWeight.SemiBold
153
127
  ),
154
- headerS: TextStyle = TextStyle(
128
+ bodyDefaultRegular: TextStyle = TextStyle(
155
129
  fontSize = 14.sp,
156
130
  lineHeight = 20.sp,
157
- fontWeight = FontWeight.SemiBold
158
- ),
159
- paragraphDefault: TextStyle = TextStyle(
160
- fontSize = 15.sp,
161
- lineHeight = 22.sp,
162
131
  fontWeight = FontWeight.Normal
163
132
  ),
164
- paragraphBold: TextStyle = TextStyle(
165
- fontSize = 15.sp,
166
- lineHeight = 22.sp,
167
- fontWeight = FontWeight.Bold
168
- ),
169
- paragraphItalic: TextStyle = TextStyle(
170
- fontSize = 15.sp,
171
- lineHeight = 22.sp,
172
- fontWeight = FontWeight.Normal,
173
- fontStyle = FontStyle.Italic
174
- ),
175
- descriptionDefault: TextStyle = TextStyle(
133
+ bodyDefaultRegularStrikethrough: TextStyle = TextStyle(
176
134
  fontSize = 14.sp,
177
135
  lineHeight = 20.sp,
136
+ fontWeight = FontWeight.Normal,
137
+ textDecoration = TextDecoration.LineThrough
138
+ ),
139
+ descriptionDefaultRegular: TextStyle = TextStyle(
140
+ fontSize = 12.sp,
141
+ lineHeight = 18.sp,
178
142
  fontWeight = FontWeight.Normal
179
143
  ),
180
- descriptionXs: TextStyle = TextStyle(
144
+ descriptionDefaultRegularStrikethrough: TextStyle = TextStyle(
145
+ fontSize = 12.sp,
146
+ lineHeight = 18.sp,
147
+ fontWeight = FontWeight.Normal,
148
+ textDecoration = TextDecoration.LineThrough
149
+ ),
150
+ descriptionXsRegular: TextStyle = TextStyle(
181
151
  fontSize = 10.sp,
182
152
  lineHeight = 14.sp,
183
153
  fontWeight = FontWeight.Normal
184
154
  ),
185
- descriptionS: TextStyle = TextStyle(
186
- fontSize = 12.sp,
187
- lineHeight = 16.sp,
155
+ descriptionXsRegularStrikethrough: TextStyle = TextStyle(
156
+ fontSize = 10.sp,
157
+ lineHeight = 14.sp,
188
158
  fontWeight = FontWeight.Normal,
159
+ textDecoration = TextDecoration.LineThrough
189
160
  ),
190
- labelDefault: TextStyle = TextStyle(
161
+ labelDefaultMedium: TextStyle = TextStyle(
191
162
  fontSize = 14.sp,
192
163
  lineHeight = 20.sp,
193
164
  fontWeight = FontWeight.Medium
194
165
  ),
195
- labelXxs: TextStyle = TextStyle(
196
- fontSize = 8.sp,
197
- lineHeight = 12.sp,
166
+ labelSMedium: TextStyle = TextStyle(
167
+ fontSize = 12.sp,
168
+ lineHeight = 18.sp,
198
169
  fontWeight = FontWeight.Medium
199
170
  ),
200
- labelXs: TextStyle = TextStyle(
171
+ labelXsMedium: TextStyle = TextStyle(
201
172
  fontSize = 10.sp,
202
173
  lineHeight = 14.sp,
203
174
  fontWeight = FontWeight.Medium
204
175
  ),
205
- labelS: TextStyle = TextStyle(
206
- fontSize = 12.sp,
207
- lineHeight = 16.sp,
208
- fontWeight = FontWeight.Medium
209
- ),
210
- actionDefault: TextStyle = TextStyle(
176
+ actionDefaultBold: TextStyle = TextStyle(
211
177
  fontSize = 16.sp,
212
178
  lineHeight = 22.sp,
213
179
  fontWeight = FontWeight.Bold
214
180
  ),
215
- actionXxs: TextStyle = TextStyle(
216
- fontSize = 10.sp,
217
- lineHeight = 14.sp,
181
+ actionSBold: TextStyle = TextStyle(
182
+ fontSize = 14.sp,
183
+ lineHeight = 20.sp,
218
184
  fontWeight = FontWeight.Bold
219
185
  ),
220
- actionXs: TextStyle = TextStyle(
186
+ actionXsBold: TextStyle = TextStyle(
221
187
  fontSize = 12.sp,
222
- lineHeight = 16.sp,
188
+ lineHeight = 18.sp,
223
189
  fontWeight = FontWeight.Bold
224
190
  ),
225
- actionS: TextStyle = TextStyle(
226
- fontSize = 15.sp,
227
- lineHeight = 22.sp,
191
+ actionXxsBold: TextStyle = TextStyle(
192
+ fontSize = 10.sp,
193
+ lineHeight = 14.sp,
228
194
  fontWeight = FontWeight.Bold
229
195
  ),
230
196
  ) : this(
231
- headlineDefault = headlineDefault,
232
- headlineS = headlineS,
233
- headlineL = headlineL,
234
- headlineXl = headlineXl,
235
- titleDefault = titleDefault,
236
- titleXs = titleXs,
237
- titleS = titleS,
238
- headerDefault = headerDefault,
239
- headerXs = headerXs,
240
- headerS = headerS,
241
- paragraphDefault = paragraphDefault,
242
- paragraphBold = paragraphBold,
243
- paragraphItalic = paragraphItalic,
244
- descriptionDefault = descriptionDefault,
245
- descriptionXs = descriptionXs,
246
- descriptionS = descriptionS,
247
- labelDefault = labelDefault,
248
- labelXxs = labelXxs,
249
- labelXs = labelXs,
250
- labelS = labelS,
251
- actionDefault = actionDefault,
252
- actionXxs = actionXxs,
253
- actionXs = actionXs,
254
- actionS = actionS
197
+ headlineDefaultBold = headlineDefaultBold,
198
+ headerMBold = headerMBold,
199
+ headerDefaultBold = headerDefaultBold,
200
+ headerSSemibold = headerSSemibold,
201
+ headerXsSemibold = headerXsSemibold,
202
+ bodyDefaultRegular = bodyDefaultRegular,
203
+ bodyDefaultRegularStrikethrough = bodyDefaultRegularStrikethrough,
204
+ descriptionDefaultRegular = descriptionDefaultRegular,
205
+ descriptionDefaultRegularStrikethrough = descriptionDefaultRegularStrikethrough,
206
+ descriptionXsRegular = descriptionXsRegular,
207
+ descriptionXsRegularStrikethrough = descriptionXsRegularStrikethrough,
208
+ labelDefaultMedium = labelDefaultMedium,
209
+ labelSMedium = labelSMedium,
210
+ labelXsMedium = labelXsMedium,
211
+ actionDefaultBold = actionDefaultBold,
212
+ actionSBold = actionSBold,
213
+ actionXsBold = actionXsBold,
214
+ actionXxsBold = actionXxsBold
255
215
  )
256
216
  }
257
217
 
@@ -13,12 +13,12 @@ public class MiniAppContext {
13
13
  public var appName: Any? = nil
14
14
  public var appIcon: String = ""
15
15
  public var description: Any? = nil
16
- public var support: Any? = nil
17
- public var toolkitConfig: Any? = nil
18
- public var providerId: String = ""
19
- public var permissions: Any? = nil
20
-
21
- public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil, support: Any? = nil, toolkitConfig: Any? = nil, providerId: String, permissions: Any? = nil) {
16
+ public var support: [String: Any] = [:]
17
+ public var toolkitConfig: [String: Any] = [:]
18
+ public var providerId: String = "momo"
19
+ public var permissions: [[String: Any]] = []
20
+
21
+ public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil, support: [String: Any] = [:], toolkitConfig: [String: Any] = [:], providerId: String = "momo", permissions: [[String: Any]] = []) {
22
22
  self.appId = appId
23
23
  self.appCode = appCode
24
24
  self.appName = appName
@@ -31,12 +31,20 @@ public class MiniAppContext {
31
31
  }
32
32
  }
33
33
 
34
+ public class KitConfig {
35
+ public var trustBanner: TrustBannerData? = nil
36
+ public var headerBar: String? = nil
37
+ public var headerGradient: String? = nil
38
+ }
39
+
34
40
  public class ApplicationEnvironment: ObservableObject {
35
41
  let applicationContext: MiniAppContext?
36
- let composeApi: KitComposeApi
37
-
38
- public init(applicationContext: MiniAppContext?, composeApi: KitComposeApi) {
42
+ let composeApi: KitComposeApi?
43
+ let config: KitConfig?
44
+
45
+ public init(applicationContext: MiniAppContext? = nil, composeApi: KitComposeApi? = nil, config: KitConfig? = nil) {
39
46
  self.applicationContext = applicationContext
40
47
  self.composeApi = composeApi
48
+ self.config = config
41
49
  }
42
50
  }