@momo-kits/native-kits 0.169.13-beta.3 → 0.169.13-beta.3-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 (164) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +202 -0
  3. package/compose/compose.podspec +47 -0
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +647 -0
  12. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +1411 -0
  13. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +130 -0
  14. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +524 -0
  15. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +559 -0
  16. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +741 -0
  17. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +221 -0
  18. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +270 -0
  19. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +849 -0
  20. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +212 -0
  21. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +239 -0
  22. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +252 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +130 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +208 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -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 +194 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +315 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +206 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +421 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +750 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +242 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +398 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +400 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
  132. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +154 -0
  133. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +1038 -0
  134. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +848 -0
  135. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +47 -0
  136. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +39 -0
  137. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +463 -0
  138. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +1146 -0
  139. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +667 -0
  140. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +240 -0
  141. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +185 -0
  142. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +200 -0
  143. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  144. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  145. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  146. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -0
  147. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  148. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  149. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  150. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  151. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +65 -0
  152. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
  153. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  154. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +143 -0
  155. package/gradle/libs.versions.toml +69 -0
  156. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  157. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  158. package/gradle.properties +24 -0
  159. package/gradlew +252 -0
  160. package/gradlew.bat +94 -0
  161. package/ios-demo/README.md +120 -0
  162. package/package.json +1 -1
  163. package/scripts/sdui-visual/README.md +64 -0
  164. package/settings.gradle.kts +64 -0
@@ -0,0 +1,308 @@
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
+ }
@@ -0,0 +1,218 @@
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
+ }