@momo-kits/native-kits 0.300.8-beta.1-debug → 0.300.8-beta.1

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 (150) hide show
  1. package/package.json +1 -1
  2. package/build.gradle.kts +0 -13
  3. package/compose/build.gradle.kts +0 -195
  4. package/compose/build.gradle.kts.backup +0 -195
  5. package/compose/compose.podspec +0 -47
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -61
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsBinding.kt +0 -60
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsHost.kt +0 -32
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -268
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -55
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -354
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -130
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -137
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -262
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -237
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -280
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -342
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -362
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -304
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -308
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -218
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -456
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -175
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -208
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -291
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -71
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -315
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -54
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -118
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -212
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -422
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -750
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -152
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -244
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -398
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -103
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -93
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -208
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -133
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -446
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -387
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +0 -33
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -197
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -38
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -135
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -7
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -117
  130. package/compose/src/commonTest/kotlin/vn/momo/kits/application/KitsHostTest.kt +0 -44
  131. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +0 -39
  132. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -53
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
  134. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  135. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -31
  136. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  137. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -65
  138. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -217
  139. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  140. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -143
  141. package/gradle/libs.versions.toml +0 -66
  142. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  143. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  144. package/gradle.properties +0 -24
  145. package/gradlew +0 -252
  146. package/gradlew.bat +0 -94
  147. package/ios-demo/README.md +0 -120
  148. package/scripts/ci/build-swiftui.sh +0 -22
  149. package/scripts/ci/resolve-version.mjs +0 -144
  150. package/settings.gradle.kts +0 -63
