@momo-kits/native-kits 0.300.4 → 0.300.5-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 (141) hide show
  1. package/build.gradle.kts +13 -0
  2. package/compose/build.gradle.kts +197 -0
  3. package/compose/build.gradle.kts.backup +197 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +153 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +65 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +361 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +306 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +338 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +137 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +116 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +215 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +404 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +732 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +40 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +233 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +217 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +377 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +103 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +413 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +37 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +41 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +135 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +74 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +20 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  122. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +44 -0
  123. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +62 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +34 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +138 -0
  131. package/gradle/libs.versions.toml +68 -0
  132. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  133. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  134. package/gradle.properties +26 -0
  135. package/gradlew +252 -0
  136. package/gradlew.bat +94 -0
  137. package/ios/native-kits.podspec +1 -1
  138. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  139. package/ios-demo/README.md +120 -0
  140. package/package.json +1 -1
  141. package/settings.gradle.kts +64 -0
@@ -0,0 +1,265 @@
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.graphics.SolidColor
31
+ import androidx.compose.ui.semantics.contentDescription
32
+ import androidx.compose.ui.semantics.semantics
33
+ import androidx.compose.ui.semantics.testTag
34
+ import androidx.compose.ui.text.TextRange
35
+ import androidx.compose.ui.text.TextStyle
36
+ import androidx.compose.ui.text.input.KeyboardType
37
+ import androidx.compose.ui.text.input.TextFieldValue
38
+ import androidx.compose.ui.unit.dp
39
+ import androidx.compose.ui.unit.sp
40
+ import androidx.compose.ui.zIndex
41
+ import vn.momo.kits.const.AppTheme
42
+ import vn.momo.kits.const.Spacing
43
+ import vn.momo.kits.application.IsShowBaseLineDebug
44
+ import vn.momo.kits.const.Colors
45
+ import vn.momo.kits.const.Typography
46
+ import vn.momo.kits.const.getFontFamily
47
+ import vn.momo.kits.const.scaleSize
48
+ import vn.momo.kits.modifier.conditional
49
+ import vn.momo.kits.modifier.setAutomationId
50
+
51
+ private const val MONEY_CURRENCY = "đ"
52
+
53
+ private data class MoneyEdit(val start: Int, val end: Int, val inserted: String)
54
+
55
+ private fun digitsOf(text: String) = text.filter { it in '0'..'9' }
56
+
57
+ private fun normalizeDigits(text: String) = digitsOf(text).let { digits ->
58
+ digits.trimStart('0').ifEmpty { digits.take(1) }
59
+ }
60
+
61
+ private fun moneyDisplay(digits: String) =
62
+ if (digits.isEmpty()) "" else digits.reversed().chunked(3).joinToString(".").reversed() + MONEY_CURRENCY
63
+
64
+ // Caret position right after the `digitIndex`-th digit of `display`.
65
+ private fun caretFromDigitIndex(display: String, digitIndex: Int): Int {
66
+ var count = 0
67
+ display.forEachIndexed { index, char ->
68
+ if (char in '0'..'9' && ++count == digitIndex) return index + 1
69
+ }
70
+ return 0
71
+ }
72
+
73
+ // Finds which range of `old` was replaced to produce `next`, given the post-edit caret.
74
+ private fun detectEdit(old: String, next: String, caret: Int): MoneyEdit {
75
+ val tail = next.length - caret
76
+ if (tail in 0..old.length && next.substring(caret) == old.substring(old.length - tail)) {
77
+ var prefix = 0
78
+ while (prefix < minOf(caret, old.length - tail) && old[prefix] == next[prefix]) prefix++
79
+ return MoneyEdit(prefix, old.length - tail, next.substring(prefix, caret))
80
+ }
81
+ var prefix = 0
82
+ while (prefix < minOf(old.length, next.length) && old[prefix] == next[prefix]) prefix++
83
+ var suffix = 0
84
+ while (suffix < minOf(old.length, next.length) - prefix &&
85
+ old[old.length - 1 - suffix] == next[next.length - 1 - suffix]
86
+ ) suffix++
87
+ return MoneyEdit(prefix, old.length - suffix, next.substring(prefix, next.length - suffix))
88
+ }
89
+
90
+ // Applies `edit` to the digits of `display`. Separators and currency are never
91
+ // deleted: removing a separator deletes the digit before it instead, removing
92
+ // only the currency leaves the digits untouched.
93
+ // Returns the new digits and the caret as a digit index.
94
+ private fun applyEdit(display: String, edit: MoneyEdit): Pair<String, Int> {
95
+ val digits = digitsOf(display)
96
+ var left = digitsOf(display.substring(0, edit.start)).length
97
+ var removed = digitsOf(display.substring(edit.start, edit.end)).length
98
+ val inserted = digitsOf(edit.inserted)
99
+ if (removed == 0 && inserted.isEmpty() && left > 0 && '.' in display.substring(edit.start, edit.end)) {
100
+ left -= 1
101
+ removed = 1
102
+ }
103
+ if (removed == 0 && inserted.isEmpty()) return digits to left
104
+ val next = digits.substring(0, left) + inserted + digits.substring(left + removed)
105
+ val trimmed = next.trimStart('0').ifEmpty { next.take(1) }
106
+ return trimmed to maxOf(0, left + inserted.length - (next.length - trimmed.length))
107
+ }
108
+
109
+ @Composable
110
+ fun InputMoney(
111
+ text: MutableState<String> = remember { mutableStateOf("0") },
112
+ floatingValue: String = "",
113
+ floatingValueColor: Color = AppTheme.current.colors.text.hint,
114
+ floatingIcon: String = "",
115
+ floatingIconColor: Color = AppTheme.current.colors.text.default,
116
+ placeholder: String = "0đ",
117
+ size: InputSize = InputSize.SMALL,
118
+ onChangeText: (String) -> Unit = {},
119
+ error: String = "",
120
+ errorSpacing: Boolean = false,
121
+ disabled: Boolean = false,
122
+ icon: String = "",
123
+ iconColor: Color = AppTheme.current.colors.text.default,
124
+ onPressIcon: () -> Unit = {},
125
+ leadingIcon: String = "",
126
+ leadingIconColor: Color = AppTheme.current.colors.text.hint,
127
+ onFocus: () -> Unit = {},
128
+ onBlur: () -> Unit = {},
129
+ loading: Boolean = false,
130
+ required: Boolean = false,
131
+ fontWeight: InputFontWeight = InputFontWeight.BOLD,
132
+ keyboardType: KeyboardType = KeyboardType.Number,
133
+ ) {
134
+ var isFocused by remember { mutableStateOf(false) }
135
+ var field by remember { mutableStateOf(TextFieldValue()) }
136
+ val digits = normalizeDigits(text.value)
137
+ val current = if (digitsOf(field.text) == digits) field else moneyDisplay(digits).let {
138
+ TextFieldValue(it, TextRange(caretFromDigitIndex(it, digits.length)))
139
+ }
140
+ val (textColor, placeholderColor, iconTintColor, floatingTitleColor, floatingIconTintColor) =
141
+ getInputColors(disabled, iconColor, floatingValueColor, floatingIconColor)
142
+
143
+ val testId = if (disabled) "input_${floatingValue}_disabled" else "input_$floatingValue"
144
+
145
+ Column(modifier = Modifier
146
+ .conditional(IsShowBaseLineDebug) {
147
+ border(1.dp, Colors.blue_03)
148
+ }
149
+ .semantics {
150
+ contentDescription = floatingValue; testTag = testId
151
+ }) {
152
+ BasicTextField(
153
+ enabled = !disabled,
154
+ singleLine = true,
155
+ value = current,
156
+ textStyle = TextStyle(
157
+ color = textColor,
158
+ fontSize = scaleSize(20.sp),
159
+ lineHeight = scaleSize(24.sp),
160
+ fontWeight = fontWeight.value,
161
+ fontFamily = getFontFamily(AppTheme.current.font, fontWeight.value)
162
+ ),
163
+ keyboardOptions = KeyboardOptions.Default.copy(keyboardType = keyboardType),
164
+ cursorBrush = SolidColor(AppTheme.current.colors.primary),
165
+ modifier = Modifier.height(size.values.height).onFocusChanged {
166
+ if (it.isFocused) onFocus() else if (isFocused) onBlur()
167
+ isFocused = it.isFocused
168
+ },
169
+ onValueChange = { value ->
170
+ if (value.text == current.text) {
171
+ // Keeps the caret out of the currency suffix.
172
+ val max = if (current.text.isEmpty()) 0 else current.text.length - MONEY_CURRENCY.length
173
+ field = value.copy(
174
+ selection = TextRange(
175
+ value.selection.start.coerceAtMost(max),
176
+ value.selection.end.coerceAtMost(max)
177
+ )
178
+ )
179
+ } else {
180
+ val (newDigits, caretDigit) = applyEdit(
181
+ current.text,
182
+ detectEdit(current.text, value.text, value.selection.min)
183
+ )
184
+ val display = moneyDisplay(newDigits)
185
+ field = TextFieldValue(display, TextRange(caretFromDigitIndex(display, caretDigit)))
186
+ if (newDigits != digits) {
187
+ text.value = newDigits
188
+ onChangeText(newDigits)
189
+ }
190
+ }
191
+ },
192
+ decorationBox = { innerTextField ->
193
+ // Floating Icon
194
+ FloatingLabel(
195
+ floatingValue = floatingValue,
196
+ floatingIcon = floatingIcon,
197
+ titleColor = floatingTitleColor,
198
+ iconColor = floatingIconTintColor,
199
+ offsetY = -size.values.height / 2,
200
+ required = required,
201
+ )
202
+ //input box wrapper
203
+ Box(
204
+ modifier = Modifier.fillMaxWidth()
205
+ .border(
206
+ 1.dp,
207
+ getBorderColor(isFocused, error, disabled),
208
+ RoundedCornerShape(size.values.borderRadius)
209
+ ),
210
+ contentAlignment = Alignment.CenterStart
211
+ ) {
212
+ Row(
213
+ modifier = Modifier.padding(horizontal = Spacing.M),
214
+ verticalAlignment = Alignment.CenterVertically
215
+ ) {
216
+ //leading icon
217
+ if (leadingIcon.isNotEmpty()) {
218
+ Icon(
219
+ source = leadingIcon,
220
+ modifier = Modifier.padding(end = Spacing.XS),
221
+ size = if (size.name == InputSize.SMALL.name) 24.dp else 32.dp,
222
+ color = leadingIconColor
223
+ )
224
+ }
225
+ Box(Modifier.weight(9f), contentAlignment = Alignment.CenterStart) {
226
+ if (text.value.isEmpty()) {
227
+ Text(
228
+ text = placeholder,
229
+ style = TextStyle(
230
+ fontSize = 20.sp,
231
+ lineHeight = 24.sp,
232
+ fontWeight = fontWeight.value
233
+ ),
234
+ color = placeholderColor
235
+ )
236
+ }
237
+ // Composed even when empty so the caret shows over the placeholder.
238
+ innerTextField()
239
+ }
240
+ if (isFocused && text.value.isNotEmpty()) {
241
+ Row {
242
+ Spacer(Modifier.width(Spacing.XS))
243
+ Icon(
244
+ source = "24_navigation_close_circle_full",
245
+ size = 16.dp,
246
+ color = AppTheme.current.colors.text.hint,
247
+ modifier = Modifier.clickable(
248
+ onClick = {
249
+ text.value = ""
250
+ onChangeText.invoke("")
251
+ },
252
+ interactionSource = remember { MutableInteractionSource() },
253
+ indication = null
254
+ ).setAutomationId("ic_clear")
255
+ )
256
+ }
257
+ }
258
+ RenderRightIcon(loading, icon, iconTintColor, onPressIcon)
259
+ }
260
+ }
261
+ },
262
+ )
263
+ ErrorView(error, errorSpacing, "")
264
+ }
265
+ }
@@ -0,0 +1,235 @@
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
+
105
+ val handleChangeText: (String) -> Unit = { text ->
106
+ if (text.length <= maxLength &&
107
+ (dataType != "number" || !text.any { !it.isDigit() }) &&
108
+ (text.length < value.length || value.length < text.length)
109
+ ) {
110
+ onChangeText(text)
111
+ }
112
+ }
113
+
114
+ fun onClearText(){
115
+ handleChangeText("")
116
+ }
117
+
118
+ val fontSize = scaleSize(20.sp)
119
+
120
+ Column(modifier = modifier.conditional(IsShowBaseLineDebug) {
121
+ border(1.dp, Colors.blue_03)
122
+ }) {
123
+ BasicTextField(
124
+ value = value,
125
+ textStyle = TextStyle(fontSize = fontSize),
126
+ onValueChange = handleChangeText,
127
+ singleLine = true,
128
+ keyboardOptions = KeyboardOptions.Default.copy(keyboardType = if (dataType == "number") KeyboardType.Number else KeyboardType.Ascii),
129
+ modifier = Modifier.height(56.dp).onFocusChanged {
130
+ if (it.isFocused) onFocus() else if (isFocused) onBlur()
131
+ isFocused = it.isFocused
132
+ },
133
+ decorationBox = { innerTextField ->
134
+ Box {
135
+ Box(
136
+ modifier = Modifier.fillMaxWidth().height(56.dp).alpha(0f)
137
+ ) { innerTextField() }
138
+ if (floatingValue.isNotEmpty()) {
139
+ Box(
140
+ modifier = Modifier.wrapContentSize()
141
+ .offset(y = ((-56).dp / 2))
142
+ .align(Alignment.Center)
143
+ .background(AppTheme.current.colors.background.surface)
144
+ .zIndex(10f),
145
+ ) {
146
+ Row(
147
+ modifier = Modifier
148
+ .padding(horizontal = Spacing.S),
149
+ verticalAlignment = Alignment.Bottom
150
+ ) {
151
+ Text(
152
+ floatingValue,
153
+ style = Typography.labelSMedium,
154
+ color = AppTheme.current.colors.text.hint
155
+ )
156
+ }
157
+ }
158
+ }
159
+ Box(
160
+ modifier = Modifier
161
+ .fillMaxWidth()
162
+ .height(56.dp)
163
+ .border(
164
+ 1.dp,
165
+ getBorderColor(isFocused, errorMessage, false),
166
+ RoundedCornerShape(
167
+ Radius.S
168
+ )
169
+ ), contentAlignment = Alignment.Center
170
+ ) {
171
+ Row(
172
+ modifier = Modifier.padding(vertical = 8.dp),
173
+ horizontalArrangement = Arrangement.SpaceBetween,
174
+ verticalAlignment = Alignment.CenterVertically
175
+ ) {
176
+ if (length != null) {
177
+ for (i in 0 until length) {
178
+ if (isFocused && value.length == i) {
179
+ OTPCaret()
180
+ } else {
181
+ val textColor =
182
+ if (value.getOrNull(i) != null) AppTheme.current.colors.text.default else AppTheme.current.colors.text.hint
183
+ val typo =
184
+ if (value.getOrNull(i) != null) Typography.headerDefaultBold else Typography.descriptionDefaultRegular
185
+ Text(
186
+ text = value.getOrNull(i)?.toString() ?: "-",
187
+ color = textColor,
188
+ style = typo
189
+ )
190
+ }
191
+ if (i != length - 1) Spacer(Modifier.width(Spacing.L))
192
+ }
193
+ } else {
194
+ if (value.isEmpty() && !isFocused && placeholder.isNotEmpty()) {
195
+ return@BasicTextField Text(
196
+ text = placeholder,
197
+ color = AppTheme.current.colors.text.hint
198
+ )
199
+ } else {
200
+ for (i in value.indices) {
201
+ Text(
202
+ style = Typography.headerDefaultBold,
203
+ text = value[i].toString()
204
+ )
205
+ if (i != value.length - 1 || (isFocused && value.length != maxLength)) {
206
+ Spacer(Modifier.width(Spacing.L))
207
+ }
208
+ }
209
+ if (isFocused && value.length != maxLength) OTPCaret()
210
+ }
211
+ }
212
+ }
213
+ }
214
+ Box(
215
+ modifier = Modifier.align(Alignment.Center).zIndex(10f)
216
+ ) {
217
+ Row(
218
+ horizontalArrangement = Arrangement.End,
219
+ modifier = Modifier.fillMaxWidth()
220
+ ) {
221
+ Icon(
222
+ "24_navigation_close_circle_full",
223
+ size = 12.dp,
224
+ modifier = Modifier.padding(end = 12.dp).clickable {
225
+ onClearText()
226
+ }
227
+ )
228
+ }
229
+ }
230
+ }
231
+ }
232
+ )
233
+ ErrorView(errorMessage, errorSpacing, "")
234
+ }
235
+ }