@momo-kits/native-kits 0.169.11 → 0.169.12-beta.1-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 (143) 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 +71 -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 +398 -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 +6 -1
  139. package/ios/native-kits.podspec +1 -1
  140. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  141. package/ios-demo/README.md +120 -0
  142. package/package.json +1 -1
  143. package/settings.gradle.kts +64 -0
@@ -0,0 +1,398 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.runtime.getValue
4
+ import androidx.compose.animation.animateColorAsState
5
+ import androidx.compose.animation.core.Animatable
6
+ import androidx.compose.animation.core.animateFloatAsState
7
+ import androidx.compose.animation.core.tween
8
+ import androidx.compose.foundation.clickable
9
+ import androidx.compose.foundation.interaction.MutableInteractionSource
10
+ import androidx.compose.foundation.interaction.collectIsPressedAsState
11
+ import androidx.compose.runtime.LaunchedEffect
12
+ import androidx.compose.runtime.mutableStateMapOf
13
+ import androidx.compose.ui.draw.clip
14
+ import androidx.compose.ui.draw.dropShadow
15
+ import androidx.compose.ui.draw.innerShadow
16
+ import androidx.compose.ui.graphics.Color
17
+ import androidx.compose.ui.graphics.Shape
18
+ import androidx.compose.ui.graphics.graphicsLayer
19
+ import androidx.compose.ui.layout.onPlaced
20
+ import androidx.compose.ui.layout.positionInParent
21
+ import androidx.compose.ui.platform.LocalDensity
22
+ import androidx.compose.ui.semantics.Role
23
+ import androidx.compose.ui.semantics.contentDescription
24
+ import androidx.compose.ui.semantics.role
25
+ import androidx.compose.ui.semantics.selected
26
+ import androidx.compose.ui.semantics.semantics
27
+ import androidx.compose.foundation.background
28
+ import androidx.compose.foundation.border
29
+ import androidx.compose.foundation.layout.*
30
+ import androidx.compose.foundation.shape.CircleShape
31
+ import androidx.compose.foundation.shape.RoundedCornerShape
32
+ import androidx.compose.runtime.Composable
33
+ import androidx.compose.runtime.remember
34
+ import androidx.compose.ui.Alignment
35
+ import androidx.compose.ui.Modifier
36
+ import androidx.compose.ui.text.style.TextAlign
37
+ import androidx.compose.ui.text.style.TextOverflow
38
+ import androidx.compose.ui.unit.dp
39
+ import vn.momo.kits.application.IsShowBaseLineDebug
40
+ import vn.momo.kits.components.*
41
+ import vn.momo.kits.const.*
42
+ import vn.momo.kits.layout.getScreenLayout
43
+ import vn.momo.kits.modifier.InternalApi
44
+ import vn.momo.kits.modifier.activeOpacityClickable
45
+ import vn.momo.kits.modifier.conditional
46
+ import vn.momo.kits.modifier.setAutomationId
47
+
48
+ @InternalApi
49
+ const val BOTTOM_TAB_BAR_HEIGHT = 68
50
+
51
+ // Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
52
+ @Composable
53
+ internal fun BottomTabBar(
54
+ items: List<BottomTabItem>,
55
+ floatingButton: BottomTabFloatingButton? = null,
56
+ selectedIndex: Int,
57
+ onTabSelected: (Int) -> Unit,
58
+ ) {
59
+ val layout = getScreenLayout()
60
+ Box(
61
+ modifier = Modifier
62
+ .fillMaxWidth()
63
+ .padding(bottom = tabBarBottomGap(layout.insetBottom)),
64
+ contentAlignment = Alignment.BottomCenter,
65
+ ) {
66
+ HorizontalTabBar(
67
+ items = items,
68
+ floatingButton = floatingButton,
69
+ selectedIndex = selectedIndex,
70
+ onTabSelected = onTabSelected,
71
+ modifier = Modifier
72
+ .offset(x = (layout.insetLeft - layout.insetRight) / 2)
73
+ .width(
74
+ horizontalBarWidth(
75
+ layout.width, layout.height, layout.insetLeft, layout.insetRight,
76
+ items.size, hasCenterAction(floatingButton, items.size),
77
+ ),
78
+ ),
79
+ )
80
+ }
81
+ }
82
+
83
+ // Floating bar, items split evenly; Special type puts the center action in a notch, rising ctaLift above the bar.
84
+ @Composable
85
+ internal fun HorizontalTabBar(
86
+ items: List<BottomTabItem>,
87
+ floatingButton: BottomTabFloatingButton?,
88
+ selectedIndex: Int,
89
+ onTabSelected: (Int) -> Unit,
90
+ modifier: Modifier = Modifier,
91
+ ) {
92
+ val cta = floatingButton?.takeIf { hasCenterAction(it, items.size) }
93
+ val mid = items.size / 2
94
+ val density = LocalDensity.current
95
+ val itemBounds = remember(items.size) { mutableStateMapOf<Int, Pair<Float, Float>>() }
96
+
97
+ BoxWithConstraints(modifier = modifier) {
98
+ val shape = remember(maxWidth, cta != null) {
99
+ NotchedBarShape(TabBarMetrics.height / 2, if (cta != null) maxWidth / 2 else null)
100
+ }
101
+ Box(
102
+ modifier = Modifier
103
+ .padding(top = if (cta != null) TabBarMetrics.ctaLift else 0.dp)
104
+ .fillMaxWidth()
105
+ .height(TabBarMetrics.height)
106
+ .tabBarContainer(shape)
107
+ .padding(horizontal = TabBarMetrics.paddingHorizontal, vertical = TabBarMetrics.paddingVertical)
108
+ .setAutomationId("bottom_tab_bar"),
109
+ ) {
110
+ itemBounds[selectedIndex]?.let { (x, width) ->
111
+ ActiveIndicator(
112
+ offset = x,
113
+ modifier = Modifier
114
+ .width(with(density) { width.toDp() })
115
+ .height(TabBarMetrics.indicatorHeight),
116
+ shape = RoundedCornerShape(TabBarMetrics.indicatorRadius),
117
+ axisX = true,
118
+ )
119
+ }
120
+ Row(
121
+ modifier = Modifier.fillMaxSize(),
122
+ horizontalArrangement = Arrangement.spacedBy(TabBarMetrics.itemGap),
123
+ verticalAlignment = Alignment.CenterVertically,
124
+ ) {
125
+ items.forEachIndexed { index, item ->
126
+ if (cta != null && index == mid) {
127
+ Spacer(Modifier.width(TabBarMetrics.ctaSlotWidth))
128
+ }
129
+ TabBarItem(
130
+ item = item,
131
+ selected = index == selectedIndex,
132
+ modifier = Modifier.onPlaced {
133
+ itemBounds[index] = it.positionInParent().x to it.size.width.toFloat()
134
+ },
135
+ onClick = { onTabSelected(index) },
136
+ )
137
+ }
138
+ }
139
+ }
140
+ cta?.let { CenterAction(it, Modifier.align(Alignment.TopCenter).offset(y = centerActionTop())) }
141
+ }
142
+ }
143
+
144
+ // Offset of the center action column from the bar top: the items are centered in the container (which
145
+ // starts ctaLift down), so the column is placed for its label to start on the tab labels' line.
146
+ private fun centerActionTop() = with(TabBarMetrics) {
147
+ val itemHeight = indicatorHeight + itemIconLabelGap + labelHeight
148
+ val itemLabelTop = ctaLift + paddingVertical + (height - paddingVertical * 2 - itemHeight) / 2 +
149
+ indicatorHeight + itemIconLabelGap
150
+ itemLabelTop - ctaLabelGap - ctaSize
151
+ }
152
+
153
+ // One active indicator per bar (Background/tonal with its inner shadows) sliding to the selected item
154
+ // along x (horizontal bar) or y (rail); it lands in place on the first measure and slides from then on.
155
+ @Composable
156
+ internal fun ActiveIndicator(offset: Float, modifier: Modifier, shape: Shape, axisX: Boolean) {
157
+ val colors = AppTheme.current.colors
158
+ val position = remember { Animatable(offset) }
159
+ LaunchedEffect(offset) {
160
+ if (position.value != offset) position.animateTo(offset, TabBarMotion.indicator)
161
+ }
162
+ Box(
163
+ modifier
164
+ .graphicsLayer {
165
+ if (axisX) translationX = position.value else translationY = position.value
166
+ }
167
+ .background(colors.background.tonal, shape)
168
+ .then(
169
+ indicatorInnerShadows(colors.primary).fold(Modifier as Modifier) { acc, shadow ->
170
+ acc.innerShadow(shape, shadow)
171
+ }
172
+ )
173
+ )
174
+ }
175
+
176
+ @Composable
177
+ private fun RowScope.TabBarItem(
178
+ item: BottomTabItem,
179
+ selected: Boolean,
180
+ modifier: Modifier,
181
+ onClick: () -> Unit,
182
+ ) {
183
+ Column(
184
+ modifier = modifier
185
+ .weight(1f)
186
+ .conditional(IsShowBaseLineDebug) {
187
+ border(1.dp, Colors.blue_03)
188
+ }
189
+ .activeOpacityClickable { onClick() }
190
+ .semantics {
191
+ role = Role.Tab
192
+ this.selected = selected
193
+ contentDescription = item.label
194
+ },
195
+ horizontalAlignment = Alignment.CenterHorizontally,
196
+ verticalArrangement = Arrangement.spacedBy(TabBarMetrics.itemIconLabelGap),
197
+ ) {
198
+ TabItemContent(item, selected)
199
+ }
200
+ }
201
+
202
+ // Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
203
+ // slots; the icon and label tint cross-fade on focus.
204
+ @Composable
205
+ internal fun ColumnScope.TabItemContent(
206
+ item: BottomTabItem,
207
+ selected: Boolean,
208
+ vertical: Boolean = false,
209
+ showLabel: Boolean = true,
210
+ ) {
211
+ val colors = AppTheme.current.colors
212
+ val tint by animateColorAsState(
213
+ if (selected) colors.primary else colors.text.secondary,
214
+ tween(TabBarMotion.TINT_MILLIS, easing = inOutQuad),
215
+ label = "TabTint",
216
+ )
217
+
218
+ Box(
219
+ modifier = Modifier
220
+ .then(if (vertical) Modifier else Modifier.fillMaxWidth())
221
+ .height(if (vertical) TabBarMetrics.railIndicatorHeight else TabBarMetrics.indicatorHeight)
222
+ .padding(horizontal = TabBarMetrics.indicatorPaddingHorizontal),
223
+ contentAlignment = Alignment.Center,
224
+ ) {
225
+ TabIcon(item, tint, vertical)
226
+ }
227
+ if (showLabel) {
228
+ // fixed slot so a capped-scale label overflows downward and the icon above it stays put
229
+ Box(
230
+ modifier = Modifier.height(
231
+ if (vertical) TabBarMetrics.railLabelHeight else TabBarMetrics.labelHeight
232
+ ),
233
+ contentAlignment = Alignment.TopCenter,
234
+ ) {
235
+ Text(
236
+ text = item.label,
237
+ color = tint,
238
+ style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
239
+ textAlign = TextAlign.Center,
240
+ maxLines = 1,
241
+ overflow = TextOverflow.Ellipsis,
242
+ modifier = (if (vertical) Modifier else Modifier.fillMaxWidth())
243
+ .wrapContentHeight(Alignment.Top, unbounded = true),
244
+ )
245
+ }
246
+ }
247
+ }
248
+
249
+ // Badge value shown on a tab: null hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
250
+ internal fun tabBadgeLabel(item: BottomTabItem): String? {
251
+ val label = item.badgeLabel ?: return if (item.showDot) "" else null
252
+ if (label.isEmpty()) return ""
253
+ if (label.all { it in '0'..'9' }) {
254
+ val value = label.toLongOrNull() ?: Long.MAX_VALUE
255
+ if (value == 0L) return if (item.showDot) "" else null
256
+ return if (value > 99) "99+" else label
257
+ }
258
+ return label
259
+ }
260
+
261
+ // 24 icon; badges hang off it unclipped: dot at 16/-2, label badge at 12/-7 growing right, or
262
+ // centered over the icon at -10 on the rail.
263
+ @Composable
264
+ internal fun TabIcon(item: BottomTabItem, tint: androidx.compose.ui.graphics.Color, vertical: Boolean) {
265
+ val badge = tabBadgeLabel(item)
266
+ Box(Modifier.size(TabBarMetrics.iconSize)) {
267
+ Icon(source = item.icon, size = TabBarMetrics.iconSize, color = tint)
268
+ when {
269
+ badge == null -> Unit
270
+ badge.isEmpty() -> BadgeDot(
271
+ size = DotSize.Small,
272
+ modifier = Modifier.offset(x = 16.dp, y = -Spacing.XXS),
273
+ )
274
+ vertical -> TabBadge(
275
+ badge,
276
+ Modifier.matchParentSize()
277
+ .wrapContentSize(Alignment.TopCenter, unbounded = true)
278
+ .offset(y = (-10).dp),
279
+ )
280
+ else -> TabBadge(
281
+ badge,
282
+ Modifier.matchParentSize()
283
+ .wrapContentSize(Alignment.TopStart, unbounded = true)
284
+ .offset(x = Spacing.M, y = (-7).dp),
285
+ )
286
+ }
287
+ }
288
+ }
289
+
290
+ // Numbers use the error color, text the warning color (Figma Badge round numeric / text); the text keeps
291
+ // its design size so it fits the 16 height on the Duo displays too.
292
+ @Composable
293
+ private fun TabBadge(label: String, modifier: Modifier) {
294
+ val colors = AppTheme.current.colors
295
+ val isNumber = label.trimEnd('+').let { it.isNotEmpty() && it.all { c -> c in '0'..'9' } }
296
+ Box(
297
+ modifier = modifier
298
+ .height(16.dp)
299
+ .widthIn(min = 16.dp, max = TabBarMetrics.badgeMaxWidth)
300
+ .background(if (isNumber) colors.error.primary else colors.warning.primary, CircleShape)
301
+ .border(1.dp, colors.background.surface, CircleShape)
302
+ .padding(horizontal = Spacing.XS),
303
+ contentAlignment = Alignment.Center,
304
+ ) {
305
+ ScaleSizeScope(1f) {
306
+ Text(
307
+ text = label,
308
+ style = Typography.actionXxsBold,
309
+ color = Colors.black_01,
310
+ maxLines = 1,
311
+ overflow = TextOverflow.Ellipsis,
312
+ )
313
+ }
314
+ }
315
+ }
316
+
317
+ // Center action press: the button shrinks while held; the label stays plain text.
318
+ @Composable
319
+ internal fun rememberCenterActionPress(): Pair<MutableInteractionSource, Boolean> {
320
+ val interactionSource = remember { MutableInteractionSource() }
321
+ val pressed by interactionSource.collectIsPressedAsState()
322
+ return interactionSource to pressed
323
+ }
324
+
325
+ @Composable
326
+ internal fun Modifier.centerActionPressScale(pressed: Boolean): Modifier {
327
+ val scale by animateFloatAsState(
328
+ if (pressed) TabBarMotion.CTA_PRESSED_SCALE else 1f,
329
+ tween(TabBarMotion.CTA_PRESS_MILLIS, easing = inOutQuad),
330
+ label = "CenterActionPress",
331
+ )
332
+ return graphicsLayer {
333
+ scaleX = scale
334
+ scaleY = scale
335
+ }
336
+ }
337
+
338
+ @Composable
339
+ internal fun Modifier.centerActionButton(size: androidx.compose.ui.unit.Dp, pressed: Boolean): Modifier {
340
+ return centerActionPressScale(pressed)
341
+ .size(size)
342
+ .then(CtaShadows.fold(Modifier as Modifier) { acc, shadow -> acc.spreadShadow(CircleShape, shadow) })
343
+ .background(AppTheme.current.colors.primary, CircleShape)
344
+ .border(1.dp, Color.White.copy(alpha = TabBarMetrics.ctaBorderOpacity), CircleShape)
345
+ }
346
+
347
+ @Composable
348
+ internal fun CenterActionLabel(label: String, overlay: (@Composable () -> Unit)?, vertical: Boolean) {
349
+ val colors = AppTheme.current.colors
350
+ Box(
351
+ modifier = Modifier
352
+ .then(if (vertical) Modifier else Modifier.heightIn(min = TabBarMetrics.ctaLabelHeight))
353
+ .padding(horizontal = if (vertical) Spacing.XS else Spacing.XXS),
354
+ contentAlignment = Alignment.Center,
355
+ ) {
356
+ Text(
357
+ text = label,
358
+ style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
359
+ color = colors.text.secondary,
360
+ textAlign = TextAlign.Center,
361
+ maxLines = 1,
362
+ overflow = TextOverflow.Ellipsis,
363
+ )
364
+ overlay?.let {
365
+ Box(Modifier.matchParentSize().wrapContentSize(Alignment.Center, unbounded = true)) { it() }
366
+ }
367
+ }
368
+ }
369
+
370
+ // Center action (.Nav/CTA): button rising out of the notch, label under it.
371
+ @Composable
372
+ private fun CenterAction(data: BottomTabFloatingButton, modifier: Modifier) {
373
+ val (interactionSource, pressed) = rememberCenterActionPress()
374
+ Column(
375
+ modifier = modifier
376
+ .width(TabBarMetrics.ctaSlotWidth)
377
+ .conditional(IsShowBaseLineDebug) {
378
+ border(1.dp, Colors.blue_03)
379
+ }
380
+ .clickable(interactionSource = interactionSource, indication = null, onClick = data.onPress)
381
+ .setAutomationId(data.label),
382
+ horizontalAlignment = Alignment.CenterHorizontally,
383
+ verticalArrangement = Arrangement.spacedBy(TabBarMetrics.ctaLabelGap),
384
+ ) {
385
+ Box(Modifier.centerActionButton(TabBarMetrics.ctaSize, pressed), contentAlignment = Alignment.Center) {
386
+ val iconContent = data.iconContent
387
+ if (iconContent != null) {
388
+ // custom content (e.g. an oversized Lottie) is clipped to the round button
389
+ Box(Modifier.size(TabBarMetrics.ctaSize).clip(CircleShape), contentAlignment = Alignment.Center) {
390
+ iconContent()
391
+ }
392
+ } else {
393
+ Icon(source = data.icon, color = Colors.black_01, size = TabBarMetrics.ctaIconSize)
394
+ }
395
+ }
396
+ CenterActionLabel(data.label, data.labelContent, vertical = false)
397
+ }
398
+ }
@@ -0,0 +1,103 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.ui.Modifier
4
+ import androidx.compose.ui.draw.dropShadow
5
+ import androidx.compose.ui.geometry.Rect
6
+ import androidx.compose.ui.geometry.RoundRect
7
+ import androidx.compose.ui.geometry.Size
8
+ import androidx.compose.ui.geometry.CornerRadius
9
+ import androidx.compose.ui.geometry.Offset
10
+ import androidx.compose.ui.graphics.addOutline
11
+ import androidx.compose.ui.graphics.Color
12
+ import androidx.compose.ui.graphics.Outline
13
+ import androidx.compose.ui.graphics.Path
14
+ import androidx.compose.ui.graphics.Shape
15
+ import androidx.compose.ui.graphics.shadow.Shadow
16
+ import androidx.compose.ui.unit.Density
17
+ import androidx.compose.ui.unit.Dp
18
+ import androidx.compose.ui.unit.DpOffset
19
+ import androidx.compose.ui.unit.LayoutDirection
20
+ import androidx.compose.ui.unit.dp
21
+ import androidx.compose.foundation.background
22
+ import androidx.compose.foundation.border
23
+ import androidx.compose.runtime.Composable
24
+ import vn.momo.kits.const.AppTheme
25
+
26
+ // Rounded container, with the notch dipped into the top edge around `notchCenterX` (from the left).
27
+ internal class NotchedBarShape(
28
+ private val radius: Dp,
29
+ private val notchCenterX: Dp? = null,
30
+ ) : Shape {
31
+ override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
32
+ val r = minOf(with(density) { radius.toPx() }, size.height / 2, size.width / 2)
33
+ val path = Path()
34
+ if (notchCenterX == null) {
35
+ path.addRoundRect(RoundRect(Rect(0f, 0f, size.width, size.height), CornerRadius(r)))
36
+ return Outline.Generic(path)
37
+ }
38
+ val cx = with(density) { notchCenterX.toPx() }
39
+ val unit = density.density
40
+ path.apply {
41
+ moveTo(r, 0f)
42
+ lineTo(cx - NOTCH_HALF_WIDTH * unit, 0f)
43
+ NOTCH_CURVES.forEach { (c1, c2, end) ->
44
+ cubicTo(
45
+ cx + c1.first * unit, c1.second * unit,
46
+ cx + c2.first * unit, c2.second * unit,
47
+ cx + end.first * unit, end.second * unit,
48
+ )
49
+ }
50
+ lineTo(size.width - r, 0f)
51
+ arcTo(Rect(size.width - 2 * r, 0f, size.width, 2 * r), -90f, 90f, false)
52
+ lineTo(size.width, size.height - r)
53
+ arcTo(Rect(size.width - 2 * r, size.height - 2 * r, size.width, size.height), 0f, 90f, false)
54
+ lineTo(r, size.height)
55
+ arcTo(Rect(0f, size.height - 2 * r, 2 * r, size.height), 90f, 90f, false)
56
+ lineTo(0f, r)
57
+ arcTo(Rect(0f, 0f, 2 * r, 2 * r), 180f, 90f, false)
58
+ close()
59
+ }
60
+ return Outline.Generic(path)
61
+ }
62
+ }
63
+
64
+ // The shape shrunk by `inset` on every side. A shadow cast from it with no spread is a shadow of the
65
+ // shape with spread -inset; dropShadow's own negative spread clips the blur of path outlines.
66
+ internal class InsetShape(private val shape: Shape, private val inset: Dp) : Shape {
67
+ override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
68
+ val insetPx = with(density) { inset.toPx() }
69
+ val inner = Size((size.width - 2 * insetPx).coerceAtLeast(0f), (size.height - 2 * insetPx).coerceAtLeast(0f))
70
+ val path = Path().apply {
71
+ addOutline(shape.createOutline(inner, layoutDirection, density))
72
+ translate(Offset(insetPx, insetPx))
73
+ }
74
+ return Outline.Generic(path)
75
+ }
76
+ }
77
+
78
+ // Shadow with a negative spread, cast from the shrunk shape.
79
+ internal fun Modifier.spreadShadow(shape: Shape, shadow: Shadow): Modifier {
80
+ if (shadow.spread < 0.dp) {
81
+ return dropShadow(
82
+ InsetShape(shape, -shadow.spread),
83
+ Shadow(radius = shadow.radius, color = shadow.color, offset = shadow.offset, alpha = shadow.alpha),
84
+ )
85
+ }
86
+ return dropShadow(shape, shadow)
87
+ }
88
+
89
+ // Floating shadow follows the shape (Figma Shadow/floating: 12% blur 24, 4% y12 blur 32 spread -16).
90
+ @Composable
91
+ internal fun Modifier.tabBarContainer(shape: Shape): Modifier {
92
+ return dropShadow(shape, Shadow(radius = 24.dp, color = Color.Black, alpha = 0.12f))
93
+ .spreadShadow(
94
+ shape,
95
+ Shadow(radius = 32.dp, spread = (-16).dp, color = Color.Black, alpha = 0.04f, offset = DpOffset(0.dp, 12.dp)),
96
+ )
97
+ .background(
98
+ AppTheme.current.colors.background.surface.copy(alpha = TabBarMetrics.backgroundOpacity),
99
+ shape,
100
+ )
101
+ // Figma .Nav/Background: 1px light-gray hairline defining the pill edge
102
+ .border(1.dp, AppTheme.current.colors.border.default, shape)
103
+ }
@@ -0,0 +1,93 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.Stable
5
+ import androidx.compose.runtime.compositionLocalOf
6
+ import androidx.compose.runtime.getValue
7
+ import androidx.compose.runtime.mutableStateOf
8
+ import androidx.compose.runtime.remember
9
+ import androidx.compose.runtime.setValue
10
+ import androidx.compose.ui.unit.Dp
11
+ import vn.momo.kits.const.Spacing
12
+ import vn.momo.kits.layout.DuoMetrics
13
+ import vn.momo.kits.layout.ScreenLayout
14
+
15
+ // iPhone Duo: which side bar bar starts compressed when the strip cannot hold both whole.
16
+ enum class DuoBarCompressionBehavior { TOOLBAR, TAB_BAR }
17
+
18
+ private enum class DuoBar { TOOLBAR, TAB_BAR }
19
+
20
+ @Stable
21
+ internal class DuoBarCompression(
22
+ val toolbarCompressed: Boolean = false,
23
+ val tabBarCompressed: Boolean = false,
24
+ // the open rail needs the toolbar button slot too: only Back stays
25
+ val toolbarHidden: Boolean = false,
26
+ val expandToolbar: () -> Unit = {},
27
+ val expandTabBar: () -> Unit = {},
28
+ // a rail opened from the compressed state closes once a tab is picked
29
+ val onTabSelected: () -> Unit = {},
30
+ // side bar columns report their full height so the tab bar knows what is left
31
+ val setToolbarHeight: (Dp) -> Unit = {},
32
+ )
33
+
34
+ internal val LocalDuoBarCompression = compositionLocalOf { DuoBarCompression() }
35
+
36
+ // space kept between the top and the bottom groups (HIG Vertical controls)
37
+ internal val DUO_GROUP_GAP = Spacing.M
38
+ // Back, then the right toolkit: help + home capsule
39
+ private val DEFAULT_TOOLBAR_HEIGHT = DuoMetrics.controlSize + Spacing.M + DuoMetrics.itemPitch * 2
40
+ // Back, then the single button the toolbar folds into
41
+ private val COMPRESSED_TOOLBAR_HEIGHT = DuoMetrics.controlSize * 2 + Spacing.M
42
+
43
+ // Port of RN DuoBarCompression (HIG Vertical controls): both whole, else one compressed (tap swaps), else both.
44
+ @Composable
45
+ internal fun rememberDuoBarCompression(
46
+ behavior: DuoBarCompressionBehavior,
47
+ tabCount: Int,
48
+ hasQr: Boolean,
49
+ layout: ScreenLayout,
50
+ ): DuoBarCompression {
51
+ var toolbarHeight by remember { mutableStateOf(DEFAULT_TOOLBAR_HEIGHT) }
52
+ var expanded by remember(behavior) {
53
+ mutableStateOf(if (behavior == DuoBarCompressionBehavior.TOOLBAR) DuoBar.TAB_BAR else DuoBar.TOOLBAR)
54
+ }
55
+ var opened by remember { mutableStateOf<DuoBar?>(null) }
56
+ val setToolbarHeight = remember { { height: Dp -> toolbarHeight = height } }
57
+ val sideBar = layout.sideBar
58
+
59
+ return remember(sideBar, layout.height, tabCount, hasQr, toolbarHeight, expanded, opened) {
60
+ if (sideBar == null) return@remember DuoBarCompression()
61
+ val room = layout.height - sideBar.bottom - sideBar.top - DUO_GROUP_GAP
62
+ val tabBar = duoRailHeight(tabCount, hasQr)
63
+ val compressedTabBar = duoRailHeight(1, hasQr, compressed = true)
64
+ fun fits(toolbar: Dp, tabs: Dp) = toolbar + tabs <= room
65
+
66
+ when {
67
+ fits(toolbarHeight, tabBar) -> DuoBarCompression(setToolbarHeight = setToolbarHeight)
68
+ fits(COMPRESSED_TOOLBAR_HEIGHT, tabBar) && fits(toolbarHeight, compressedTabBar) -> DuoBarCompression(
69
+ toolbarCompressed = expanded == DuoBar.TAB_BAR,
70
+ tabBarCompressed = expanded == DuoBar.TOOLBAR,
71
+ expandToolbar = { expanded = DuoBar.TOOLBAR },
72
+ expandTabBar = { expanded = DuoBar.TAB_BAR },
73
+ setToolbarHeight = setToolbarHeight,
74
+ )
75
+ // an opened rail always shows, even when only the group gap is short: it closes once a tab is picked
76
+ opened == DuoBar.TAB_BAR -> DuoBarCompression(
77
+ toolbarCompressed = true,
78
+ toolbarHidden = true,
79
+ expandToolbar = { opened = DuoBar.TOOLBAR },
80
+ expandTabBar = { opened = DuoBar.TAB_BAR },
81
+ onTabSelected = { opened = null },
82
+ setToolbarHeight = setToolbarHeight,
83
+ )
84
+ else -> DuoBarCompression(
85
+ toolbarCompressed = opened != DuoBar.TOOLBAR,
86
+ tabBarCompressed = true,
87
+ expandToolbar = { opened = DuoBar.TOOLBAR },
88
+ expandTabBar = { opened = DuoBar.TAB_BAR },
89
+ setToolbarHeight = setToolbarHeight,
90
+ )
91
+ }
92
+ }
93
+ }