@momo-kits/native-kits 0.169.12 → 0.169.13-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 (144) 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 +409 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +111 -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/Navigation/BottomTab/BottomTabBar.swift +14 -4
  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/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +16 -3
  143. package/package.json +1 -1
  144. package/settings.gradle.kts +64 -0
@@ -0,0 +1,409 @@
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.graphics.drawscope.Stroke
15
+ import androidx.compose.ui.draw.drawBehind
16
+ import androidx.compose.ui.draw.dropShadow
17
+ import androidx.compose.ui.draw.innerShadow
18
+ import androidx.compose.ui.graphics.Color
19
+ import androidx.compose.ui.graphics.Shape
20
+ import androidx.compose.ui.graphics.graphicsLayer
21
+ import androidx.compose.ui.layout.onPlaced
22
+ import androidx.compose.ui.layout.positionInParent
23
+ import androidx.compose.ui.platform.LocalDensity
24
+ import androidx.compose.ui.semantics.Role
25
+ import androidx.compose.ui.semantics.contentDescription
26
+ import androidx.compose.ui.semantics.role
27
+ import androidx.compose.ui.semantics.selected
28
+ import androidx.compose.ui.semantics.semantics
29
+ import androidx.compose.foundation.background
30
+ import androidx.compose.foundation.border
31
+ import androidx.compose.foundation.layout.*
32
+ import androidx.compose.foundation.shape.CircleShape
33
+ import androidx.compose.foundation.shape.RoundedCornerShape
34
+ import androidx.compose.runtime.Composable
35
+ import androidx.compose.runtime.remember
36
+ import androidx.compose.ui.Alignment
37
+ import androidx.compose.ui.Modifier
38
+ import androidx.compose.ui.text.style.TextAlign
39
+ import androidx.compose.ui.text.style.TextOverflow
40
+ import androidx.compose.ui.unit.dp
41
+ import vn.momo.kits.application.IsShowBaseLineDebug
42
+ import vn.momo.kits.components.*
43
+ import vn.momo.kits.const.*
44
+ import vn.momo.kits.layout.getScreenLayout
45
+ import vn.momo.kits.modifier.InternalApi
46
+ import vn.momo.kits.modifier.activeOpacityClickable
47
+ import vn.momo.kits.modifier.conditional
48
+ import vn.momo.kits.modifier.setAutomationId
49
+
50
+ @InternalApi
51
+ const val BOTTOM_TAB_BAR_HEIGHT = 68
52
+
53
+ // Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
54
+ @Composable
55
+ internal fun BottomTabBar(
56
+ items: List<BottomTabItem>,
57
+ floatingButton: BottomTabFloatingButton? = null,
58
+ selectedIndex: Int,
59
+ onTabSelected: (Int) -> Unit,
60
+ ) {
61
+ val layout = getScreenLayout()
62
+ Box(
63
+ modifier = Modifier
64
+ .fillMaxWidth()
65
+ .padding(bottom = tabBarBottomGap(layout.insetBottom)),
66
+ contentAlignment = Alignment.BottomCenter,
67
+ ) {
68
+ HorizontalTabBar(
69
+ items = items,
70
+ floatingButton = floatingButton,
71
+ selectedIndex = selectedIndex,
72
+ onTabSelected = onTabSelected,
73
+ modifier = Modifier
74
+ .offset(x = (layout.insetLeft - layout.insetRight) / 2)
75
+ .width(
76
+ horizontalBarWidth(
77
+ layout.width, layout.height, layout.insetLeft, layout.insetRight,
78
+ items.size, hasCenterAction(floatingButton, items.size),
79
+ ),
80
+ ),
81
+ )
82
+ }
83
+ }
84
+
85
+ // Floating bar, items split evenly; Special type puts the center action in a notch, rising ctaLift above the bar.
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) { debugFrame() }
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
+ // text badges keep 5 characters, then "..." ("Khám phá" -> "Khám...")
250
+ private const val BADGE_MAX_CHARS = 5
251
+
252
+ // Badge value shown on a tab: null hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity),
253
+ // text keeps its first 5 characters.
254
+ internal fun tabBadgeLabel(item: BottomTabItem): String? {
255
+ val label = item.badgeLabel ?: return if (item.showDot) "" else null
256
+ if (label.isEmpty()) return ""
257
+ if (label.all { it in '0'..'9' }) {
258
+ val value = label.toLongOrNull() ?: Long.MAX_VALUE
259
+ if (value == 0L) return if (item.showDot) "" else null
260
+ return if (value > 99) "99+" else label
261
+ }
262
+ return if (label.length > BADGE_MAX_CHARS) label.take(BADGE_MAX_CHARS).trimEnd() + "..." else label
263
+ }
264
+
265
+ // 24 icon; badges hang off it unclipped: dot at 16/-2, label badge at 12/-7 growing right, or
266
+ // centered over the icon at -10 on the rail.
267
+ @Composable
268
+ internal fun TabIcon(item: BottomTabItem, tint: androidx.compose.ui.graphics.Color, vertical: Boolean) {
269
+ val badge = tabBadgeLabel(item)
270
+ Box(Modifier.size(TabBarMetrics.iconSize)) {
271
+ Icon(source = item.icon, size = TabBarMetrics.iconSize, color = tint)
272
+ when {
273
+ badge == null -> Unit
274
+ badge.isEmpty() -> BadgeDot(
275
+ size = DotSize.Small,
276
+ modifier = Modifier.offset(x = 16.dp, y = -Spacing.XXS),
277
+ )
278
+ vertical -> TabBadge(
279
+ badge,
280
+ Modifier.matchParentSize()
281
+ .wrapContentSize(Alignment.TopCenter, unbounded = true)
282
+ .offset(y = (-10).dp),
283
+ )
284
+ else -> TabBadge(
285
+ badge,
286
+ Modifier.matchParentSize()
287
+ .wrapContentSize(Alignment.TopStart, unbounded = true)
288
+ .offset(x = Spacing.M, y = (-7).dp),
289
+ )
290
+ }
291
+ }
292
+ }
293
+
294
+ private val BADGE_BORDER = 1.dp
295
+
296
+ // Numbers use the error color, text the warning color (Figma Badge round numeric / text); the text keeps
297
+ // its design size so it fits the 16 height on the Duo displays too.
298
+ @Composable
299
+ private fun TabBadge(label: String, modifier: Modifier) {
300
+ val colors = AppTheme.current.colors
301
+ val isNumber = label.trimEnd('+').let { it.isNotEmpty() && it.all { c -> c in '0'..'9' } }
302
+ Box(
303
+ modifier = modifier
304
+ .height(16.dp)
305
+ .widthIn(min = 16.dp, max = TabBarMetrics.badgeMaxWidth)
306
+ // the 1 ring is drawn under the label: Modifier.border would paint over the text
307
+ .background(colors.background.surface, CircleShape)
308
+ .padding(BADGE_BORDER)
309
+ .background(if (isNumber) colors.error.primary else colors.warning.primary, CircleShape)
310
+ .padding(horizontal = Spacing.XS - BADGE_BORDER),
311
+ contentAlignment = Alignment.Center,
312
+ ) {
313
+ ScaleSizeScope(1f) {
314
+ Text(
315
+ text = label,
316
+ style = Typography.actionXxsBold,
317
+ color = Colors.black_01,
318
+ maxLines = 1,
319
+ overflow = TextOverflow.Ellipsis,
320
+ )
321
+ }
322
+ }
323
+ }
324
+
325
+ // Baseline-debug outline drawn behind the content: Modifier.border paints over the badge hanging past the frame.
326
+ private fun Modifier.debugFrame(): Modifier {
327
+ return drawBehind { drawRect(Colors.blue_03, style = Stroke(1.dp.toPx())) }
328
+ }
329
+
330
+ // Center action press: the button shrinks while held; the label stays plain text.
331
+ @Composable
332
+ internal fun rememberCenterActionPress(): Pair<MutableInteractionSource, Boolean> {
333
+ val interactionSource = remember { MutableInteractionSource() }
334
+ val pressed by interactionSource.collectIsPressedAsState()
335
+ return interactionSource to pressed
336
+ }
337
+
338
+ @Composable
339
+ internal fun Modifier.centerActionPressScale(pressed: Boolean): Modifier {
340
+ val scale by animateFloatAsState(
341
+ if (pressed) TabBarMotion.CTA_PRESSED_SCALE else 1f,
342
+ tween(TabBarMotion.CTA_PRESS_MILLIS, easing = inOutQuad),
343
+ label = "CenterActionPress",
344
+ )
345
+ return graphicsLayer {
346
+ scaleX = scale
347
+ scaleY = scale
348
+ }
349
+ }
350
+
351
+ @Composable
352
+ internal fun Modifier.centerActionButton(size: androidx.compose.ui.unit.Dp, pressed: Boolean): Modifier {
353
+ return centerActionPressScale(pressed)
354
+ .size(size)
355
+ .then(CtaShadows.fold(Modifier as Modifier) { acc, shadow -> acc.spreadShadow(CircleShape, shadow) })
356
+ .background(AppTheme.current.colors.primary, CircleShape)
357
+ .border(1.dp, Color.White.copy(alpha = TabBarMetrics.ctaBorderOpacity), CircleShape)
358
+ }
359
+
360
+ @Composable
361
+ internal fun CenterActionLabel(label: String, overlay: (@Composable () -> Unit)?, vertical: Boolean) {
362
+ val colors = AppTheme.current.colors
363
+ Box(
364
+ modifier = Modifier
365
+ .then(if (vertical) Modifier else Modifier.heightIn(min = TabBarMetrics.ctaLabelHeight))
366
+ .padding(horizontal = if (vertical) Spacing.XS else Spacing.XXS),
367
+ contentAlignment = Alignment.Center,
368
+ ) {
369
+ Text(
370
+ text = label,
371
+ style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
372
+ color = colors.text.secondary,
373
+ textAlign = TextAlign.Center,
374
+ maxLines = 1,
375
+ overflow = TextOverflow.Ellipsis,
376
+ )
377
+ overlay?.let {
378
+ Box(Modifier.matchParentSize().wrapContentSize(Alignment.Center, unbounded = true)) { it() }
379
+ }
380
+ }
381
+ }
382
+
383
+ // Center action (.Nav/CTA): button rising out of the notch, label under it.
384
+ @Composable
385
+ private fun CenterAction(data: BottomTabFloatingButton, modifier: Modifier) {
386
+ val (interactionSource, pressed) = rememberCenterActionPress()
387
+ Column(
388
+ modifier = modifier
389
+ .width(TabBarMetrics.ctaSlotWidth)
390
+ .conditional(IsShowBaseLineDebug) { debugFrame() }
391
+ .clickable(interactionSource = interactionSource, indication = null, onClick = data.onPress)
392
+ .setAutomationId(data.label),
393
+ horizontalAlignment = Alignment.CenterHorizontally,
394
+ verticalArrangement = Arrangement.spacedBy(TabBarMetrics.ctaLabelGap),
395
+ ) {
396
+ Box(Modifier.centerActionButton(TabBarMetrics.ctaSize, pressed), contentAlignment = Alignment.Center) {
397
+ val iconContent = data.iconContent
398
+ if (iconContent != null) {
399
+ // custom content (e.g. an oversized Lottie) is clipped to the round button
400
+ Box(Modifier.size(TabBarMetrics.ctaSize).clip(CircleShape), contentAlignment = Alignment.Center) {
401
+ iconContent()
402
+ }
403
+ } else {
404
+ Icon(source = data.icon, color = Colors.black_01, size = TabBarMetrics.ctaIconSize)
405
+ }
406
+ }
407
+ CenterActionLabel(data.label, data.labelContent, vertical = false)
408
+ }
409
+ }
@@ -0,0 +1,111 @@
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.ui.graphics.drawOutline
23
+ import androidx.compose.ui.graphics.drawscope.Stroke
24
+ import androidx.compose.ui.draw.drawBehind
25
+ import androidx.compose.runtime.Composable
26
+ import vn.momo.kits.const.AppTheme
27
+
28
+ // Rounded container, with the notch dipped into the top edge around `notchCenterX` (from the left).
29
+ internal class NotchedBarShape(
30
+ private val radius: Dp,
31
+ private val notchCenterX: Dp? = null,
32
+ ) : Shape {
33
+ override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
34
+ val r = minOf(with(density) { radius.toPx() }, size.height / 2, size.width / 2)
35
+ val path = Path()
36
+ if (notchCenterX == null) {
37
+ path.addRoundRect(RoundRect(Rect(0f, 0f, size.width, size.height), CornerRadius(r)))
38
+ return Outline.Generic(path)
39
+ }
40
+ val cx = with(density) { notchCenterX.toPx() }
41
+ val unit = density.density
42
+ path.apply {
43
+ moveTo(r, 0f)
44
+ lineTo(cx - NOTCH_HALF_WIDTH * unit, 0f)
45
+ NOTCH_CURVES.forEach { (c1, c2, end) ->
46
+ cubicTo(
47
+ cx + c1.first * unit, c1.second * unit,
48
+ cx + c2.first * unit, c2.second * unit,
49
+ cx + end.first * unit, end.second * unit,
50
+ )
51
+ }
52
+ lineTo(size.width - r, 0f)
53
+ arcTo(Rect(size.width - 2 * r, 0f, size.width, 2 * r), -90f, 90f, false)
54
+ lineTo(size.width, size.height - r)
55
+ arcTo(Rect(size.width - 2 * r, size.height - 2 * r, size.width, size.height), 0f, 90f, false)
56
+ lineTo(r, size.height)
57
+ arcTo(Rect(0f, size.height - 2 * r, 2 * r, size.height), 90f, 90f, false)
58
+ lineTo(0f, r)
59
+ arcTo(Rect(0f, 0f, 2 * r, 2 * r), 180f, 90f, false)
60
+ close()
61
+ }
62
+ return Outline.Generic(path)
63
+ }
64
+ }
65
+
66
+ // The shape shrunk by `inset` on every side. A shadow cast from it with no spread is a shadow of the
67
+ // shape with spread -inset; dropShadow's own negative spread clips the blur of path outlines.
68
+ internal class InsetShape(private val shape: Shape, private val inset: Dp) : Shape {
69
+ override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
70
+ val insetPx = with(density) { inset.toPx() }
71
+ val inner = Size((size.width - 2 * insetPx).coerceAtLeast(0f), (size.height - 2 * insetPx).coerceAtLeast(0f))
72
+ val path = Path().apply {
73
+ addOutline(shape.createOutline(inner, layoutDirection, density))
74
+ translate(Offset(insetPx, insetPx))
75
+ }
76
+ return Outline.Generic(path)
77
+ }
78
+ }
79
+
80
+ // Shadow with a negative spread, cast from the shrunk shape.
81
+ internal fun Modifier.spreadShadow(shape: Shape, shadow: Shadow): Modifier {
82
+ if (shadow.spread < 0.dp) {
83
+ return dropShadow(
84
+ InsetShape(shape, -shadow.spread),
85
+ Shadow(radius = shadow.radius, color = shadow.color, offset = shadow.offset, alpha = shadow.alpha),
86
+ )
87
+ }
88
+ return dropShadow(shape, shadow)
89
+ }
90
+
91
+ // Floating shadow follows the shape (Figma Shadow/floating: 12% blur 24, 4% y12 blur 32 spread -16).
92
+ @Composable
93
+ internal fun Modifier.tabBarContainer(shape: Shape): Modifier {
94
+ val borderColor = AppTheme.current.colors.border.default
95
+ return dropShadow(shape, Shadow(radius = 24.dp, color = Color.Black, alpha = 0.12f))
96
+ .spreadShadow(
97
+ shape,
98
+ Shadow(radius = 32.dp, spread = (-16).dp, color = Color.Black, alpha = 0.04f, offset = DpOffset(0.dp, 12.dp)),
99
+ )
100
+ .background(
101
+ AppTheme.current.colors.background.surface.copy(alpha = TabBarMetrics.backgroundOpacity),
102
+ shape,
103
+ )
104
+ // Figma .Nav/Background: 1px light-gray hairline defining the pill edge, drawn under the items
105
+ // (Modifier.border paints over children, cutting a badge that reaches the rounded end)
106
+ .drawBehind {
107
+ val hairline = 1.dp.toPx()
108
+ val outline = InsetShape(shape, 0.5.dp).createOutline(size, layoutDirection, this)
109
+ drawOutline(outline, borderColor, style = Stroke(hairline))
110
+ }
111
+ }
@@ -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
+ }