@momo-kits/native-kits 0.169.8-beta.3-debug → 0.169.8-beta.4

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