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