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