@momo-kits/native-kits 0.300.4 → 0.300.5-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 (141) hide show
  1. package/build.gradle.kts +13 -0
  2. package/compose/build.gradle.kts +197 -0
  3. package/compose/build.gradle.kts.backup +197 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +153 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +65 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +361 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +306 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +338 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +137 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +116 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +215 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +404 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +732 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +40 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +233 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +217 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +377 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +103 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +413 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +37 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +41 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +135 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +74 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +20 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  122. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +44 -0
  123. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +62 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +34 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +138 -0
  131. package/gradle/libs.versions.toml +68 -0
  132. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  133. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  134. package/gradle.properties +26 -0
  135. package/gradlew +252 -0
  136. package/gradlew.bat +94 -0
  137. package/ios/native-kits.podspec +1 -1
  138. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  139. package/ios-demo/README.md +120 -0
  140. package/package.json +1 -1
  141. package/settings.gradle.kts +64 -0
@@ -0,0 +1,207 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.animation.core.Animatable
4
+ import androidx.compose.animation.core.tween
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.border
7
+ import androidx.compose.foundation.gestures.detectHorizontalDragGestures
8
+ import androidx.compose.foundation.layout.*
9
+ import androidx.compose.foundation.shape.RoundedCornerShape
10
+ import androidx.compose.runtime.Composable
11
+ import androidx.compose.runtime.getValue
12
+ import androidx.compose.runtime.remember
13
+ import androidx.compose.runtime.rememberCoroutineScope
14
+ import androidx.compose.runtime.rememberUpdatedState
15
+ import androidx.compose.ui.Alignment
16
+ import androidx.compose.ui.Modifier
17
+ import androidx.compose.ui.draw.clip
18
+ import androidx.compose.ui.graphics.Color
19
+ import androidx.compose.ui.input.pointer.pointerInput
20
+ import androidx.compose.ui.platform.LocalDensity
21
+ import androidx.compose.ui.unit.Dp
22
+ import androidx.compose.ui.unit.IntOffset
23
+ import androidx.compose.ui.unit.dp
24
+ import kotlinx.coroutines.launch
25
+ import vn.momo.kits.application.IsShowBaseLineDebug
26
+ import vn.momo.kits.const.AppTheme
27
+ import vn.momo.kits.const.Colors
28
+ import vn.momo.kits.const.Typography
29
+ import vn.momo.kits.modifier.activeOpacityClickable
30
+ import vn.momo.kits.modifier.conditional
31
+ import kotlin.math.roundToInt
32
+
33
+ data class SwipeAction(
34
+ val label: String = "",
35
+ val icon: String = "",
36
+ val onPress: () -> Unit = {},
37
+ val backgroundColor: Color? = null,
38
+ )
39
+
40
+ private val ACTION_WIDTH = 56.dp
41
+
42
+ @Composable
43
+ fun Swipe(
44
+ modifier: Modifier = Modifier,
45
+ leftActions: List<SwipeAction> = emptyList(),
46
+ rightActions: List<SwipeAction> = emptyList(),
47
+ height: Dp = 56.dp,
48
+ itemRadius: Dp = 0.dp,
49
+ onSwipeableOpen: () -> Unit = {},
50
+ onSwipeableClose: () -> Unit = {},
51
+ onSwipeableLeftOpen: () -> Unit = {},
52
+ onSwipeableRightOpen: () -> Unit = {},
53
+ content: @Composable () -> Unit = {},
54
+ ) {
55
+ val theme = AppTheme.current
56
+ val density = LocalDensity.current
57
+ val scope = rememberCoroutineScope()
58
+
59
+ val left = leftActions.take(3)
60
+ val right = rightActions.take(3)
61
+
62
+ val leftWidthPx = with(density) { (ACTION_WIDTH * left.size).toPx() }
63
+ val rightWidthPx = with(density) { (ACTION_WIDTH * right.size).toPx() }
64
+
65
+ val offsetX = remember { Animatable(0f) }
66
+
67
+ // pointerInput is keyed on the action counts only, so read the latest callbacks.
68
+ val currentOnOpen by rememberUpdatedState(onSwipeableOpen)
69
+ val currentOnClose by rememberUpdatedState(onSwipeableClose)
70
+ val currentOnLeftOpen by rememberUpdatedState(onSwipeableLeftOpen)
71
+ val currentOnRightOpen by rememberUpdatedState(onSwipeableRightOpen)
72
+
73
+ val shape = remember(itemRadius) {
74
+ if (itemRadius > 0.dp) RoundedCornerShape(itemRadius) else RoundedCornerShape(0.dp)
75
+ }
76
+
77
+ fun snapToClosest() {
78
+ scope.launch {
79
+ val current = offsetX.value
80
+ val target = when {
81
+ current > leftWidthPx * 0.5f && left.isNotEmpty() -> {
82
+ currentOnLeftOpen()
83
+ currentOnOpen()
84
+ leftWidthPx
85
+ }
86
+ current < -rightWidthPx * 0.5f && right.isNotEmpty() -> {
87
+ currentOnRightOpen()
88
+ currentOnOpen()
89
+ -rightWidthPx
90
+ }
91
+ else -> {
92
+ currentOnClose()
93
+ 0f
94
+ }
95
+ }
96
+ offsetX.animateTo(target, tween(200))
97
+ }
98
+ }
99
+
100
+ Box(
101
+ modifier = modifier
102
+ .fillMaxWidth()
103
+ .height(height)
104
+ .conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) }
105
+ ) {
106
+ // Left actions
107
+ if (left.isNotEmpty()) {
108
+ Row(
109
+ modifier = Modifier
110
+ .align(Alignment.CenterStart)
111
+ .fillMaxHeight()
112
+ ) {
113
+ left.forEach { action ->
114
+ SwipeActionButton(
115
+ action = action,
116
+ width = ACTION_WIDTH,
117
+ height = height,
118
+ shape = shape,
119
+ defaultColor = theme.colors.primary,
120
+ )
121
+ }
122
+ }
123
+ }
124
+
125
+ // Right actions
126
+ if (right.isNotEmpty()) {
127
+ Row(
128
+ modifier = Modifier
129
+ .align(Alignment.CenterEnd)
130
+ .fillMaxHeight()
131
+ ) {
132
+ right.forEach { action ->
133
+ SwipeActionButton(
134
+ action = action,
135
+ width = ACTION_WIDTH,
136
+ height = height,
137
+ shape = shape,
138
+ defaultColor = theme.colors.error.primary,
139
+ )
140
+ }
141
+ }
142
+ }
143
+
144
+ // Main content
145
+ Box(
146
+ modifier = Modifier
147
+ .fillMaxWidth()
148
+ .height(height)
149
+ .offset { IntOffset(offsetX.value.roundToInt(), 0) }
150
+ .clip(shape)
151
+ .background(theme.colors.background.surface)
152
+ .pointerInput(left.size, right.size) {
153
+ detectHorizontalDragGestures(
154
+ onDragEnd = { snapToClosest() },
155
+ onDragCancel = { snapToClosest() },
156
+ ) { _, dragAmount ->
157
+ scope.launch {
158
+ val newOffset = offsetX.value + dragAmount
159
+ val clamped = newOffset.coerceIn(-rightWidthPx, leftWidthPx)
160
+ offsetX.snapTo(clamped)
161
+ }
162
+ }
163
+ }
164
+ ) {
165
+ content()
166
+ }
167
+ }
168
+ }
169
+
170
+ @Composable
171
+ private fun SwipeActionButton(
172
+ action: SwipeAction,
173
+ width: Dp,
174
+ height: Dp,
175
+ shape: RoundedCornerShape,
176
+ defaultColor: Color,
177
+ ) {
178
+ val bgColor = action.backgroundColor ?: defaultColor
179
+
180
+ Box(
181
+ modifier = Modifier
182
+ .width(width)
183
+ .height(height)
184
+ .clip(shape)
185
+ .background(bgColor)
186
+ .activeOpacityClickable(onClick = action.onPress),
187
+ contentAlignment = Alignment.Center,
188
+ ) {
189
+ Column(horizontalAlignment = Alignment.CenterHorizontally) {
190
+ if (action.icon.isNotEmpty()) {
191
+ Icon(
192
+ source = action.icon,
193
+ size = 20.dp,
194
+ color = Colors.black_01,
195
+ )
196
+ }
197
+ if (action.label.isNotEmpty()) {
198
+ Text(
199
+ text = action.label,
200
+ style = Typography.labelSMedium,
201
+ color = Colors.black_01,
202
+ maxLines = 1,
203
+ )
204
+ }
205
+ }
206
+ }
207
+ }
@@ -0,0 +1,92 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.clickable
6
+ import androidx.compose.foundation.layout.*
7
+ import androidx.compose.foundation.shape.RoundedCornerShape
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.runtime.remember
10
+ import androidx.compose.ui.Alignment
11
+ import androidx.compose.ui.Modifier
12
+ import androidx.compose.ui.draw.clip
13
+ import androidx.compose.ui.graphics.Color
14
+ import androidx.compose.ui.unit.dp
15
+ import vn.momo.kits.application.IsShowBaseLineDebug
16
+ import vn.momo.kits.const.Colors
17
+ import vn.momo.kits.const.Spacing
18
+ import vn.momo.kits.modifier.conditional
19
+ import vn.momo.kits.modifier.setAutomationId
20
+
21
+ private val switchShape = RoundedCornerShape(20.dp)
22
+ private val circleShape = RoundedCornerShape(percent = 100)
23
+
24
+ @Composable
25
+ fun Switch(
26
+ value: Boolean = false,
27
+ onChange: (Boolean) -> Unit = {},
28
+ disabled: Boolean = false,
29
+ title: String? = "",
30
+ accessibilityId: String? = ""
31
+ ) {
32
+ // Memoize color calculations to avoid repeated conditional logic
33
+ val colors = remember(value, disabled) {
34
+ val circleColor = if (value) Colors.black_01 else Colors.black_03
35
+ val bgColor = when {
36
+ disabled && value -> Colors.green_09
37
+ disabled && !value -> Colors.black_05
38
+ value -> Colors.green_03
39
+ else -> Colors.black_07
40
+ }
41
+ circleColor to bgColor
42
+ }
43
+
44
+ val (circleBackgroundColor, backgroundColor) = colors
45
+
46
+ // Both params default to "", so blank must fall back too or the id is always empty.
47
+ val automationIdValue = remember(accessibilityId, title, value) {
48
+ accessibilityId?.takeIf { it.isNotEmpty() }
49
+ ?: "toggle_${title?.takeIf { it.isNotEmpty() } ?: "unknown"}_$value"
50
+ }
51
+
52
+ // Memoize alignment calculation
53
+ val contentAlignment = remember(value) {
54
+ if (value) Alignment.CenterEnd else Alignment.CenterStart
55
+ }
56
+
57
+ // Memoize click handler to avoid lambda recreation
58
+ val onClickHandler = remember(onChange, value) {
59
+ { onChange(!value) }
60
+ }
61
+
62
+ Box(modifier = Modifier.setAutomationId(automationIdValue)) {
63
+ Box(
64
+ modifier = Modifier
65
+ .width(38.dp)
66
+ .height(20.dp)
67
+ .border(0.dp, Color.Unspecified, switchShape)
68
+ .background(backgroundColor, switchShape)
69
+ .conditional(IsShowBaseLineDebug) {
70
+ border(1.dp, Colors.blue_03)
71
+ }
72
+ .clip(switchShape)
73
+ .clickable(enabled = !disabled, onClick = onClickHandler)
74
+ .padding(horizontal = Spacing.XS),
75
+ contentAlignment = contentAlignment
76
+ ) {
77
+ Box(
78
+ modifier = Modifier
79
+ .size(14.dp)
80
+ .border(0.dp, Color.Unspecified, circleShape)
81
+ .background(circleBackgroundColor, circleShape),
82
+ contentAlignment = Alignment.Center
83
+ ) {
84
+ Box(
85
+ Modifier
86
+ .size(6.dp)
87
+ .background(backgroundColor, circleShape)
88
+ )
89
+ }
90
+ }
91
+ }
92
+ }