@momo-kits/native-kits 0.157.7 → 0.157.8-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.
- package/build.gradle.kts +11 -0
- package/compose/build.gradle.kts +180 -0
- package/compose/build.gradle.kts.backup +180 -0
- package/compose/compose.podspec +54 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +117 -0
- package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
- package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +57 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +107 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +201 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +222 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +48 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +305 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +720 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +121 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +405 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +85 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +340 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +198 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +123 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +94 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +136 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +224 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +148 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +188 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +116 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +448 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +172 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +255 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +231 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +233 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +254 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +241 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +364 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +92 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +352 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +103 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +338 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +70 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +96 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +348 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +256 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +494 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +131 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +215 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +96 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +531 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +92 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +130 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +214 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +590 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +177 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +192 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +205 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +239 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +191 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +285 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +50 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +68 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +14 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +50 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +253 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +99 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +164 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +333 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +552 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +162 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +243 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +187 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +279 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +80 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +306 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +370 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +167 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +46 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +62 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +88 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +161 -0
- package/gradle/libs.versions.toml +57 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/gradle.properties +26 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- package/package.json +1 -1
- package/settings.gradle.kts +52 -0
|
@@ -0,0 +1,215 @@
|
|
|
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.Box
|
|
9
|
+
import androidx.compose.foundation.layout.Column
|
|
10
|
+
import androidx.compose.foundation.layout.Row
|
|
11
|
+
import androidx.compose.foundation.layout.fillMaxHeight
|
|
12
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
13
|
+
import androidx.compose.foundation.layout.height
|
|
14
|
+
import androidx.compose.foundation.layout.offset
|
|
15
|
+
import androidx.compose.foundation.layout.width
|
|
16
|
+
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
17
|
+
import androidx.compose.runtime.Composable
|
|
18
|
+
import androidx.compose.runtime.remember
|
|
19
|
+
import androidx.compose.runtime.rememberCoroutineScope
|
|
20
|
+
import androidx.compose.ui.Alignment
|
|
21
|
+
import androidx.compose.ui.Modifier
|
|
22
|
+
import androidx.compose.ui.draw.clip
|
|
23
|
+
import androidx.compose.ui.graphics.Color
|
|
24
|
+
import androidx.compose.ui.input.pointer.pointerInput
|
|
25
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
26
|
+
import androidx.compose.ui.unit.Dp
|
|
27
|
+
import androidx.compose.ui.unit.IntOffset
|
|
28
|
+
import androidx.compose.ui.unit.dp
|
|
29
|
+
import kotlinx.coroutines.launch
|
|
30
|
+
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
31
|
+
import vn.momo.kits.const.AppTheme
|
|
32
|
+
import vn.momo.kits.const.Colors
|
|
33
|
+
import vn.momo.kits.const.Radius
|
|
34
|
+
import vn.momo.kits.const.Spacing
|
|
35
|
+
import vn.momo.kits.const.Typography
|
|
36
|
+
import vn.momo.kits.modifier.activeOpacityClickable
|
|
37
|
+
import vn.momo.kits.modifier.conditional
|
|
38
|
+
import kotlin.math.roundToInt
|
|
39
|
+
|
|
40
|
+
data class SwipeAction(
|
|
41
|
+
val label: String = "",
|
|
42
|
+
val icon: String = "",
|
|
43
|
+
val onPress: () -> Unit = {},
|
|
44
|
+
val backgroundColor: Color? = null,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
private val ACTION_WIDTH = 56.dp
|
|
48
|
+
|
|
49
|
+
@Composable
|
|
50
|
+
fun Swipe(
|
|
51
|
+
modifier: Modifier = Modifier,
|
|
52
|
+
leftActions: List<SwipeAction> = emptyList(),
|
|
53
|
+
rightActions: List<SwipeAction> = emptyList(),
|
|
54
|
+
height: Dp = 56.dp,
|
|
55
|
+
itemRadius: Dp = 0.dp,
|
|
56
|
+
onSwipeableOpen: () -> Unit = {},
|
|
57
|
+
onSwipeableClose: () -> Unit = {},
|
|
58
|
+
onSwipeableLeftOpen: () -> Unit = {},
|
|
59
|
+
onSwipeableRightOpen: () -> Unit = {},
|
|
60
|
+
content: @Composable () -> Unit = {},
|
|
61
|
+
) {
|
|
62
|
+
val theme = AppTheme.current
|
|
63
|
+
val density = LocalDensity.current
|
|
64
|
+
val scope = rememberCoroutineScope()
|
|
65
|
+
|
|
66
|
+
val left = leftActions.take(3)
|
|
67
|
+
val right = rightActions.take(3)
|
|
68
|
+
|
|
69
|
+
val leftWidthPx = with(density) { (ACTION_WIDTH * left.size).toPx() }
|
|
70
|
+
val rightWidthPx = with(density) { (ACTION_WIDTH * right.size).toPx() }
|
|
71
|
+
|
|
72
|
+
val offsetX = remember { Animatable(0f) }
|
|
73
|
+
|
|
74
|
+
val shape = remember(itemRadius) {
|
|
75
|
+
if (itemRadius > 0.dp) RoundedCornerShape(itemRadius) else RoundedCornerShape(0.dp)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fun snapToClosest() {
|
|
79
|
+
scope.launch {
|
|
80
|
+
val current = offsetX.value
|
|
81
|
+
val target = when {
|
|
82
|
+
current > leftWidthPx * 0.5f && left.isNotEmpty() -> {
|
|
83
|
+
onSwipeableLeftOpen()
|
|
84
|
+
onSwipeableOpen()
|
|
85
|
+
leftWidthPx
|
|
86
|
+
}
|
|
87
|
+
current < -rightWidthPx * 0.5f && right.isNotEmpty() -> {
|
|
88
|
+
onSwipeableRightOpen()
|
|
89
|
+
onSwipeableOpen()
|
|
90
|
+
-rightWidthPx
|
|
91
|
+
}
|
|
92
|
+
else -> {
|
|
93
|
+
onSwipeableClose()
|
|
94
|
+
0f
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
offsetX.animateTo(target, tween(200))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fun close() {
|
|
102
|
+
scope.launch {
|
|
103
|
+
offsetX.animateTo(0f, tween(200))
|
|
104
|
+
onSwipeableClose()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
Box(
|
|
109
|
+
modifier = modifier
|
|
110
|
+
.fillMaxWidth()
|
|
111
|
+
.height(height)
|
|
112
|
+
.conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) }
|
|
113
|
+
) {
|
|
114
|
+
// Left actions
|
|
115
|
+
if (left.isNotEmpty()) {
|
|
116
|
+
Row(
|
|
117
|
+
modifier = Modifier
|
|
118
|
+
.align(Alignment.CenterStart)
|
|
119
|
+
.fillMaxHeight()
|
|
120
|
+
) {
|
|
121
|
+
left.forEach { action ->
|
|
122
|
+
SwipeActionButton(
|
|
123
|
+
action = action,
|
|
124
|
+
width = ACTION_WIDTH,
|
|
125
|
+
height = height,
|
|
126
|
+
shape = shape,
|
|
127
|
+
defaultColor = theme.colors.primary,
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Right actions
|
|
134
|
+
if (right.isNotEmpty()) {
|
|
135
|
+
Row(
|
|
136
|
+
modifier = Modifier
|
|
137
|
+
.align(Alignment.CenterEnd)
|
|
138
|
+
.fillMaxHeight()
|
|
139
|
+
) {
|
|
140
|
+
right.forEach { action ->
|
|
141
|
+
SwipeActionButton(
|
|
142
|
+
action = action,
|
|
143
|
+
width = ACTION_WIDTH,
|
|
144
|
+
height = height,
|
|
145
|
+
shape = shape,
|
|
146
|
+
defaultColor = theme.colors.error.primary,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Main content
|
|
153
|
+
Box(
|
|
154
|
+
modifier = Modifier
|
|
155
|
+
.fillMaxWidth()
|
|
156
|
+
.height(height)
|
|
157
|
+
.offset { IntOffset(offsetX.value.roundToInt(), 0) }
|
|
158
|
+
.clip(shape)
|
|
159
|
+
.background(theme.colors.background.surface)
|
|
160
|
+
.pointerInput(left.size, right.size) {
|
|
161
|
+
detectHorizontalDragGestures(
|
|
162
|
+
onDragEnd = { snapToClosest() },
|
|
163
|
+
onDragCancel = { snapToClosest() },
|
|
164
|
+
) { _, dragAmount ->
|
|
165
|
+
scope.launch {
|
|
166
|
+
val newOffset = offsetX.value + dragAmount
|
|
167
|
+
val clamped = newOffset.coerceIn(-rightWidthPx, leftWidthPx)
|
|
168
|
+
offsetX.snapTo(clamped)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
) {
|
|
173
|
+
content()
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@Composable
|
|
179
|
+
private fun SwipeActionButton(
|
|
180
|
+
action: SwipeAction,
|
|
181
|
+
width: Dp,
|
|
182
|
+
height: Dp,
|
|
183
|
+
shape: RoundedCornerShape,
|
|
184
|
+
defaultColor: Color,
|
|
185
|
+
) {
|
|
186
|
+
val bgColor = action.backgroundColor ?: defaultColor
|
|
187
|
+
|
|
188
|
+
Box(
|
|
189
|
+
modifier = Modifier
|
|
190
|
+
.width(width)
|
|
191
|
+
.height(height)
|
|
192
|
+
.clip(shape)
|
|
193
|
+
.background(bgColor)
|
|
194
|
+
.activeOpacityClickable(onClick = action.onPress),
|
|
195
|
+
contentAlignment = Alignment.Center,
|
|
196
|
+
) {
|
|
197
|
+
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
|
198
|
+
if (action.icon.isNotEmpty()) {
|
|
199
|
+
Icon(
|
|
200
|
+
source = action.icon,
|
|
201
|
+
size = 20.dp,
|
|
202
|
+
color = Colors.black_01,
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
if (action.label.isNotEmpty()) {
|
|
206
|
+
Text(
|
|
207
|
+
text = action.label,
|
|
208
|
+
style = Typography.labelSMedium,
|
|
209
|
+
color = Colors.black_01,
|
|
210
|
+
maxLines = 1,
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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.Box
|
|
7
|
+
import androidx.compose.foundation.layout.height
|
|
8
|
+
import androidx.compose.foundation.layout.padding
|
|
9
|
+
import androidx.compose.foundation.layout.size
|
|
10
|
+
import androidx.compose.foundation.layout.width
|
|
11
|
+
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
12
|
+
import androidx.compose.runtime.Composable
|
|
13
|
+
import androidx.compose.runtime.remember
|
|
14
|
+
import androidx.compose.ui.Alignment
|
|
15
|
+
import androidx.compose.ui.Modifier
|
|
16
|
+
import androidx.compose.ui.draw.clip
|
|
17
|
+
import androidx.compose.ui.graphics.Color
|
|
18
|
+
import androidx.compose.ui.unit.dp
|
|
19
|
+
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
20
|
+
import vn.momo.kits.const.Colors
|
|
21
|
+
import vn.momo.kits.const.Spacing
|
|
22
|
+
import vn.momo.kits.modifier.conditional
|
|
23
|
+
import vn.momo.kits.modifier.setAutomationId
|
|
24
|
+
|
|
25
|
+
// Pre-computed shapes to avoid repeated creation
|
|
26
|
+
private val switchShape = RoundedCornerShape(20.dp)
|
|
27
|
+
private val circleShape = RoundedCornerShape(percent = 100)
|
|
28
|
+
|
|
29
|
+
@Composable
|
|
30
|
+
fun Switch(
|
|
31
|
+
value: Boolean = false,
|
|
32
|
+
onChange: (Boolean) -> Unit = {},
|
|
33
|
+
disabled: Boolean = false,
|
|
34
|
+
title: String? = "",
|
|
35
|
+
accessibilityId: String? = ""
|
|
36
|
+
) {
|
|
37
|
+
// Memoize color calculations to avoid repeated conditional logic
|
|
38
|
+
val colors = remember(value, disabled) {
|
|
39
|
+
val circleColor = if (value) Colors.black_01 else Colors.black_03
|
|
40
|
+
val bgColor = when {
|
|
41
|
+
disabled && value -> Colors.green_09
|
|
42
|
+
disabled && !value -> Colors.black_05
|
|
43
|
+
value -> Colors.green_03
|
|
44
|
+
else -> Colors.black_07
|
|
45
|
+
}
|
|
46
|
+
circleColor to bgColor
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
val (circleBackgroundColor, backgroundColor) = colors
|
|
50
|
+
|
|
51
|
+
// Memoize automation ID to avoid string concatenation on every render
|
|
52
|
+
val automationIdValue = remember(accessibilityId, title, value) {
|
|
53
|
+
accessibilityId ?: "toggle_${title ?: "unknown"}_$value"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Memoize alignment calculation
|
|
57
|
+
val contentAlignment = remember(value) {
|
|
58
|
+
if (value) Alignment.CenterEnd else Alignment.CenterStart
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Memoize click handler to avoid lambda recreation
|
|
62
|
+
val onClickHandler = remember(onChange, value) {
|
|
63
|
+
{ onChange(!value) }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Box(modifier = Modifier.setAutomationId(automationIdValue)) {
|
|
67
|
+
Box(
|
|
68
|
+
modifier = Modifier
|
|
69
|
+
.width(38.dp)
|
|
70
|
+
.height(20.dp)
|
|
71
|
+
.border(0.dp, Color.Unspecified, switchShape)
|
|
72
|
+
.background(backgroundColor, switchShape)
|
|
73
|
+
.conditional(IsShowBaseLineDebug) {
|
|
74
|
+
border(1.dp, Colors.blue_03)
|
|
75
|
+
}
|
|
76
|
+
.clip(switchShape)
|
|
77
|
+
.clickable(enabled = !disabled, onClick = onClickHandler)
|
|
78
|
+
.padding(horizontal = Spacing.XS),
|
|
79
|
+
contentAlignment = contentAlignment
|
|
80
|
+
) {
|
|
81
|
+
Box(
|
|
82
|
+
modifier = Modifier
|
|
83
|
+
.size(14.dp)
|
|
84
|
+
.border(0.dp, Color.Unspecified, circleShape)
|
|
85
|
+
.background(circleBackgroundColor, circleShape),
|
|
86
|
+
contentAlignment = Alignment.Center
|
|
87
|
+
) {
|
|
88
|
+
Box(
|
|
89
|
+
Modifier
|
|
90
|
+
.size(6.dp)
|
|
91
|
+
.background(backgroundColor, circleShape)
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|