@momo-kits/native-kits 0.163.1-beta.3 → 0.163.1-beta.7-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 +182 -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 +225 -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 +320 -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,214 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.clickable
6
+ import androidx.compose.foundation.interaction.MutableInteractionSource
7
+ import androidx.compose.foundation.layout.Box
8
+ import androidx.compose.foundation.layout.Column
9
+ import androidx.compose.foundation.layout.Row
10
+ import androidx.compose.foundation.layout.Spacer
11
+ import androidx.compose.foundation.layout.fillMaxWidth
12
+ import androidx.compose.foundation.layout.height
13
+ import androidx.compose.foundation.layout.offset
14
+ import androidx.compose.foundation.layout.padding
15
+ import androidx.compose.foundation.layout.width
16
+ import androidx.compose.foundation.layout.wrapContentSize
17
+ import androidx.compose.foundation.shape.RoundedCornerShape
18
+ import androidx.compose.foundation.text.BasicTextField
19
+ import androidx.compose.foundation.text.KeyboardOptions
20
+ import androidx.compose.runtime.Composable
21
+ import androidx.compose.runtime.MutableState
22
+ import androidx.compose.runtime.getValue
23
+ import androidx.compose.runtime.mutableStateOf
24
+ import androidx.compose.runtime.remember
25
+ import androidx.compose.runtime.setValue
26
+ import androidx.compose.ui.Alignment
27
+ import androidx.compose.ui.Modifier
28
+ import androidx.compose.ui.focus.onFocusChanged
29
+ import androidx.compose.ui.graphics.Color
30
+ import androidx.compose.ui.semantics.contentDescription
31
+ import androidx.compose.ui.semantics.semantics
32
+ import androidx.compose.ui.semantics.testTag
33
+ import androidx.compose.ui.text.AnnotatedString
34
+ import androidx.compose.ui.text.TextStyle
35
+ import androidx.compose.ui.text.input.KeyboardType
36
+ import androidx.compose.ui.text.input.OffsetMapping
37
+ import androidx.compose.ui.text.input.TransformedText
38
+ import androidx.compose.ui.text.input.VisualTransformation
39
+ import androidx.compose.ui.unit.dp
40
+ import androidx.compose.ui.unit.sp
41
+ import androidx.compose.ui.zIndex
42
+ import vn.momo.kits.const.AppTheme
43
+ import vn.momo.kits.const.Spacing
44
+ import vn.momo.kits.application.IsShowBaseLineDebug
45
+ import vn.momo.kits.const.Colors
46
+ import vn.momo.kits.const.Typography
47
+ import vn.momo.kits.modifier.conditional
48
+ import vn.momo.kits.utils.formatNumberToMoney
49
+
50
+ class CustomConverter : VisualTransformation {
51
+ override fun filter(text: AnnotatedString): TransformedText {
52
+ if (text.text.isEmpty()) {
53
+ return TransformedText(
54
+ AnnotatedString("0"),
55
+ object : OffsetMapping {
56
+ override fun originalToTransformed(offset: Int): Int = 0
57
+ override fun transformedToOriginal(offset: Int): Int = 0
58
+ }
59
+ )
60
+ }
61
+
62
+ if (text.text == "0") {
63
+ return TransformedText(AnnotatedString("0"), OffsetMapping.Identity)
64
+ }
65
+
66
+ val formattedText = formatNumberToMoney(text.text.toLong())
67
+
68
+ return TransformedText(
69
+ AnnotatedString(formattedText),
70
+ object : OffsetMapping {
71
+ override fun originalToTransformed(offset: Int): Int = formattedText.length
72
+ override fun transformedToOriginal(offset: Int): Int = text.length
73
+ }
74
+ )
75
+ }
76
+ }
77
+
78
+ @Composable
79
+ fun InputMoney(
80
+ text: MutableState<String> = remember { mutableStateOf("0") },
81
+ floatingValue: String = "",
82
+ floatingValueColor: Color = AppTheme.current.colors.text.hint,
83
+ floatingIcon: String = "",
84
+ floatingIconColor: Color = AppTheme.current.colors.text.default,
85
+ placeholder: String = "0đ",
86
+ size: InputSize = InputSize.SMALL,
87
+ onChangeText: (String) -> Unit = {},
88
+ error: String = "",
89
+ errorSpacing: Boolean = false,
90
+ disabled: Boolean = false,
91
+ icon: String = "",
92
+ iconColor: Color = AppTheme.current.colors.text.default,
93
+ onPressIcon: () -> Unit = {},
94
+ leadingIcon: String = "",
95
+ leadingIconColor: Color = AppTheme.current.colors.text.hint,
96
+ onFocus: () -> Unit = {},
97
+ onBlur: () -> Unit = {},
98
+ loading: Boolean = false,
99
+ required: Boolean = false,
100
+ fontWeight: InputFontWeight = InputFontWeight.BOLD,
101
+ keyboardType: KeyboardType = KeyboardType.Number,
102
+ ) {
103
+ var isFocused by remember { mutableStateOf(false) }
104
+ var isBlurred = false
105
+ val (textColor, placeholderColor, iconTintColor, floatingTitleColor, floatingIconTintColor) =
106
+ getInputColors(disabled, iconColor, floatingValueColor, floatingIconColor)
107
+
108
+ val testId = if (disabled) "input_${floatingValue}_disabled" else "input_$floatingValue"
109
+
110
+ Column(modifier = Modifier
111
+ .conditional(IsShowBaseLineDebug) {
112
+ border(1.dp, Colors.blue_03)
113
+ }
114
+ .semantics {
115
+ contentDescription = floatingValue; testTag = testId
116
+ }) {
117
+ BasicTextField(
118
+ enabled = !disabled,
119
+ singleLine = true,
120
+ value = text.value,
121
+ textStyle = TextStyle(
122
+ color = textColor,
123
+ fontSize = 20.sp,
124
+ lineHeight = 24.sp,
125
+ fontWeight = fontWeight.value
126
+ ),
127
+ visualTransformation = CustomConverter(),
128
+ keyboardOptions = KeyboardOptions.Default.copy(keyboardType = keyboardType),
129
+ modifier = Modifier.height(size.values.height).onFocusChanged {
130
+ isFocused = it.isFocused
131
+ if (it.isFocused) {
132
+ onFocus()
133
+ }
134
+ if (!it.isFocused && isBlurred) onBlur()
135
+ if (it.isFocused && !isBlurred) isBlurred = true
136
+ },
137
+ onValueChange = {
138
+ val numericValue = it.filter { char -> char.isDigit() }
139
+ onChangeText(numericValue)
140
+ },
141
+ decorationBox = { innerTextField ->
142
+ // Floating Icon
143
+ FloatingLabel(
144
+ floatingValue = floatingValue,
145
+ floatingIcon = floatingIcon,
146
+ titleColor = floatingTitleColor,
147
+ iconColor = floatingIconTintColor,
148
+ offsetY = -size.values.height / 2,
149
+ required = required,
150
+ )
151
+ //input box wrapper
152
+ Box(
153
+ modifier = Modifier.fillMaxWidth()
154
+ .border(
155
+ 1.dp,
156
+ getBorderColor(isFocused, error, disabled),
157
+ RoundedCornerShape(size.values.borderRadius)
158
+ ),
159
+ contentAlignment = Alignment.CenterStart
160
+ ) {
161
+ Row(
162
+ modifier = Modifier.padding(horizontal = Spacing.M),
163
+ verticalAlignment = Alignment.CenterVertically
164
+ ) {
165
+ //leading icon
166
+ if (leadingIcon.isNotEmpty()) {
167
+ Icon(
168
+ source = leadingIcon,
169
+ modifier = Modifier.padding(end = Spacing.XS),
170
+ size = if (size.name == InputSize.SMALL.name) 24.dp else 32.dp,
171
+ color = leadingIconColor
172
+ )
173
+ }
174
+ Box(Modifier.weight(9f).padding(start = 0.dp)) {
175
+ if (text.value.isEmpty()) {
176
+ Text(
177
+ text = placeholder,
178
+ style = TextStyle(
179
+ fontSize = 20.sp,
180
+ lineHeight = 24.sp,
181
+ fontWeight = fontWeight.value
182
+ ),
183
+ color = placeholderColor
184
+ )
185
+ } else {
186
+ innerTextField()
187
+ }
188
+ }
189
+ if (isFocused && text.value.isNotEmpty()) {
190
+ Row {
191
+ Spacer(Modifier.width(Spacing.XS))
192
+ Icon(
193
+ source = "24_navigation_close_circle_full",
194
+ size = 16.dp,
195
+ color = AppTheme.current.colors.text.hint,
196
+ modifier = Modifier.clickable(
197
+ onClick = {
198
+ text.value = ""
199
+ onChangeText.invoke("")
200
+ },
201
+ interactionSource = remember { MutableInteractionSource() },
202
+ indication = null
203
+ )
204
+ )
205
+ }
206
+ }
207
+ RenderRightIcon(loading, icon, iconTintColor, onPressIcon)
208
+ }
209
+ }
210
+ },
211
+ )
212
+ ErrorView(error, errorSpacing, "")
213
+ }
214
+ }
@@ -0,0 +1,240 @@
1
+ package vn.momo.kits.components
2
+
3
+ import vn.momo.kits.modifier.InternalApi
4
+
5
+ import androidx.compose.animation.core.LinearEasing
6
+ import androidx.compose.animation.core.RepeatMode
7
+ import androidx.compose.animation.core.animateFloat
8
+ import androidx.compose.animation.core.infiniteRepeatable
9
+ import androidx.compose.animation.core.rememberInfiniteTransition
10
+ import androidx.compose.animation.core.tween
11
+ import androidx.compose.foundation.background
12
+ import androidx.compose.foundation.border
13
+ import androidx.compose.ui.draw.alpha
14
+ import androidx.compose.foundation.clickable
15
+ import androidx.compose.foundation.layout.Arrangement
16
+ import androidx.compose.foundation.layout.Box
17
+ import androidx.compose.foundation.layout.Column
18
+ import androidx.compose.foundation.layout.Row
19
+ import androidx.compose.foundation.layout.Spacer
20
+ import androidx.compose.foundation.layout.fillMaxWidth
21
+ import androidx.compose.foundation.layout.height
22
+ import androidx.compose.foundation.layout.offset
23
+ import androidx.compose.foundation.layout.padding
24
+ import androidx.compose.foundation.layout.size
25
+ import androidx.compose.foundation.layout.width
26
+ import androidx.compose.foundation.layout.wrapContentSize
27
+ import androidx.compose.foundation.shape.RoundedCornerShape
28
+ import androidx.compose.foundation.text.BasicTextField
29
+ import androidx.compose.foundation.text.KeyboardOptions
30
+ import androidx.compose.runtime.Composable
31
+ import androidx.compose.runtime.getValue
32
+ import androidx.compose.runtime.mutableStateOf
33
+ import androidx.compose.runtime.remember
34
+ import androidx.compose.runtime.setValue
35
+ import androidx.compose.ui.Alignment
36
+ import androidx.compose.ui.Modifier
37
+ import androidx.compose.ui.focus.onFocusChanged
38
+ import androidx.compose.ui.text.TextStyle
39
+ import androidx.compose.ui.text.input.KeyboardType
40
+ import androidx.compose.ui.unit.dp
41
+ import androidx.compose.ui.unit.sp
42
+ import androidx.compose.ui.zIndex
43
+ import vn.momo.kits.const.AppTheme
44
+ import vn.momo.kits.const.Radius
45
+ import vn.momo.kits.const.Spacing
46
+ import vn.momo.kits.application.IsShowBaseLineDebug
47
+ import vn.momo.kits.const.Colors
48
+ import vn.momo.kits.const.Typography
49
+ import vn.momo.kits.const.scaleSize
50
+ import vn.momo.kits.modifier.conditional
51
+
52
+ @Composable
53
+ @InternalApi
54
+ fun OTPCaret() {
55
+ val duration = 500
56
+ val backgroundColor = AppTheme.current.colors.primary
57
+
58
+ val infiniteTransition = rememberInfiniteTransition()
59
+ val alpha by infiniteTransition.animateFloat(
60
+ initialValue = 1f,
61
+ targetValue = 0f,
62
+ animationSpec = infiniteRepeatable(
63
+ animation = tween(
64
+ durationMillis = duration,
65
+ delayMillis = duration,
66
+ easing = LinearEasing
67
+ ),
68
+ repeatMode = RepeatMode.Reverse
69
+ )
70
+ )
71
+
72
+ Row(
73
+ verticalAlignment = Alignment.CenterVertically
74
+ ) {
75
+ Box(
76
+ modifier = Modifier
77
+ .size(1.dp, scaleSize(12f).dp)
78
+ .background(backgroundColor.copy(alpha = alpha))
79
+ )
80
+ Text(
81
+ text = "-",
82
+ color = AppTheme.current.colors.text.hint,
83
+ style = Typography.descriptionDefaultRegular
84
+ )
85
+ }
86
+ }
87
+
88
+ @Composable
89
+ fun InputOTP(
90
+ value: String = "",
91
+ length: Int? = null,
92
+ errorMessage: String = "",
93
+ errorSpacing: Boolean = false,
94
+ floatingValue: String = "Label",
95
+ placeholder: String = "",
96
+ onChangeText: (String) -> Unit,
97
+ onFocus: () -> Unit = {},
98
+ onBlur: () -> Unit = {},
99
+ dataType: String = "number",
100
+ modifier: Modifier = Modifier
101
+ ) {
102
+ val maxLength = length ?: 10
103
+ var isFocused by remember { mutableStateOf(false) }
104
+ var isBlurred = false
105
+
106
+ val handleChangeText: (String) -> Unit = { text ->
107
+ if (text.length <= maxLength &&
108
+ (dataType != "number" || !text.any { !it.isDigit() }) &&
109
+ (text.length < value.length || value.length < text.length)
110
+ ) {
111
+ onChangeText(text)
112
+ }
113
+ }
114
+
115
+ fun onClearText(){
116
+ handleChangeText("")
117
+ }
118
+
119
+ val fontSize = scaleSize(20.sp)
120
+
121
+ Column(modifier = modifier.conditional(IsShowBaseLineDebug) {
122
+ border(1.dp, Colors.blue_03)
123
+ }) {
124
+ BasicTextField(
125
+ value = value,
126
+ textStyle = TextStyle(fontSize = fontSize),
127
+ onValueChange = handleChangeText,
128
+ singleLine = true,
129
+ keyboardOptions = KeyboardOptions.Default.copy(keyboardType = if (dataType == "number") KeyboardType.Number else KeyboardType.Ascii),
130
+ modifier = modifier.height(56.dp).onFocusChanged {
131
+ isFocused = it.isFocused
132
+ if (it.isFocused) {
133
+ onFocus()
134
+ }
135
+ if (!it.isFocused && isBlurred) onBlur()
136
+ if (it.isFocused && !isBlurred) isBlurred = true
137
+ },
138
+ decorationBox = { innerTextField ->
139
+ Box {
140
+ Box(
141
+ modifier = Modifier.fillMaxWidth().height(56.dp).alpha(0f)
142
+ ) { innerTextField() }
143
+ if (floatingValue.isNotEmpty()) {
144
+ Box(
145
+ modifier = Modifier.wrapContentSize()
146
+ .offset(y = ((-56).dp / 2))
147
+ .align(Alignment.Center)
148
+ .background(AppTheme.current.colors.background.surface)
149
+ .zIndex(10f),
150
+ ) {
151
+ Row(
152
+ modifier = Modifier
153
+ .padding(horizontal = Spacing.S),
154
+ verticalAlignment = Alignment.Bottom
155
+ ) {
156
+ Text(
157
+ floatingValue,
158
+ style = Typography.labelSMedium,
159
+ color = AppTheme.current.colors.text.hint
160
+ )
161
+ }
162
+ }
163
+ }
164
+ Box(
165
+ modifier = Modifier
166
+ .fillMaxWidth()
167
+ .height(56.dp)
168
+ .border(
169
+ 1.dp,
170
+ getBorderColor(isFocused, errorMessage, false),
171
+ RoundedCornerShape(
172
+ Radius.S
173
+ )
174
+ ), contentAlignment = Alignment.Center
175
+ ) {
176
+ Row(
177
+ modifier = Modifier.padding(vertical = 8.dp),
178
+ horizontalArrangement = Arrangement.SpaceBetween,
179
+ verticalAlignment = Alignment.CenterVertically
180
+ ) {
181
+ if (length != null) {
182
+ for (i in 0 until length) {
183
+ if (isFocused && value.length == i) {
184
+ OTPCaret()
185
+ } else {
186
+ val textColor =
187
+ if (value.getOrNull(i) != null) AppTheme.current.colors.text.default else AppTheme.current.colors.text.hint
188
+ val typo =
189
+ if (value.getOrNull(i) != null) Typography.headerDefaultBold else Typography.descriptionDefaultRegular
190
+ Text(
191
+ text = value.getOrNull(i)?.toString() ?: "-",
192
+ color = textColor,
193
+ style = typo
194
+ )
195
+ }
196
+ if (i != length - 1) Spacer(Modifier.width(Spacing.L))
197
+ }
198
+ } else {
199
+ if (value.isEmpty() && !isFocused && placeholder.isNotEmpty()) {
200
+ return@BasicTextField Text(
201
+ text = placeholder,
202
+ color = AppTheme.current.colors.text.hint
203
+ )
204
+ } else {
205
+ for (i in value.indices) {
206
+ Text(
207
+ style = Typography.headerDefaultBold,
208
+ text = value[i].toString()
209
+ )
210
+ if (i != value.length - 1 || (isFocused && value.length != MAX_LENGTH)) {
211
+ Spacer(Modifier.width(Spacing.L))
212
+ }
213
+ }
214
+ if (isFocused && value.length != MAX_LENGTH) OTPCaret()
215
+ }
216
+ }
217
+ }
218
+ }
219
+ Box(
220
+ modifier = Modifier.align(Alignment.Center).zIndex(10f)
221
+ ) {
222
+ Row(
223
+ horizontalArrangement = Arrangement.End,
224
+ modifier = Modifier.fillMaxWidth()
225
+ ) {
226
+ Icon(
227
+ "24_navigation_close_circle_full",
228
+ size = 12.dp,
229
+ modifier = Modifier.padding(end = 12.dp).clickable {
230
+ onClearText()
231
+ }
232
+ )
233
+ }
234
+ }
235
+ }
236
+ }
237
+ )
238
+ ErrorView(errorMessage, errorSpacing, "")
239
+ }
240
+ }
@@ -0,0 +1,216 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.clickable
6
+ import androidx.compose.foundation.interaction.MutableInteractionSource
7
+ import androidx.compose.foundation.layout.*
8
+ import androidx.compose.foundation.shape.RoundedCornerShape
9
+ import androidx.compose.foundation.text.BasicTextField
10
+ import androidx.compose.foundation.text.KeyboardOptions
11
+ import androidx.compose.runtime.*
12
+ import androidx.compose.ui.Alignment
13
+ import androidx.compose.ui.Modifier
14
+ import androidx.compose.ui.focus.onFocusChanged
15
+ import androidx.compose.ui.graphics.Color
16
+ import androidx.compose.ui.graphics.SolidColor
17
+ import androidx.compose.ui.layout.ContentScale
18
+ import androidx.compose.ui.text.TextStyle
19
+ import androidx.compose.ui.text.input.KeyboardType
20
+ import androidx.compose.ui.unit.Dp
21
+ import androidx.compose.ui.unit.dp
22
+ import vn.momo.kits.application.IsShowBaseLineDebug
23
+ import vn.momo.kits.const.*
24
+ import vn.momo.kits.modifier.conditional
25
+ import vn.momo.kits.modifier.setAutomationId
26
+
27
+ data class InputPhoneNumberSizeDetail(
28
+ val borderWidth: Dp,
29
+ val borderRadius: Dp,
30
+ val height: Dp,
31
+ val textStyle: TextStyle,
32
+ val dividerHeight: Dp,
33
+ )
34
+
35
+ enum class InputPhoneNumberSize(val values: InputPhoneNumberSizeDetail) {
36
+ SMALL(
37
+ InputPhoneNumberSizeDetail(
38
+ borderWidth = 1.dp,
39
+ borderRadius = Radius.S,
40
+ height = 48.dp,
41
+ textStyle = Typography.headerSSemibold,
42
+ dividerHeight = 24.dp
43
+ )
44
+ ),
45
+ LARGE(
46
+ InputPhoneNumberSizeDetail(
47
+ borderWidth = 1.dp,
48
+ borderRadius = Radius.S,
49
+ height = 56.dp,
50
+ textStyle = Typography.headerMBold,
51
+ dividerHeight = 32.dp
52
+ )
53
+ )
54
+ }
55
+
56
+ @Composable
57
+ private fun getBorderColor(isFocused: Boolean, error: String): Color {
58
+ val theme = AppTheme.current
59
+ return remember(isFocused, error, theme) {
60
+ when {
61
+ error.isNotEmpty() -> theme.colors.error.primary
62
+ isFocused -> theme.colors.primary
63
+ else -> theme.colors.border.default
64
+ }
65
+ }
66
+ }
67
+
68
+ @Composable
69
+ fun InputPhoneNumber(
70
+ text: MutableState<String> = remember { mutableStateOf("") },
71
+ placeholder: String = "0123456789",
72
+ size: InputPhoneNumberSize = InputPhoneNumberSize.SMALL,
73
+ onChangeText: (String) -> Unit = {},
74
+ hintText: String = "",
75
+ error: String = "",
76
+ errorSpacing: Boolean = false,
77
+ icon: String = "",
78
+ iconColor: Color = AppTheme.current.colors.text.default,
79
+ onRightIconPressed: () -> Unit = {},
80
+ onFocus: () -> Unit = {},
81
+ onBlur: () -> Unit = {},
82
+ loading: Boolean = false,
83
+ modifier: Modifier = Modifier,
84
+ inputModifier: Modifier = Modifier,
85
+ ) {
86
+ // Consolidated state management
87
+ var inputState by remember { mutableStateOf(InputState()) }
88
+
89
+ // Memoized color calculations
90
+ val theme = AppTheme.current
91
+ val colors = remember( theme) {
92
+ Triple(
93
+ theme.colors.text.default, // textColor
94
+ theme.colors.text.hint, // placeholderColor
95
+ iconColor // iconTintColor
96
+ )
97
+ }
98
+
99
+ val (textColor, placeholderColor, iconTintColor) = colors
100
+ val textStyle = scaleSize(size.values.textStyle.copy(color = textColor))
101
+
102
+
103
+ Column(modifier = modifier
104
+ .conditional(IsShowBaseLineDebug) {
105
+ border(1.dp, Colors.blue_03)
106
+ }) {
107
+ BasicTextField(
108
+ singleLine = true,
109
+ value = text.value,
110
+ textStyle = textStyle,
111
+ keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),
112
+ cursorBrush = SolidColor(AppTheme.current.colors.primary),
113
+ modifier = inputModifier
114
+ .height(scaleSize(size.values.height.value).dp)
115
+ .onFocusChanged { focusState ->
116
+ val wasFocused = inputState.isFocused
117
+ inputState = inputState.copy(
118
+ isFocused = focusState.isFocused,
119
+ hasBeenBlurred = inputState.hasBeenBlurred || wasFocused
120
+ )
121
+
122
+ if (focusState.isFocused) {
123
+ onFocus()
124
+ } else if (inputState.hasBeenBlurred) {
125
+ onBlur()
126
+ }
127
+ },
128
+ onValueChange = onChangeText,
129
+ decorationBox = { innerTextField ->
130
+ // Input container
131
+ Box(
132
+ modifier = Modifier
133
+ .fillMaxWidth()
134
+ .background(
135
+ color = AppTheme.current.colors.background.surface,
136
+ shape = RoundedCornerShape(size.values.borderRadius)
137
+ )
138
+ .border(
139
+ if(inputState.isFocused) 1.5.dp else 1.dp,
140
+ getBorderColor(inputState.isFocused, error),
141
+ RoundedCornerShape(size.values.borderRadius)
142
+ ),
143
+ contentAlignment = Alignment.CenterStart
144
+ ) {
145
+ Row(
146
+ modifier = Modifier.padding(horizontal = Spacing.M),
147
+ verticalAlignment = Alignment.CenterVertically
148
+ ) {
149
+ // Leading icon
150
+ Image(
151
+ source = "https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png",
152
+ modifier = Modifier.size(24.dp).padding(end = Spacing.XS),
153
+ options = Options(
154
+ contentScale = ContentScale.Fit,
155
+ alignment = Alignment.Center
156
+ )
157
+ )
158
+ Text(
159
+ "+84",
160
+ color = textColor,
161
+ style = size.values.textStyle.copy(color = textColor),
162
+ )
163
+
164
+ // Divider
165
+ Box(modifier = Modifier.padding(horizontal = Spacing.M)) {
166
+ Box(
167
+ modifier = Modifier.width(1.dp)
168
+ .height(size.values.dividerHeight)
169
+ .background(Colors.black_04)
170
+ )
171
+ }
172
+
173
+
174
+ Box(Modifier.weight(1f)) {
175
+ if (text.value.isEmpty()) {
176
+ Text(
177
+ text = placeholder,
178
+ style = size.values.textStyle.copy(color = placeholderColor),
179
+ color = placeholderColor,
180
+ modifier = Modifier.align(Alignment.CenterStart)
181
+ )
182
+ }
183
+ innerTextField()
184
+ }
185
+
186
+ // Clear button
187
+ if (inputState.isFocused && text.value.isNotEmpty()) {
188
+ Row {
189
+ Icon(
190
+ source = "24_navigation_close_circle_full",
191
+ size = 16.dp,
192
+ color = theme.colors.text.hint,
193
+ modifier = Modifier.clickable(
194
+ onClick = {
195
+ text.value = ""
196
+ onChangeText.invoke("")
197
+ },
198
+ interactionSource = remember { MutableInteractionSource() },
199
+ indication = null
200
+ )
201
+ .padding(horizontal = Spacing.S)
202
+ .setAutomationId("ic_clear")
203
+ )
204
+ }
205
+ }
206
+
207
+ // Right icon (password toggle or custom icon)
208
+ RenderRightIcon(loading, icon, iconTintColor, onRightIconPressed)
209
+ }
210
+ }
211
+ },
212
+ )
213
+ // Error/hint display
214
+ ErrorView(error, errorSpacing, hintText)
215
+ }
216
+ }