@momo-kits/native-kits 0.169.12-beta.1 → 0.169.12-beta.2-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 (145) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +198 -0
  3. package/compose/compose.podspec +47 -0
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -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 +354 -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 +130 -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 +482 -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 +224 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -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 +40 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -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 +304 -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 +88 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -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 +205 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -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 +175 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -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 +208 -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 +12 -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 +291 -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/HeaderLayout.kt +67 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +315 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +206 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +421 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +750 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +242 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +406 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +400 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -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 +32 -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 +65 -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/ReduceMotion.ios.kt +48 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +143 -0
  132. package/gradle/libs.versions.toml +67 -0
  133. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  134. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  135. package/gradle.properties +24 -0
  136. package/gradlew +252 -0
  137. package/gradlew.bat +94 -0
  138. package/ios/Layout/HeaderLayout.swift +1 -6
  139. package/ios/Navigation/BottomTab/BottomTabBar.swift +14 -4
  140. package/ios/native-kits.podspec +1 -1
  141. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  142. package/ios-demo/README.md +120 -0
  143. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +16 -3
  144. package/package.json +1 -1
  145. package/settings.gradle.kts +64 -0
@@ -0,0 +1,542 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.animation.core.animateDpAsState
4
+ import androidx.compose.animation.core.tween
5
+ import androidx.compose.foundation.*
6
+ import androidx.compose.foundation.layout.*
7
+ import androidx.compose.foundation.pager.HorizontalPager
8
+ import androidx.compose.foundation.pager.rememberPagerState
9
+ import androidx.compose.foundation.shape.RoundedCornerShape
10
+ import androidx.compose.runtime.*
11
+ import androidx.compose.ui.Alignment
12
+ import androidx.compose.ui.Modifier
13
+ import androidx.compose.ui.draw.clipToBounds
14
+ import androidx.compose.ui.geometry.Offset
15
+ import androidx.compose.ui.graphics.Color
16
+ import androidx.compose.ui.graphics.drawscope.withTransform
17
+ import androidx.compose.ui.graphics.Path
18
+ import androidx.compose.ui.layout.onGloballyPositioned
19
+ import androidx.compose.ui.layout.positionInParent
20
+ import androidx.compose.ui.platform.LocalDensity
21
+ import androidx.compose.ui.text.style.TextOverflow
22
+ import androidx.compose.ui.unit.Dp
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.*
27
+ import vn.momo.kits.modifier.activeOpacityClickable
28
+ import vn.momo.kits.modifier.conditional
29
+
30
+ data class TabViewItem(
31
+ val title: String,
32
+ val icon: String? = null,
33
+ val renderIcon: (@Composable (active: Boolean) -> Unit)? = null,
34
+ val showDot: Boolean = false,
35
+ val dotSize: DotSize = DotSize.Small,
36
+ val badgeValue: String? = null,
37
+ val accessibilityLabel: String? = null,
38
+ val content: @Composable () -> Unit = {},
39
+ )
40
+
41
+ enum class TabViewType { DEFAULT, CARD }
42
+
43
+ enum class TabViewDirection { ROW, COLUMN }
44
+
45
+ @Composable
46
+ fun TabView(
47
+ modifier: Modifier = Modifier,
48
+ tabs: List<TabViewItem>,
49
+ initialPage: Int = 0,
50
+ type: TabViewType = TabViewType.DEFAULT,
51
+ scrollable: Boolean = false,
52
+ fitContent: Boolean = false,
53
+ selectedColor: Color? = null,
54
+ unselectedColor: Color? = null,
55
+ direction: TabViewDirection = TabViewDirection.ROW,
56
+ userScrollEnabled: Boolean = true,
57
+ onPressTabItem: (Int) -> Unit = {},
58
+ onPageSelected: (Int) -> Unit = {},
59
+ ) {
60
+ if (tabs.isEmpty()) return
61
+
62
+ val theme = AppTheme.current
63
+ val resolvedSelectedColor = selectedColor ?: theme.colors.primary
64
+ val resolvedUnselectedColor = unselectedColor ?: theme.colors.text.default
65
+
66
+ val startPage = initialPage.coerceIn(0, tabs.lastIndex)
67
+ var selectedIndex by remember { mutableStateOf(startPage) }
68
+
69
+ // Track which pages have already been visited for lazy rendering
70
+ val lazyRendered = remember { mutableStateListOf(startPage) }
71
+
72
+ val pagerState = if (!fitContent) {
73
+ rememberPagerState(initialPage = startPage) { tabs.size }
74
+ } else null
75
+
76
+ val coroutineScope = rememberCoroutineScope()
77
+ // The collector below outlives recompositions; read the latest callback, not the first one.
78
+ val currentOnPageSelected by rememberUpdatedState(onPageSelected)
79
+
80
+ // Keep selectedIndex in sync when user swipes the pager
81
+ if (pagerState != null) {
82
+ LaunchedEffect(pagerState) {
83
+ snapshotFlow { pagerState.currentPage }.collect { page ->
84
+ if (!lazyRendered.contains(page)) lazyRendered.add(page)
85
+ selectedIndex = page
86
+ currentOnPageSelected(page)
87
+ }
88
+ }
89
+ }
90
+
91
+ val onTabPressed: (Int) -> Unit = { index ->
92
+ onPressTabItem(index)
93
+ if (!lazyRendered.contains(index)) lazyRendered.add(index)
94
+ selectedIndex = index
95
+ if (pagerState != null) {
96
+ coroutineScope.launch { pagerState.animateScrollToPage(index) }
97
+ }
98
+ if (fitContent) {
99
+ onPageSelected(index)
100
+ }
101
+ }
102
+
103
+ Column(
104
+ modifier = modifier
105
+ .fillMaxWidth()
106
+ .conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) },
107
+ ) {
108
+ when {
109
+ type == TabViewType.CARD -> CardTabBar(
110
+ tabs = tabs,
111
+ selectedIndex = selectedIndex,
112
+ selectedColor = resolvedSelectedColor,
113
+ unselectedColor = resolvedUnselectedColor,
114
+ direction = direction,
115
+ onPressTabItem = onTabPressed,
116
+ )
117
+
118
+ scrollable -> ScrollableTabBar(
119
+ tabs = tabs,
120
+ selectedIndex = selectedIndex,
121
+ selectedColor = resolvedSelectedColor,
122
+ unselectedColor = resolvedUnselectedColor,
123
+ direction = direction,
124
+ onPressTabItem = onTabPressed,
125
+ )
126
+
127
+ else -> DefaultTabBar(
128
+ tabs = tabs,
129
+ selectedIndex = selectedIndex,
130
+ selectedColor = resolvedSelectedColor,
131
+ unselectedColor = resolvedUnselectedColor,
132
+ direction = direction,
133
+ onPressTabItem = onTabPressed,
134
+ )
135
+ }
136
+
137
+ if (fitContent) {
138
+ Box(modifier = Modifier.fillMaxWidth()) {
139
+ tabs.getOrNull(selectedIndex)?.content?.invoke()
140
+ }
141
+ } else if (pagerState != null) {
142
+ HorizontalPager(
143
+ state = pagerState,
144
+ modifier = Modifier
145
+ .fillMaxWidth()
146
+ .weight(1f),
147
+ userScrollEnabled = userScrollEnabled,
148
+ ) { page ->
149
+ Box(modifier = Modifier.fillMaxWidth()) {
150
+ if (lazyRendered.contains(page)) {
151
+ tabs[page].content()
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ @Composable
160
+ private fun DefaultTabBar(
161
+ tabs: List<TabViewItem>,
162
+ selectedIndex: Int,
163
+ selectedColor: Color,
164
+ unselectedColor: Color,
165
+ direction: TabViewDirection,
166
+ onPressTabItem: (Int) -> Unit,
167
+ ) {
168
+ val theme = AppTheme.current
169
+ val density = LocalDensity.current
170
+ var totalWidthPx by remember { mutableStateOf(0) }
171
+
172
+ val itemWidth: Dp = if (totalWidthPx > 0 && tabs.isNotEmpty()) {
173
+ with(density) { (totalWidthPx / tabs.size).toDp() }
174
+ } else 0.dp
175
+
176
+ val indicatorOffsetX: Dp by animateDpAsState(
177
+ targetValue = itemWidth * selectedIndex + Spacing.XS,
178
+ animationSpec = tween(durationMillis = 200),
179
+ label = "DefaultIndicatorX",
180
+ )
181
+ val indicatorWidth: Dp = (itemWidth - Spacing.XS * 2).coerceAtLeast(0.dp)
182
+
183
+ Box(
184
+ modifier = Modifier
185
+ .fillMaxWidth()
186
+ .onGloballyPositioned { totalWidthPx = it.size.width }
187
+ .background(theme.colors.background.surface)
188
+ .border(
189
+ width = 0.5.dp,
190
+ color = theme.colors.border.default,
191
+ shape = RoundedCornerShape(0.dp),
192
+ ),
193
+ ) {
194
+ Row(modifier = Modifier.fillMaxWidth()) {
195
+ tabs.forEachIndexed { index, tab ->
196
+ TabItemView(
197
+ modifier = Modifier.weight(1f),
198
+ tab = tab,
199
+ active = selectedIndex == index,
200
+ selectedColor = selectedColor,
201
+ unselectedColor = unselectedColor,
202
+ direction = direction,
203
+ onPress = { onPressTabItem(index) },
204
+ )
205
+ }
206
+ }
207
+
208
+ TabUnderlineIndicator(offsetX = indicatorOffsetX, width = indicatorWidth, color = selectedColor)
209
+ }
210
+ }
211
+
212
+ @Composable
213
+ private fun ScrollableTabBar(
214
+ tabs: List<TabViewItem>,
215
+ selectedIndex: Int,
216
+ selectedColor: Color,
217
+ unselectedColor: Color,
218
+ direction: TabViewDirection,
219
+ onPressTabItem: (Int) -> Unit,
220
+ ) {
221
+ val theme = AppTheme.current
222
+ val density = LocalDensity.current
223
+ val scrollState: ScrollState = rememberScrollState()
224
+ val coroutineScope = rememberCoroutineScope()
225
+
226
+ // Per-item (widthPx, xPx) measured relative to the scrollable row
227
+ val itemMeasures = remember { mutableStateListOf<Pair<Float, Float>>() }
228
+
229
+ val rawWidth = itemMeasures.getOrNull(selectedIndex)?.first ?: 0f
230
+ val rawX = itemMeasures.getOrNull(selectedIndex)?.second ?: 0f
231
+
232
+ val animatedWidth: Dp by animateDpAsState(
233
+ targetValue = with(density) { rawWidth.toDp() },
234
+ animationSpec = tween(250),
235
+ label = "ScrollableIndicatorWidth",
236
+ )
237
+ val animatedX: Dp by animateDpAsState(
238
+ targetValue = with(density) { rawX.toDp() },
239
+ animationSpec = tween(250),
240
+ label = "ScrollableIndicatorX",
241
+ )
242
+
243
+ // Auto-scroll bar to keep selected item visible
244
+ LaunchedEffect(selectedIndex, itemMeasures.size) {
245
+ val x = itemMeasures.getOrNull(selectedIndex)?.second ?: return@LaunchedEffect
246
+ val target = (x - with(density) { Spacing.S.toPx() }).coerceAtLeast(0f).toInt()
247
+ coroutineScope.launch { scrollState.animateScrollTo(target) }
248
+ }
249
+
250
+ val scrollOffsetDp = with(density) { scrollState.value.toDp() }
251
+
252
+ Box(
253
+ modifier = Modifier
254
+ .fillMaxWidth()
255
+ .background(theme.colors.background.surface)
256
+ .border(
257
+ width = 0.5.dp,
258
+ color = theme.colors.border.default,
259
+ shape = RoundedCornerShape(0.dp),
260
+ ),
261
+ ) {
262
+ Row(
263
+ modifier = Modifier
264
+ .fillMaxWidth()
265
+ .horizontalScroll(scrollState),
266
+ ) {
267
+ tabs.forEachIndexed { index, tab ->
268
+ Box(
269
+ modifier = Modifier
270
+ .wrapContentWidth()
271
+ .onGloballyPositioned { coords ->
272
+ val w = coords.size.width.toFloat()
273
+ val x = coords.positionInParent().x
274
+ while (itemMeasures.size <= index) itemMeasures.add(0f to 0f)
275
+ itemMeasures[index] = w to x
276
+ },
277
+ ) {
278
+ TabItemView(
279
+ tab = tab,
280
+ active = selectedIndex == index,
281
+ selectedColor = selectedColor,
282
+ unselectedColor = unselectedColor,
283
+ direction = direction,
284
+ scrollable = true,
285
+ onPress = { onPressTabItem(index) },
286
+ )
287
+ }
288
+ }
289
+ }
290
+
291
+ TabUnderlineIndicator(
292
+ offsetX = animatedX - scrollOffsetDp + Spacing.XS,
293
+ width = (animatedWidth - Spacing.XS * 2).coerceAtLeast(0.dp),
294
+ color = selectedColor,
295
+ )
296
+ }
297
+ }
298
+
299
+ @Composable
300
+ private fun CardTabBar(
301
+ tabs: List<TabViewItem>,
302
+ selectedIndex: Int,
303
+ selectedColor: Color,
304
+ unselectedColor: Color,
305
+ direction: TabViewDirection,
306
+ onPressTabItem: (Int) -> Unit,
307
+ ) {
308
+ val theme = AppTheme.current
309
+ val surface = theme.colors.background.surface
310
+
311
+ // As react-kits: a flat `black_02` strip of unselected tabs, with one raised card over it for the
312
+ // active tab, 4dp taller and joined to the strip by a curved "ear" on each side.
313
+ val pathWidth = if (tabs.size > 2) 22.dp else 28.dp
314
+ val isFirst = selectedIndex == 0
315
+ val isLast = selectedIndex == tabs.lastIndex
316
+
317
+ // Only as tall as the flat strip: like react-kits' absolute card, the raised one overflows up into
318
+ // the 4dp top padding instead of adding height.
319
+ BoxWithConstraints(
320
+ modifier = Modifier
321
+ .fillMaxWidth()
322
+ .padding(top = Spacing.XS)
323
+ .height(CARD_TAB_HEIGHT),
324
+ ) {
325
+ val itemWidth = maxWidth / tabs.size
326
+
327
+ Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.Bottom) {
328
+ tabs.forEachIndexed { index, tab ->
329
+ Box(
330
+ modifier = Modifier
331
+ .width(itemWidth)
332
+ .height(CARD_TAB_HEIGHT)
333
+ .background(
334
+ color = Colors.black_02,
335
+ shape = RoundedCornerShape(topStart = Radius.M, topEnd = Radius.M),
336
+ )
337
+ .activeOpacityClickable { onPressTabItem(index) }
338
+ .padding(horizontal = Spacing.S),
339
+ contentAlignment = Alignment.Center,
340
+ ) {
341
+ Row(verticalAlignment = Alignment.CenterVertically) {
342
+ TabLeadingIcon(tab = tab, active = false, color = unselectedColor)
343
+ Text(
344
+ text = tab.title,
345
+ style = Typography.bodyDefaultRegular,
346
+ color = unselectedColor,
347
+ maxLines = 1,
348
+ overflow = TextOverflow.Ellipsis,
349
+ modifier = Modifier.weight(1f, fill = false),
350
+ )
351
+ TabTrailingBadge(tab)
352
+ }
353
+ }
354
+ }
355
+ }
356
+
357
+ val active = tabs.getOrNull(selectedIndex) ?: return@BoxWithConstraints
358
+ Row(
359
+ modifier = Modifier
360
+ // Pinned to the strip's bottom so both end on the same pixel (a manual offset leaves a sub-dp sliver).
361
+ .align(Alignment.BottomStart)
362
+ .offset(x = itemWidth * selectedIndex - (if (isFirst) 0.dp else pathWidth))
363
+ // requiredHeight: a plain height is coerced to the 40dp box and stops 4dp short of the panel.
364
+ .requiredHeight(CARD_TAB_ACTIVE_HEIGHT),
365
+ verticalAlignment = Alignment.Bottom,
366
+ ) {
367
+ // react-kits nudges each ear 8pt UNDER the card so the join has no seam.
368
+ if (!isFirst) CardTabEar(pathWidth, mirrored = true, color = surface, nudge = 8.dp)
369
+ Box(
370
+ modifier = Modifier
371
+ .width(itemWidth)
372
+ .fillMaxHeight()
373
+ .background(
374
+ color = surface,
375
+ shape = RoundedCornerShape(topStart = Radius.M, topEnd = Radius.M),
376
+ )
377
+ .activeOpacityClickable { onPressTabItem(selectedIndex) }
378
+ .padding(horizontal = if (tabs.size == 3) Spacing.S else Spacing.M),
379
+ contentAlignment = Alignment.Center,
380
+ ) {
381
+ Row(verticalAlignment = Alignment.CenterVertically) {
382
+ TabLeadingIcon(tab = active, active = true, color = selectedColor)
383
+ Text(
384
+ text = active.title,
385
+ style = Typography.headerSSemibold,
386
+ color = selectedColor,
387
+ maxLines = 1,
388
+ overflow = TextOverflow.Ellipsis,
389
+ modifier = Modifier.weight(1f, fill = false),
390
+ )
391
+ TabTrailingBadge(active)
392
+ }
393
+ }
394
+ if (!isLast) CardTabEar(pathWidth, mirrored = false, color = surface, nudge = -8.dp)
395
+ }
396
+ }
397
+ }
398
+
399
+ private val CARD_TAB_HEIGHT = 40.dp
400
+ private val CARD_TAB_ACTIVE_HEIGHT = 44.dp
401
+ @Composable
402
+ private fun CardTabEar(width: Dp, mirrored: Boolean, color: Color, nudge: Dp) {
403
+ // Clipped like react-kits' Svg, whose 28-wide path is cut at a 22pt `pathWidth`.
404
+ Canvas(modifier = Modifier.offset(x = nudge).width(width).height(CARD_TAB_ACTIVE_HEIGHT).clipToBounds()) {
405
+ val path = Path().apply {
406
+ moveTo(0f, 0f)
407
+ lineTo(0.60765f, 0f)
408
+ cubicTo(6.47582f, 0f, 11.4819f, 4.23831f, 12.4602f, 10.0244f)
409
+ cubicTo(13.9248f, 18.6872f, 15.9294f, 30.37f, 16.6925f, 34f)
410
+ cubicTo(17.9536f, 40f, 22.259f, 44f, 27.9996f, 44f)
411
+ lineTo(0f, 44f)
412
+ close()
413
+ }
414
+ // Path coordinates are dp (react-kits viewBox), but DrawScope draws in px.
415
+ val pxPerDp = density
416
+ withTransform({
417
+ if (mirrored) scale(-1f, 1f)
418
+ scale(pxPerDp, pxPerDp, pivot = Offset.Zero)
419
+ }) { drawPath(path = path, color = color) }
420
+ }
421
+ }
422
+
423
+ @Composable
424
+ private fun TabItemView(
425
+ modifier: Modifier = Modifier,
426
+ tab: TabViewItem,
427
+ active: Boolean,
428
+ selectedColor: Color,
429
+ unselectedColor: Color,
430
+ direction: TabViewDirection,
431
+ scrollable: Boolean = false,
432
+ onPress: () -> Unit,
433
+ ) {
434
+ val textColor = if (active) selectedColor else unselectedColor
435
+ val textStyle = if (active) Typography.headerSSemibold else Typography.bodyDefaultRegular
436
+
437
+ if (direction == TabViewDirection.COLUMN) {
438
+ Column(
439
+ modifier = modifier
440
+ .height(68.dp)
441
+ .activeOpacityClickable { onPress() }
442
+ .padding(horizontal = Spacing.S),
443
+ horizontalAlignment = Alignment.CenterHorizontally,
444
+ verticalArrangement = Arrangement.Center,
445
+ ) {
446
+ // Icon area with badge/dot overlay
447
+ Box(contentAlignment = Alignment.TopEnd) {
448
+ if (tab.renderIcon != null) {
449
+ tab.renderIcon.invoke(active)
450
+ } else if (tab.icon != null) {
451
+ Icon(
452
+ source = tab.icon,
453
+ size = 24.dp,
454
+ color = textColor,
455
+ )
456
+ }
457
+ if (tab.showDot) {
458
+ BadgeDot(
459
+ size = tab.dotSize,
460
+ modifier = Modifier
461
+ .align(Alignment.TopEnd)
462
+ .offset(x = 4.dp, y = (-4).dp),
463
+ )
464
+ } else if (!tab.badgeValue.isNullOrEmpty()) {
465
+ Badge(
466
+ label = tab.badgeValue,
467
+ modifier = Modifier
468
+ .align(Alignment.TopEnd)
469
+ .offset(x = 4.dp, y = (-4).dp),
470
+ )
471
+ }
472
+ }
473
+ if (tab.icon != null || tab.renderIcon != null) {
474
+ Spacer(modifier = Modifier.height(Spacing.XXS))
475
+ }
476
+ Text(
477
+ text = tab.title,
478
+ style = textStyle,
479
+ color = textColor,
480
+ maxLines = 1,
481
+ overflow = TextOverflow.Ellipsis,
482
+ )
483
+ }
484
+ } else {
485
+ Row(
486
+ modifier = modifier
487
+ .height(48.dp)
488
+ .activeOpacityClickable { onPress() }
489
+ .padding(horizontal = Spacing.M),
490
+ horizontalArrangement = Arrangement.Center,
491
+ verticalAlignment = Alignment.CenterVertically,
492
+ ) {
493
+ TabLeadingIcon(tab = tab, active = active, color = textColor)
494
+ Text(
495
+ text = tab.title,
496
+ style = textStyle,
497
+ color = textColor,
498
+ maxLines = 1,
499
+ overflow = TextOverflow.Ellipsis,
500
+ modifier = if (scrollable) Modifier else Modifier.weight(1f, fill = false),
501
+ )
502
+ TabTrailingBadge(tab)
503
+ }
504
+ }
505
+ }
506
+
507
+ @Composable
508
+ private fun BoxScope.TabUnderlineIndicator(offsetX: Dp, width: Dp, color: Color) {
509
+ Box(
510
+ modifier = Modifier
511
+ .align(Alignment.BottomStart)
512
+ .offset(x = offsetX)
513
+ .width(width)
514
+ .height(2.dp)
515
+ .background(
516
+ color = color,
517
+ shape = RoundedCornerShape(topStart = Radius.XXS, topEnd = Radius.XXS),
518
+ ),
519
+ )
520
+ }
521
+
522
+ @Composable
523
+ private fun TabLeadingIcon(tab: TabViewItem, active: Boolean, color: Color) {
524
+ if (tab.renderIcon != null) {
525
+ tab.renderIcon.invoke(active)
526
+ Spacer(modifier = Modifier.width(Spacing.XS))
527
+ } else if (tab.icon != null) {
528
+ Icon(source = tab.icon, size = 18.dp, color = color)
529
+ Spacer(modifier = Modifier.width(Spacing.XS))
530
+ }
531
+ }
532
+
533
+ @Composable
534
+ private fun TabTrailingBadge(tab: TabViewItem) {
535
+ if (tab.showDot) {
536
+ Spacer(modifier = Modifier.width(Spacing.XS))
537
+ BadgeDot(size = tab.dotSize)
538
+ } else if (!tab.badgeValue.isNullOrEmpty()) {
539
+ Spacer(modifier = Modifier.width(Spacing.XS))
540
+ Badge(label = tab.badgeValue, modifier = Modifier)
541
+ }
542
+ }
@@ -0,0 +1,86 @@
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.Box
6
+ import androidx.compose.foundation.layout.Row
7
+ import androidx.compose.foundation.layout.height
8
+ import androidx.compose.foundation.layout.padding
9
+ import androidx.compose.foundation.shape.RoundedCornerShape
10
+ import androidx.compose.runtime.Composable
11
+ import androidx.compose.ui.Alignment
12
+ import androidx.compose.ui.Modifier
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.*
17
+ import vn.momo.kits.modifier.conditional
18
+
19
+ enum class TagSize(val height: Float) {
20
+ Large(24.toFloat()),
21
+ Medium(18.toFloat())
22
+ }
23
+
24
+ enum class TagColor(val backgroundColor: Color, val textColor: Color) {
25
+ Default(Colors.black_04, Colors.black_17),
26
+ Orange(Colors.orange_08, Colors.orange_03),
27
+ Green(Colors.green_08, Colors.green_03),
28
+ Red(Colors.red_08, Colors.red_03),
29
+ Blue(Colors.blue_08, Colors.blue_03),
30
+ Grey(Colors.black_04, Colors.black_12),
31
+ }
32
+
33
+ // RN only accepts the `_03` palette as a custom tag color.
34
+ private val tagCustomColors = listOf(
35
+ Colors.black_03,
36
+ Colors.pink_03,
37
+ Colors.violet_03,
38
+ Colors.indigo_03,
39
+ Colors.blue_03,
40
+ Colors.mint_03,
41
+ Colors.green_03,
42
+ Colors.lime_03,
43
+ Colors.yellow_03,
44
+ Colors.gold_03,
45
+ Colors.orange_03,
46
+ Colors.red_03,
47
+ )
48
+
49
+ @Composable
50
+ fun Tag(
51
+ label: String = "Label",
52
+ icon: String? = null,
53
+ color: TagColor = TagColor.Default,
54
+ size: TagSize = TagSize.Large,
55
+ customColor: Color? = null,
56
+ ) {
57
+ val custom = customColor?.takeIf { it in tagCustomColors }
58
+ val tagColor = custom ?: color.backgroundColor
59
+ val labelColor = if (custom != null) Colors.black_01 else color.textColor
60
+
61
+ Box(
62
+ modifier = Modifier
63
+ .height(scaleSize(size.height).dp)
64
+ .background(tagColor, shape = RoundedCornerShape(Radius.S))
65
+ .conditional(IsShowBaseLineDebug) {
66
+ border(1.dp, Colors.blue_03)
67
+ }
68
+ .padding(horizontal = Spacing.S),
69
+ contentAlignment = Alignment.Center
70
+ ) {
71
+ Row(verticalAlignment = Alignment.CenterVertically) {
72
+ if (icon != null) {
73
+ Icon(
74
+ source = icon,
75
+ size = 16.dp,
76
+ color = labelColor
77
+ )
78
+ }
79
+ Text(
80
+ text = label,
81
+ color = labelColor,
82
+ style = Typography.labelSMedium
83
+ )
84
+ }
85
+ }
86
+ }