@momo-kits/native-kits 0.167.1-beta.9-debug → 0.167.1-duo-search.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 (189) hide show
  1. package/CLAUDE.md +36 -0
  2. package/ios/Application/ApplicationEnvironment.swift +6 -0
  3. package/ios/Application/Components.swift +1 -3
  4. package/ios/Application/HeaderRight.swift +32 -14
  5. package/ios/Application/Layout/ScreenLayout.swift +312 -0
  6. package/ios/Application/Navigation/BottomTab/BottomTab.swift +67 -10
  7. package/ios/Application/Navigation/BottomTab/BottomTabBar.swift +5 -2
  8. package/ios/Application/Navigation/BottomTab/DuoBarCompression.swift +105 -0
  9. package/ios/Application/Navigation/BottomTab/DuoTabBar.swift +304 -0
  10. package/ios/Application/Navigation/HeaderUser.swift +4 -4
  11. package/ios/Application/Navigation/NavigationContainer.swift +48 -42
  12. package/ios/Application/Navigation/Navigator.swift +122 -29
  13. package/ios/Application/Navigation/NavigatorManager.swift +13 -6
  14. package/ios/Application/Navigation/Overplay/BottomSheet.swift +41 -4
  15. package/ios/Application/Navigation/Overplay/ModalScreen.swift +7 -0
  16. package/ios/Application/Navigation/component/DuoScrollGradient.swift +54 -0
  17. package/ios/Application/Navigation/component/Header.swift +11 -6
  18. package/ios/Application/Navigation/component/HeaderBackground.swift +3 -2
  19. package/ios/Application/Navigation/component/NavigationFooter.swift +1 -1
  20. package/ios/Application/Navigation/component/NavigationHeaderRight.swift +93 -9
  21. package/ios/Application/Navigation/component/SideBar.swift +155 -0
  22. package/ios/Application/StackScreen.swift +175 -18
  23. package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +59 -5
  24. package/ios/Colors+Radius+Spacing/Colors.swift +1 -1
  25. package/ios/Extensions/Color++.swift +20 -9
  26. package/ios/Extensions/OptionalEnvironmentObject.swift +12 -0
  27. package/ios/Icon/Icon.swift +14 -22
  28. package/ios/Icon/Icons.swift +1329 -0
  29. package/ios/Image/Image.swift +16 -5
  30. package/ios/Lottie/LottieView.swift +4 -2
  31. package/ios/Popup/PopupDisplay.swift +84 -67
  32. package/ios/Popup/PopupLayout.swift +45 -0
  33. package/ios/Popup/PopupNotify.swift +44 -26
  34. package/ios/Popup/PopupPromotion.swift +18 -6
  35. package/ios/Resources/dot_loading.json +558 -0
  36. package/ios/Resources/lottie_circle_loader.json +1 -0
  37. package/ios/Template/TrustBanner/TrustBanner.swift +69 -31
  38. package/ios/Typography/FontScale.swift +3 -3
  39. package/ios/native-kits.podspec +1 -1
  40. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  41. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/DuoTabDemo.swift +80 -0
  42. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/Home.swift +2 -0
  43. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/IPhoneDuoDemo.swift +173 -0
  44. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupDisplayDemo.swift +1 -0
  45. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +2 -2
  46. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupPromotionDemo.swift +2 -0
  47. package/package.json +1 -1
  48. package/scripts/gen-ios-icons.mjs +36 -0
  49. package/build.gradle.kts +0 -11
  50. package/compose/build.gradle.kts +0 -190
  51. package/compose/build.gradle.kts.backup +0 -190
  52. package/compose/compose.podspec +0 -47
  53. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  54. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  55. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  56. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  57. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -151
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +0 -52
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -124
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +0 -183
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +0 -207
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +0 -39
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +0 -86
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +0 -76
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +0 -76
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +0 -293
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +0 -33
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -831
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -269
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +0 -110
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -378
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +0 -69
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -82
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -356
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -113
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -542
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -76
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -231
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -189
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -475
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -114
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -266
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -240
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -223
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -264
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -185
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -41
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -84
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -40
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -328
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -97
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -310
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -90
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -323
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -220
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -473
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -199
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -91
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -552
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -88
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -125
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -207
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -234
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -188
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -16
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -14
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  132. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  133. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -221
  134. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -270
  135. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -52
  136. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -38
  137. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -39
  138. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  139. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  140. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  141. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  142. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  143. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  144. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -299
  145. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  146. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -129
  147. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -106
  148. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -201
  149. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -393
  150. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  151. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -595
  152. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -148
  153. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  154. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -175
  155. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -225
  156. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  157. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -169
  158. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -358
  159. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -83
  160. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  161. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -75
  162. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -309
  163. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -40
  164. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -364
  165. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -132
  166. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  167. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  168. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -91
  169. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  170. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -71
  171. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  172. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  173. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  174. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -105
  175. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -40
  176. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  177. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  178. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  179. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  180. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -213
  181. package/gradle/libs.versions.toml +0 -69
  182. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  183. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  184. package/gradle.properties +0 -26
  185. package/gradlew +0 -252
  186. package/gradlew.bat +0 -94
  187. package/ios-demo/README.md +0 -120
  188. package/local.properties +0 -8
  189. package/settings.gradle.kts +0 -64