@@ -1,308 +0,0 @@
1
- package vn.momo.kits.components
2
-
3
- import androidx.compose.animation.core.animateFloatAsState
4
- import androidx.compose.animation.core.spring
5
- import androidx.compose.foundation.background
6
- import androidx.compose.foundation.border
7
- import androidx.compose.foundation.layout.*
8
- import androidx.compose.foundation.shape.RoundedCornerShape
9
- import androidx.compose.runtime.*
10
- import androidx.compose.ui.Alignment
11
- import androidx.compose.ui.Modifier
12
- import androidx.compose.ui.draw.clip
13
- import androidx.compose.ui.input.pointer.pointerInput
14
- import androidx.compose.ui.layout.onGloballyPositioned
15
- import androidx.compose.ui.platform.LocalDensity
16
- import androidx.compose.ui.text.style.TextAlign
17
- import androidx.compose.ui.unit.IntOffset
18
- import androidx.compose.ui.unit.dp
19
- import vn.momo.kits.application.IsShowBaseLineDebug
20
- import vn.momo.kits.const.*
21
- import vn.momo.kits.modifier.conditional
22
- import kotlin.math.abs
23
- import kotlin.math.min
24
- import kotlin.math.roundToInt
25
-
26
- private val THUMB_SIZE = 20.dp
27
- private val THUMB_BORDER = 3.dp
28
- private val TRACK_HEIGHT = 4.dp
29
- private val LABEL_PAD_H = Spacing.XS
30
- private val LABEL_PAD_V = Spacing.XXS
31
- private val LABEL_GAP = Spacing.XS // space between label and thumb top
32
-
33
-
34
- private fun clamp(value: Float, min: Float, max: Float): Float = min(kotlin.math.max(value, min), max)
35
-
36
- private fun getValueForPosition(
37
- positionInView: Float,
38
- containerWidth: Float,
39
- thumbWidth: Float,
40
- min: Float,
41
- max: Float,
42
- step: Float,
43
- ): Float {
44
- val availableSpace = containerWidth - thumbWidth
45
- if (availableSpace <= 0f || max <= min) return min
46
- var relPosition = (positionInView - thumbWidth / 2f) / availableSpace
47
- // A zero step would make the snap math NaN, and NaN.roundToInt() throws.
48
- if (step <= 0f) return clamp(min + relPosition * (max - min), min, max)
49
- val relStepUnit = step / (max - min)
50
- val relOffset = relPosition % relStepUnit
51
- relPosition -= relOffset
52
- if (relOffset / relStepUnit >= 0.5f) relPosition += relStepUnit
53
- return clamp(min + (relPosition / relStepUnit).roundToInt() * step, min, max)
54
- }
55
-
56
- /** Direct port of RN isLowCloser(). */
57
- private fun isLowCloser(downX: Float, lowPosition: Float, highPosition: Float): Boolean {
58
- if (lowPosition == highPosition) return downX < lowPosition
59
- return abs(downX - lowPosition) < abs(downX - highPosition)
60
- }
61
-
62
- private fun valueToFraction(value: Float, min: Float, max: Float): Float {
63
- if (max == min) return 0f
64
- return clamp((value - min) / (max - min), 0f, 1f)
65
- }
66
-
67
- private fun formatLabel(value: Float): String {
68
- if (value == value.toLong().toFloat()) {
69
- return value.toLong().toString()
70
- }
71
- return ((value * 10).toLong() / 10.0).toString()
72
- }
73
-
74
- /**
75
- * Range slider ported from RN; [disableRange] keeps only the low thumb.
76
- * [low]/[high] only seed the thumbs (not controlled); [minRange] is the minimum gap between them.
77
- */
78
- @Composable
79
- fun Slider(
80
- min: Float,
81
- max: Float,
82
- step: Float,
83
- modifier: Modifier = Modifier,
84
- low: Float? = null,
85
- high: Float? = null,
86
- minRange: Float = 0f,
87
- disableRange: Boolean = false,
88
- floatingLabel: Boolean = false,
89
- disabled: Boolean = false,
90
- onValueChanged: (low: Float, high: Float, byUser: Boolean) -> Unit = { _, _, _ -> },
91
- onSliderTouchStart: (low: Float, high: Float) -> Unit = { _, _ -> },
92
- onSliderTouchEnd: (low: Float, high: Float) -> Unit = { _, _ -> },
93
- ) {
94
- val theme = AppTheme.current
95
- val density = LocalDensity.current
96
-
97
- val initLow = remember(low, min, max, step) {
98
- clamp(low ?: min, min, max)
99
- }
100
- val initHigh = remember(high, min, max, step, disableRange) {
101
- if (disableRange) max else clamp(high ?: max, min, max)
102
- }
103
-
104
- var lowValue by remember { mutableFloatStateOf(initLow) }
105
- var highValue by remember { mutableFloatStateOf(initHigh) }
106
-
107
- val lowFraction by animateFloatAsState(
108
- targetValue = valueToFraction(lowValue, min, max),
109
- animationSpec = spring(stiffness = 1200f),
110
- label = "lowFraction"
111
- )
112
- val highFraction by animateFloatAsState(
113
- targetValue = valueToFraction(highValue, min, max),
114
- animationSpec = spring(stiffness = 1200f),
115
- label = "highFraction"
116
- )
117
-
118
- var draggingLow by remember { mutableStateOf(true) }
119
- var isDragging by remember { mutableStateOf(false) }
120
-
121
- // pointerInput is not keyed on the callbacks, so read their latest values.
122
- val currentOnValueChanged by rememberUpdatedState(onValueChanged)
123
- val currentOnTouchStart by rememberUpdatedState(onSliderTouchStart)
124
- val currentOnTouchEnd by rememberUpdatedState(onSliderTouchEnd)
125
-
126
- val thumbColor = if (disabled) theme.colors.text.disable else theme.colors.primary
127
- val trackActiveColor = if (disabled) theme.colors.text.disable else theme.colors.primary
128
- val trackInactiveColor = theme.colors.background.default
129
-
130
- // trackWidthPx is the full pixel width of the BoxWithConstraints (incl. thumb padding)
131
- var trackWidthPx by remember { mutableFloatStateOf(0f) }
132
- val thumbSizePx = with(density) { THUMB_SIZE.toPx() }
133
-
134
- Box(
135
- modifier = modifier
136
- .fillMaxWidth()
137
- .conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) }
138
- ) {
139
- BoxWithConstraints(
140
- modifier = Modifier
141
- .fillMaxWidth()
142
- .onGloballyPositioned { coords -> trackWidthPx = coords.size.width.toFloat() }
143
- .pointerInput(disabled, min, max, step, minRange, disableRange) {
144
- if (disabled) return@pointerInput
145
-
146
- awaitPointerEventScope {
147
- while (true) {
148
- val downEvent = awaitPointerEvent()
149
- val downChange = downEvent.changes.firstOrNull() ?: continue
150
- val touchX = downChange.position.x
151
-
152
- // Pick the closer thumb
153
- val lowCenterX = thumbSizePx / 2f +
154
- valueToFraction(lowValue, min, max) * (trackWidthPx - thumbSizePx)
155
- val highCenterX = thumbSizePx / 2f +
156
- valueToFraction(highValue, min, max) * (trackWidthPx - thumbSizePx)
157
-
158
- draggingLow = disableRange || isLowCloser(touchX, lowCenterX, highCenterX)
159
- isDragging = true
160
- currentOnTouchStart(lowValue, highValue)
161
-
162
- applyDrag(touchX, trackWidthPx, thumbSizePx,
163
- min, max, step, minRange, draggingLow,
164
- lowValue, highValue) { nl, nh ->
165
- lowValue = nl
166
- highValue = nh
167
- currentOnValueChanged(nl, nh, true)
168
- }
169
-
170
- while (true) {
171
- val moveEvent = awaitPointerEvent()
172
- val moveChange = moveEvent.changes.firstOrNull() ?: break
173
- moveChange.consume()
174
-
175
- if (!moveChange.pressed) {
176
- isDragging = false
177
- currentOnTouchEnd(lowValue, highValue)
178
- break
179
- }
180
-
181
- applyDrag(moveChange.position.x, trackWidthPx, thumbSizePx,
182
- min, max, step, minRange, draggingLow,
183
- lowValue, highValue) { nl, nh ->
184
- lowValue = nl
185
- highValue = nh
186
- currentOnValueChanged(nl, nh, true)
187
- }
188
- }
189
- }
190
- }
191
- }
192
- ) {
193
- val trackWidth = maxWidth
194
- val availableWidth = trackWidth - THUMB_SIZE
195
-
196
- if (floatingLabel && isDragging) {
197
- val activeFraction = if (draggingLow) lowFraction else highFraction
198
- val activeValue = if (draggingLow) lowValue else highValue
199
- val labelOffsetDp = availableWidth * activeFraction
200
-
201
- Box(
202
- modifier = Modifier
203
- .align(Alignment.TopStart)
204
- .offset { IntOffset(x = with(density) { labelOffsetDp.toPx().roundToInt() }, y = 0) }
205
- ) {
206
- Box(
207
- modifier = Modifier
208
- .background(
209
- color = Colors.black_01,
210
- shape = RoundedCornerShape(Radius.XS)
211
- )
212
- .padding(horizontal = LABEL_PAD_H, vertical = LABEL_PAD_V)
213
- ) {
214
- Text(
215
- text = formatLabel(activeValue),
216
- style = Typography.descriptionXsRegular,
217
- color = theme.colors.text.default,
218
- textAlign = TextAlign.Center
219
- )
220
- }
221
- }
222
- }
223
-
224
- // Top padding pushes track + thumbs below the label when floatingLabel is on
225
- val topPad = if (floatingLabel) THUMB_SIZE + LABEL_GAP else 0.dp
226
-
227
- // Inactive track, full width
228
- Box(
229
- modifier = Modifier
230
- .align(Alignment.TopStart)
231
- .padding(top = topPad + (THUMB_SIZE - TRACK_HEIGHT) / 2)
232
- .padding(horizontal = THUMB_SIZE / 2)
233
- .fillMaxWidth()
234
- .height(TRACK_HEIGHT)
235
- .clip(RoundedCornerShape(percent = 50))
236
- .background(trackInactiveColor)
237
- )
238
-
239
- // Active track: the selected range, or up to the single thumb
240
- val activeStartFraction = if (disableRange) 0f else lowFraction
241
- val activeEndFraction = if (disableRange) lowFraction else highFraction
242
- val activeStartDp = THUMB_SIZE / 2 + availableWidth * activeStartFraction
243
- val activeWidthDp = availableWidth * (activeEndFraction - activeStartFraction)
244
-
245
- if (activeWidthDp > 0.dp) {
246
- Box(
247
- modifier = Modifier
248
- .align(Alignment.TopStart)
249
- .padding(top = topPad + (THUMB_SIZE - TRACK_HEIGHT) / 2)
250
- .offset(x = activeStartDp)
251
- .width(activeWidthDp)
252
- .height(TRACK_HEIGHT)
253
- .clip(RoundedCornerShape(percent = 50))
254
- .background(trackActiveColor)
255
- )
256
- }
257
-
258
- // Low thumb
259
- Box(
260
- modifier = Modifier
261
- .align(Alignment.TopStart)
262
- .padding(top = topPad)
263
- .offset(x = availableWidth * lowFraction)
264
- .size(THUMB_SIZE)
265
- .clip(RoundedCornerShape(percent = 100))
266
- .background(thumbColor)
267
- .border(THUMB_BORDER, theme.colors.background.surface, RoundedCornerShape(percent = 100))
268
- )
269
-
270
- // High thumb
271
- if (!disableRange) {
272
- Box(
273
- modifier = Modifier
274
- .align(Alignment.TopStart)
275
- .padding(top = topPad)
276
- .offset(x = availableWidth * highFraction)
277
- .size(THUMB_SIZE)
278
- .clip(RoundedCornerShape(percent = 100))
279
- .background(thumbColor)
280
- .border(THUMB_BORDER, theme.colors.background.surface, RoundedCornerShape(percent = 100))
281
- )
282
- }
283
- }
284
- }
285
- }
286
-
287
- private fun applyDrag(
288
- positionX: Float,
289
- trackWidthPx: Float,
290
- thumbSizePx: Float,
291
- min: Float,
292
- max: Float,
293
- step: Float,
294
- minRange: Float,
295
- isLow: Boolean,
296
- currentLow: Float,
297
- currentHigh: Float,
298
- onUpdate: (Float, Float) -> Unit,
299
- ) {
300
- val snapped = getValueForPosition(positionX, trackWidthPx, thumbSizePx, min, max, step)
301
- if (isLow) {
302
- val newLow = clamp(snapped, min, currentHigh - minRange)
303
- if (newLow != currentLow) onUpdate(newLow, currentHigh)
304
- } else {
305
- val newHigh = clamp(snapped, currentLow + minRange, max)
306
- if (newHigh != currentHigh) onUpdate(currentLow, newHigh)
307
- }
308
- }
@@ -1,218 +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.layout.*
6
- import androidx.compose.foundation.shape.CircleShape
7
- import androidx.compose.foundation.shape.RoundedCornerShape
8
- import androidx.compose.foundation.text.BasicTextField
9
- import androidx.compose.foundation.text.KeyboardOptions
10
- import androidx.compose.runtime.*
11
- import androidx.compose.ui.Alignment
12
- import androidx.compose.ui.Modifier
13
- import androidx.compose.ui.graphics.Color
14
- import androidx.compose.ui.text.TextStyle
15
- import androidx.compose.ui.text.font.FontWeight
16
- import androidx.compose.ui.text.input.KeyboardType
17
- import androidx.compose.ui.text.style.TextAlign
18
- import androidx.compose.ui.unit.Dp
19
- import androidx.compose.ui.unit.dp
20
- import androidx.compose.ui.unit.sp
21
- import vn.momo.kits.application.IsShowBaseLineDebug
22
- import vn.momo.kits.const.*
23
- import vn.momo.kits.const.getFontFamily
24
- import vn.momo.kits.modifier.activeOpacityClickable
25
- import vn.momo.kits.modifier.conditional
26
-
27
- enum class StepperSize {
28
- LARGE,
29
- SMALL
30
- }
31
-
32
- private data class StepperSizeSpec(
33
- val buttonSize: Dp,
34
- val iconSize: Dp,
35
- val numberMinWidth: Dp,
36
- val numberHeight: Dp,
37
- )
38
-
39
- private val stepperSizeSpecs: Map<StepperSize, StepperSizeSpec> = mapOf(
40
- StepperSize.LARGE to StepperSizeSpec(
41
- buttonSize = 36.dp,
42
- iconSize = 22.dp,
43
- numberMinWidth = 32.dp,
44
- numberHeight = 28.dp,
45
- ),
46
- StepperSize.SMALL to StepperSizeSpec(
47
- buttonSize = 28.dp,
48
- iconSize = 18.dp,
49
- numberMinWidth = 28.dp,
50
- numberHeight = 24.dp,
51
- ),
52
- )
53
-
54
- @Composable
55
- private fun StepperButton(
56
- sign: String = "+",
57
- size: StepperSize = StepperSize.LARGE,
58
- disabled: Boolean = false,
59
- onPress: () -> Unit = {},
60
- modifier: Modifier = Modifier,
61
- ) {
62
- val theme = AppTheme.current
63
- val specs = remember(size) { stepperSizeSpecs[size] ?: stepperSizeSpecs[StepperSize.LARGE]!! }
64
-
65
- val iconColor: Color = if (disabled) theme.colors.text.disable else theme.colors.primary
66
- val iconName: String = if (sign == "-") "24_navigation_minus_circle" else "24_navigation_plus_circle"
67
-
68
- val clickableModifier: Modifier = if (!disabled) {
69
- Modifier.activeOpacityClickable(onClick = onPress)
70
- } else {
71
- Modifier
72
- }
73
-
74
- Box(
75
- modifier = modifier
76
- .size(specs.buttonSize)
77
- .background(color = theme.colors.background.disable, shape = CircleShape)
78
- .then(clickableModifier)
79
- .conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) },
80
- contentAlignment = Alignment.Center,
81
- ) {
82
- Icon(
83
- source = iconName,
84
- size = specs.iconSize,
85
- color = iconColor,
86
- )
87
- }
88
- }
89
-
90
- @Composable
91
- private fun StepperNumberView(
92
- value: Int,
93
- size: StepperSize = StepperSize.LARGE,
94
- disabled: Boolean = false,
95
- editable: Boolean = false,
96
- onValueChange: (String) -> Unit = {},
97
- modifier: Modifier = Modifier,
98
- ) {
99
- val theme = AppTheme.current
100
- val specs = remember(size) { stepperSizeSpecs[size] ?: stepperSizeSpecs[StepperSize.LARGE]!! }
101
-
102
- val textColor: Color = if (disabled) theme.colors.text.disable else theme.colors.text.default
103
- val borderColor: Color = if (disabled) theme.colors.border.disable else theme.colors.border.default
104
-
105
- val scaledFontSize = scaleSize(12.sp)
106
-
107
- val textStyle = TextStyle(
108
- color = textColor,
109
- fontSize = scaledFontSize,
110
- textAlign = TextAlign.Center,
111
- fontFamily = getFontFamily(theme.font, FontWeight.Normal),
112
- )
113
-
114
- Box(
115
- modifier = modifier
116
- .defaultMinSize(minWidth = specs.numberMinWidth)
117
- .height(specs.numberHeight)
118
- .border(
119
- width = 1.dp,
120
- color = borderColor,
121
- shape = RoundedCornerShape(Radius.S),
122
- )
123
- .padding(horizontal = Spacing.XS)
124
- .conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) },
125
- contentAlignment = Alignment.Center,
126
- ) {
127
- BasicTextField(
128
- value = value.toString(),
129
- onValueChange = { if (editable) onValueChange(it) },
130
- enabled = editable && !disabled,
131
- readOnly = !editable,
132
- singleLine = true,
133
- textStyle = textStyle,
134
- keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
135
- decorationBox = { innerTextField -> innerTextField() },
136
- )
137
- }
138
- }
139
-
140
- @Composable
141
- fun Stepper(
142
- defaultValue: Int = 0,
143
- min: Int = 0,
144
- max: Int = 100,
145
- step: Int = 1,
146
- disabled: Any = false,
147
- size: StepperSize = StepperSize.LARGE,
148
- editable: Boolean = false,
149
- onValueChange: (Int) -> Unit = {},
150
- modifier: Modifier = Modifier,
151
- ) {
152
- var value by remember(defaultValue) { mutableStateOf(defaultValue.coerceIn(min, max)) }
153
-
154
- fun applyValue(raw: String) {
155
- var parsed = raw.toIntOrNull() ?: 0
156
- parsed = parsed.coerceIn(min, max)
157
- value = parsed
158
- onValueChange(parsed)
159
- }
160
-
161
- // Resolve per-part disabled state — mirrors RN getViewDisabledStatus()
162
- val disabledMinus: Boolean
163
- val disabledPlus: Boolean
164
- val disabledNumber: Boolean
165
-
166
- when (disabled) {
167
- is BooleanArray if disabled.size >= 2 -> {
168
- disabledMinus = disabled[0]
169
- disabledPlus = disabled[1]
170
- disabledNumber = disabled[0] && disabled[1]
171
- }
172
-
173
- is Boolean if disabled -> {
174
- disabledMinus = true
175
- disabledPlus = true
176
- disabledNumber = true
177
- }
178
-
179
- else -> {
180
- disabledMinus = false
181
- disabledPlus = false
182
- disabledNumber = false
183
- }
184
- }
185
-
186
- // Auto-disable buttons when the value is already at a bound
187
- val effectiveMinusDisabled = disabledMinus || value <= min
188
- val effectivePlusDisabled = disabledPlus || value >= max
189
-
190
- Row(
191
- modifier = modifier
192
- .conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) },
193
- verticalAlignment = Alignment.CenterVertically,
194
- ) {
195
- StepperButton(
196
- sign = "-",
197
- size = size,
198
- disabled = effectiveMinusDisabled,
199
- onPress = { applyValue((value - step).toString()) },
200
- )
201
-
202
- StepperNumberView(
203
- value = value,
204
- size = size,
205
- disabled = disabledNumber,
206
- editable = editable,
207
- onValueChange = { applyValue(it) },
208
- modifier = Modifier.padding(horizontal = Spacing.S),
209
- )
210
-
211
- StepperButton(
212
- sign = "+",
213
- size = size,
214
- disabled = effectivePlusDisabled,
215
- onPress = { applyValue((value + step).toString()) },
216
- )
217
- }
218
- }