@momo-kits/native-kits 0.169.13-beta.1-debug → 0.169.13-beta.2

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