@@ -1,323 +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) return min
47
- val relStepUnit = step / (max - min)
48
- var relPosition = (positionInView - thumbWidth / 2f) / availableSpace
49
- val relOffset = relPosition % relStepUnit
50
- relPosition -= relOffset
51
- if (relOffset / relStepUnit >= 0.5f) relPosition += relStepUnit
52
- return clamp(min + (relPosition / relStepUnit).roundToInt() * step, min, max)
53
- }
54
-
55
- /** Direct port of RN isLowCloser(). */
56
- private fun isLowCloser(downX: Float, lowPosition: Float, highPosition: Float): Boolean {
57
- if (lowPosition == highPosition) return downX < lowPosition
58
- return abs(downX - lowPosition) < abs(downX - highPosition)
59
- }
60
-
61
- private fun valueToFraction(value: Float, min: Float, max: Float): Float {
62
- if (max == min) return 0f
63
- return clamp((value - min) / (max - min), 0f, 1f)
64
- }
65
-
66
- private fun formatLabel(value: Float): String =
67
- if (value == value.toLong().toFloat()) value.toLong().toString()
68
- else ((value * 10).toLong() / 10.0).toString()
69
-
70
- // ── Component ─────────────────────────────────────────────────────────────────
71
-
72
- /**
73
- * Range slider (or single-thumb when [disableRange] = true), migrated from React Native.
74
- *
75
- * @param min Minimum selectable value.
76
- * @param max Maximum selectable value.
77
- * @param step Snap increment between values.
78
- * @param modifier Modifier applied to the root container.
79
- * @param low Initial lower-thumb value (defaults to [min]).
80
- * @param high Initial upper-thumb value (defaults to [max]).
81
- * @param minRange Minimum required gap between low and high (default 0).
82
- * @param disableRange When true only the low thumb is shown (single-value mode).
83
- * @param floatingLabel When true a value label floats above the active thumb during drag.
84
- * @param disabled Non-interactive; rendered in the disabled colour.
85
- * @param onValueChanged Invoked with (low, high, byUser) on every value change.
86
- * @param onSliderTouchStart Invoked when a drag gesture begins.
87
- * @param onSliderTouchEnd Invoked when a drag gesture ends.
88
- */
89
- @Composable
90
- fun Slider(
91
- min: Float,
92
- max: Float,
93
- step: Float,
94
- modifier: Modifier = Modifier,
95
- low: Float? = null,
96
- high: Float? = null,
97
- minRange: Float = 0f,
98
- disableRange: Boolean = false,
99
- floatingLabel: Boolean = false,
100
- disabled: Boolean = false,
101
- onValueChanged: (low: Float, high: Float, byUser: Boolean) -> Unit = { _, _, _ -> },
102
- onSliderTouchStart: (low: Float, high: Float) -> Unit = { _, _ -> },
103
- onSliderTouchEnd: (low: Float, high: Float) -> Unit = { _, _ -> },
104
- ) {
105
- val theme = AppTheme.current
106
- val density = LocalDensity.current
107
-
108
- // Validated, step-snapped initial values
109
- val initLow = remember(low, min, max, step) {
110
- clamp(low ?: min, min, max)
111
- }
112
- val initHigh = remember(high, min, max, step, disableRange) {
113
- if (disableRange) max else clamp(high ?: max, min, max)
114
- }
115
-
116
- var lowValue by remember { mutableFloatStateOf(initLow) }
117
- var highValue by remember { mutableFloatStateOf(initHigh) }
118
-
119
- // Smoothly animated display fractions
120
- val lowFraction by animateFloatAsState(
121
- targetValue = valueToFraction(lowValue, min, max),
122
- animationSpec = spring(stiffness = 1200f),
123
- label = "lowFraction"
124
- )
125
- val highFraction by animateFloatAsState(
126
- targetValue = valueToFraction(highValue, min, max),
127
- animationSpec = spring(stiffness = 1200f),
128
- label = "highFraction"
129
- )
130
-
131
- var draggingLow by remember { mutableStateOf(true) }
132
- var isDragging by remember { mutableStateOf(false) }
133
-
134
- val thumbColor = if (disabled) theme.colors.text.disable else theme.colors.primary
135
- val trackActiveColor = if (disabled) theme.colors.text.disable else theme.colors.primary
136
- val trackInactiveColor = theme.colors.background.default
137
-
138
- // trackWidthPx is the full pixel width of the BoxWithConstraints (incl. thumb padding)
139
- var trackWidthPx by remember { mutableFloatStateOf(0f) }
140
- val thumbSizePx = with(density) { THUMB_SIZE.toPx() }
141
-
142
- Box(
143
- modifier = modifier
144
- .fillMaxWidth()
145
- .conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) }
146
- ) {
147
- BoxWithConstraints(
148
- modifier = Modifier
149
- .fillMaxWidth()
150
- .onGloballyPositioned { coords -> trackWidthPx = coords.size.width.toFloat() }
151
- // ── Gesture handling ──────────────────────────────────────────
152
- .pointerInput(disabled, min, max, step, minRange, disableRange) {
153
- if (disabled) return@pointerInput
154
-
155
- awaitPointerEventScope {
156
- while (true) {
157
- // Finger down
158
- val downEvent = awaitPointerEvent()
159
- val downChange = downEvent.changes.firstOrNull() ?: continue
160
- val touchX = downChange.position.x
161
-
162
- // Pick the closer thumb
163
- val lowCenterX = thumbSizePx / 2f +
164
- valueToFraction(lowValue, min, max) * (trackWidthPx - thumbSizePx)
165
- val highCenterX = thumbSizePx / 2f +
166
- valueToFraction(highValue, min, max) * (trackWidthPx - thumbSizePx)
167
-
168
- draggingLow = disableRange || isLowCloser(touchX, lowCenterX, highCenterX)
169
- isDragging = true
170
- onSliderTouchStart(lowValue, highValue)
171
-
172
- // Apply initial press
173
- applyDrag(touchX, trackWidthPx, thumbSizePx,
174
- min, max, step, minRange, draggingLow,
175
- lowValue, highValue) { nl, nh ->
176
- lowValue = nl
177
- highValue = nh
178
- onValueChanged(nl, nh, true)
179
- }
180
-
181
- // Track move / release
182
- while (true) {
183
- val moveEvent = awaitPointerEvent()
184
- val moveChange = moveEvent.changes.firstOrNull() ?: break
185
- moveChange.consume()
186
-
187
- if (!moveChange.pressed) {
188
- isDragging = false
189
- onSliderTouchEnd(lowValue, highValue)
190
- break
191
- }
192
-
193
- applyDrag(moveChange.position.x, trackWidthPx, thumbSizePx,
194
- min, max, step, minRange, draggingLow,
195
- lowValue, highValue) { nl, nh ->
196
- lowValue = nl
197
- highValue = nh
198
- onValueChanged(nl, nh, true)
199
- }
200
- }
201
- }
202
- }
203
- }
204
- ) {
205
- val trackWidth = maxWidth
206
- val availableWidth = trackWidth - THUMB_SIZE
207
-
208
- // ── Floating label ────────────────────────────────────────────────
209
- if (floatingLabel && isDragging) {
210
- val activeFraction = if (draggingLow) lowFraction else highFraction
211
- val activeValue = if (draggingLow) lowValue else highValue
212
- val labelOffsetDp = availableWidth * activeFraction
213
-
214
- Box(
215
- modifier = Modifier
216
- .align(Alignment.TopStart)
217
- .offset { IntOffset(x = with(density) { labelOffsetDp.toPx().roundToInt() }, y = 0) }
218
- ) {
219
- Box(
220
- modifier = Modifier
221
- .background(
222
- color = Colors.black_01,
223
- shape = RoundedCornerShape(Radius.XS)
224
- )
225
- .padding(horizontal = LABEL_PAD_H, vertical = LABEL_PAD_V)
226
- ) {
227
- Text(
228
- text = formatLabel(activeValue),
229
- style = Typography.descriptionXsRegular,
230
- color = theme.colors.text.default,
231
- textAlign = TextAlign.Center
232
- )
233
- }
234
- }
235
- }
236
-
237
- // Top padding pushes track + thumbs below the label when floatingLabel is on
238
- val topPad = if (floatingLabel) THUMB_SIZE + LABEL_GAP else 0.dp
239
-
240
- // ── Inactive track (full width) ───────────────────────────────────
241
- Box(
242
- modifier = Modifier
243
- .align(Alignment.TopStart)
244
- .padding(top = topPad + (THUMB_SIZE - TRACK_HEIGHT) / 2)
245
- .padding(horizontal = THUMB_SIZE / 2)
246
- .fillMaxWidth()
247
- .height(TRACK_HEIGHT)
248
- .clip(RoundedCornerShape(percent = 50))
249
- .background(trackInactiveColor)
250
- )
251
-
252
- // ── Active track (selected range / single value) ──────────────────
253
- val activeStartFraction = if (disableRange) 0f else lowFraction
254
- val activeEndFraction = if (disableRange) lowFraction else highFraction
255
- val activeStartDp = THUMB_SIZE / 2 + availableWidth * activeStartFraction
256
- val activeWidthDp = availableWidth * (activeEndFraction - activeStartFraction)
257
-
258
- if (activeWidthDp > 0.dp) {
259
- Box(
260
- modifier = Modifier
261
- .align(Alignment.TopStart)
262
- .padding(top = topPad + (THUMB_SIZE - TRACK_HEIGHT) / 2)
263
- .offset(x = activeStartDp)
264
- .width(activeWidthDp)
265
- .height(TRACK_HEIGHT)
266
- .clip(RoundedCornerShape(percent = 50))
267
- .background(trackActiveColor)
268
- )
269
- }
270
-
271
- // ── Low thumb ─────────────────────────────────────────────────────
272
- Box(
273
- modifier = Modifier
274
- .align(Alignment.TopStart)
275
- .padding(top = topPad)
276
- .offset(x = availableWidth * lowFraction)
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
- // ── High thumb (range mode only) ──────────────────────────────────
284
- if (!disableRange) {
285
- Box(
286
- modifier = Modifier
287
- .align(Alignment.TopStart)
288
- .padding(top = topPad)
289
- .offset(x = availableWidth * highFraction)
290
- .size(THUMB_SIZE)
291
- .clip(RoundedCornerShape(percent = 100))
292
- .background(thumbColor)
293
- .border(THUMB_BORDER, theme.colors.background.surface, RoundedCornerShape(percent = 100))
294
- )
295
- }
296
- }
297
- }
298
- }
299
-
300
- // ── Private drag helper ───────────────────────────────────────────────────────
301
-
302
- private fun applyDrag(
303
- positionX: Float,
304
- trackWidthPx: Float,
305
- thumbSizePx: Float,
306
- min: Float,
307
- max: Float,
308
- step: Float,
309
- minRange: Float,
310
- isLow: Boolean,
311
- currentLow: Float,
312
- currentHigh: Float,
313
- onUpdate: (Float, Float) -> Unit,
314
- ) {
315
- val snapped = getValueForPosition(positionX, trackWidthPx, thumbSizePx, min, max, step)
316
- if (isLow) {
317
- val newLow = clamp(snapped, min, currentHigh - minRange)
318
- if (newLow != currentLow) onUpdate(newLow, currentHigh)
319
- } else {
320
- val newHigh = clamp(snapped, currentLow + minRange, max)
321
- if (newHigh != currentHigh) onUpdate(currentLow, newHigh)
322
- }
323
- }
@@ -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
- }