@momo-kits/native-kits 0.168.1-beta.32-debug → 0.168.1-beta.33-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +1 -0
- package/compose/build.gradle.kts +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +2 -3
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +26 -34
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +167 -319
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +71 -79
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +326 -93
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +1 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +2 -3
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/ios/Input/Input.swift +3 -1
- package/ios/Input/InputTextArea.swift +3 -1
- package/ios/Navigation/BottomTab/BottomTab.swift +67 -48
- package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -281
- package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
- package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -72
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/StackScreen.swift +1 -3
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -272
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +90 -0
- package/package.json +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -106
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
- package/ios-demo/Resources/tabbar_scan_qr_button.json +0 -1
- package/ios-demo/Resources/tabbar_scan_qr_label.json +0 -1
|
@@ -1,68 +1,106 @@
|
|
|
1
1
|
package vn.momo.kits.navigation.bottomtab
|
|
2
2
|
|
|
3
|
+
import androidx.compose.foundation.background
|
|
4
|
+
import androidx.compose.foundation.border
|
|
3
5
|
import androidx.compose.foundation.clickable
|
|
6
|
+
import androidx.compose.foundation.combinedClickable
|
|
7
|
+
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
4
8
|
import androidx.compose.foundation.layout.Arrangement
|
|
5
9
|
import androidx.compose.foundation.layout.Box
|
|
6
10
|
import androidx.compose.foundation.layout.BoxScope
|
|
7
11
|
import androidx.compose.foundation.layout.Column
|
|
12
|
+
import androidx.compose.foundation.layout.Row
|
|
13
|
+
import androidx.compose.foundation.layout.absolutePadding
|
|
14
|
+
import androidx.compose.foundation.layout.fillMaxHeight
|
|
15
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
16
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
8
17
|
import androidx.compose.foundation.layout.height
|
|
9
18
|
import androidx.compose.foundation.layout.offset
|
|
10
19
|
import androidx.compose.foundation.layout.padding
|
|
11
20
|
import androidx.compose.foundation.layout.size
|
|
12
21
|
import androidx.compose.foundation.layout.width
|
|
13
|
-
import androidx.compose.foundation.layout.
|
|
14
|
-
import androidx.compose.foundation.layout.
|
|
22
|
+
import androidx.compose.foundation.layout.widthIn
|
|
23
|
+
import androidx.compose.foundation.layout.wrapContentSize
|
|
15
24
|
import androidx.compose.foundation.shape.CircleShape
|
|
16
25
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
17
26
|
import androidx.compose.runtime.Composable
|
|
27
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
18
28
|
import androidx.compose.runtime.compositionLocalOf
|
|
29
|
+
import androidx.compose.runtime.getValue
|
|
30
|
+
import androidx.compose.runtime.mutableStateOf
|
|
31
|
+
import androidx.compose.runtime.remember
|
|
32
|
+
import androidx.compose.runtime.setValue
|
|
19
33
|
import androidx.compose.ui.AbsoluteAlignment
|
|
20
34
|
import androidx.compose.ui.Alignment
|
|
21
35
|
import androidx.compose.ui.Modifier
|
|
36
|
+
import androidx.compose.ui.composed
|
|
37
|
+
import androidx.compose.ui.draw.clip
|
|
38
|
+
import androidx.compose.ui.draw.shadow
|
|
22
39
|
import androidx.compose.ui.graphics.Color
|
|
40
|
+
import androidx.compose.ui.graphics.Shape
|
|
41
|
+
import androidx.compose.ui.graphics.graphicsLayer
|
|
42
|
+
import androidx.compose.ui.layout.onSizeChanged
|
|
23
43
|
import androidx.compose.ui.platform.LocalDensity
|
|
24
44
|
import androidx.compose.ui.semantics.Role
|
|
25
|
-
import androidx.compose.ui.semantics.
|
|
26
|
-
import androidx.compose.ui.
|
|
27
|
-
import androidx.compose.ui.semantics.selected
|
|
28
|
-
import androidx.compose.ui.semantics.semantics
|
|
29
|
-
import vn.momo.kits.modifier.activeOpacityClickable
|
|
45
|
+
import androidx.compose.ui.semantics.clearAndSetSemantics
|
|
46
|
+
import androidx.compose.ui.text.style.TextOverflow
|
|
30
47
|
import androidx.compose.ui.unit.Dp
|
|
31
48
|
import androidx.compose.ui.unit.dp
|
|
49
|
+
import vn.momo.kits.application.LocalContext
|
|
50
|
+
import vn.momo.kits.application.MiniAppContext
|
|
51
|
+
import vn.momo.kits.components.Badge
|
|
52
|
+
import vn.momo.kits.components.BadgeDot
|
|
53
|
+
import vn.momo.kits.components.DotSize
|
|
32
54
|
import vn.momo.kits.components.Icon
|
|
55
|
+
import vn.momo.kits.components.Text
|
|
33
56
|
import vn.momo.kits.const.AppTheme
|
|
34
|
-
import vn.momo.kits.const.Colors
|
|
35
|
-
import vn.momo.kits.const.Radius
|
|
36
57
|
import vn.momo.kits.const.Spacing
|
|
58
|
+
import vn.momo.kits.const.Typography
|
|
37
59
|
import vn.momo.kits.layout.DuoMetrics
|
|
38
60
|
import vn.momo.kits.layout.ScreenLayout
|
|
39
61
|
import vn.momo.kits.layout.SideBarEdge
|
|
40
62
|
import vn.momo.kits.modifier.noFeedbackClickable
|
|
41
63
|
import vn.momo.kits.modifier.setAutomationId
|
|
64
|
+
import vn.momo.kits.navigation.LocalMaxApi
|
|
42
65
|
|
|
43
|
-
// Figma
|
|
44
|
-
private val
|
|
66
|
+
// Figma Fold-Design-System MT1/MT2, mirrored from RN DuoTabBar.tsx.
|
|
67
|
+
private val ITEM_SIZE = DuoMetrics.controlSize
|
|
68
|
+
private val ICON_SIZE = 28.dp
|
|
69
|
+
private val QR_ICON_SIZE = 24.dp
|
|
70
|
+
private val RAIL_PADDING = 6.dp
|
|
71
|
+
private val RAIL_GAP = Spacing.XXS
|
|
72
|
+
// selection bubble overflows the 48 rail cell by 5 above and below
|
|
73
|
+
private val RAIL_BUBBLE_WIDTH = 44.dp
|
|
74
|
+
private val RAIL_BUBBLE_HEIGHT = 58.dp
|
|
75
|
+
private val FLOATING_HEIGHT = DuoMetrics.floatingTabBarHeight
|
|
76
|
+
private val FLOATING_PADDING = Spacing.XS
|
|
77
|
+
// the system bar sizes its pill to the tabs instead of stretching it across the display
|
|
78
|
+
private val FLOATING_ITEM_WIDTH = 80.dp
|
|
79
|
+
// the rail's badge stays inside the capsule: its end sits XXS off the cell's end edge
|
|
80
|
+
private val RAIL_BADGE_MAX_WIDTH = ITEM_SIZE - Spacing.XXS * 2
|
|
81
|
+
private val RAIL_BADGE_END_OFFSET = (ITEM_SIZE - ICON_SIZE) / 2 - Spacing.XXS
|
|
82
|
+
// Figma Home-2026 tab bar "Selection": brand pink at 8%
|
|
83
|
+
private const val SELECTION_TINT_ALPHA = 0x14 / 255f
|
|
45
84
|
|
|
46
85
|
// Space from the window bottom the rail stack and its gap take, so the header side bar stays above it.
|
|
47
86
|
internal val LocalDuoRailReserve = compositionLocalOf { 0.dp }
|
|
48
87
|
|
|
49
|
-
// Rail
|
|
88
|
+
// Rail plus the QR button under it; compressed, the rail is a single button.
|
|
50
89
|
internal fun duoRailHeight(itemCount: Int, hasQr: Boolean, compressed: Boolean = false): Dp {
|
|
51
|
-
val rail = if (compressed)
|
|
52
|
-
else
|
|
53
|
-
return rail + if (hasQr)
|
|
90
|
+
val rail = if (compressed) ITEM_SIZE
|
|
91
|
+
else RAIL_PADDING * 2 + ITEM_SIZE * itemCount + RAIL_GAP * (itemCount - 1).coerceAtLeast(0)
|
|
92
|
+
return rail + if (hasQr) Spacing.M + ITEM_SIZE else 0.dp
|
|
54
93
|
}
|
|
55
94
|
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (layout.isIPhoneDuo && layout.sideBar != null) 0.dp
|
|
60
|
-
else TabBarMetrics.height + tabBarBottomGap(layout.insetBottom) + if (hasCenterAction) TabBarMetrics.ctaLift else 0.dp
|
|
95
|
+
// Overlaps the home indicator inset like the system tab bar (21pt above the bottom with a 34pt inset).
|
|
96
|
+
private fun floatingTabBarBottom(insetBottom: Dp): Dp =
|
|
97
|
+
maxOf(insetBottom - DuoMetrics.floatingTabBarInsetOverlap, Spacing.S)
|
|
61
98
|
|
|
62
|
-
//
|
|
63
|
-
internal
|
|
99
|
+
// Space tab content leaves under the floating bar; 0 when the rail sits in the side strip or off Duo.
|
|
100
|
+
internal fun duoFloatingTabBarInset(layout: ScreenLayout): Dp =
|
|
101
|
+
if (layout.isIPhoneDuo && layout.sideBar == null) FLOATING_HEIGHT + floatingTabBarBottom(layout.insetBottom) else 0.dp
|
|
64
102
|
|
|
65
|
-
// iPhone Duo tab bar: rail in the side bar, or
|
|
103
|
+
// iPhone Duo tab bar: rail in the side bar, or a floating bar when unfolded portrait.
|
|
66
104
|
@Composable
|
|
67
105
|
internal fun BoxScope.DuoTabBar(
|
|
68
106
|
layout: ScreenLayout,
|
|
@@ -71,27 +109,21 @@ internal fun BoxScope.DuoTabBar(
|
|
|
71
109
|
selectedIndex: Int,
|
|
72
110
|
onTabSelected: (Int) -> Unit,
|
|
73
111
|
compression: DuoBarCompression = DuoBarCompression(),
|
|
112
|
+
onTabLongPress: ((Int) -> Unit)? = null,
|
|
74
113
|
) {
|
|
114
|
+
val maxApi = LocalMaxApi.current
|
|
115
|
+
// a tick per tab the lens enters while dragged
|
|
116
|
+
val onTick = remember(maxApi) { { runCatching { maxApi?.triggerEventVibration("light", callback = null) }; Unit } }
|
|
75
117
|
if (layout.sideBar != null) {
|
|
76
|
-
DuoRailTabBar(layout, items, floatingButton, selectedIndex, onTabSelected, compression)
|
|
118
|
+
DuoRailTabBar(layout, items, floatingButton, selectedIndex, onTabSelected, compression, onTabLongPress, onTick)
|
|
77
119
|
} else {
|
|
78
|
-
|
|
79
|
-
items = items,
|
|
80
|
-
floatingButton = floatingButton,
|
|
81
|
-
selectedIndex = selectedIndex,
|
|
82
|
-
onTabSelected = onTabSelected,
|
|
83
|
-
fixedFontScale = true,
|
|
84
|
-
modifier = Modifier
|
|
85
|
-
.align(Alignment.BottomCenter)
|
|
86
|
-
.padding(bottom = tabBarBottomGap(layout.insetBottom))
|
|
87
|
-
.width(horizontalBarWidth(layout.width, layout.height, layout.insetLeft, layout.insetRight)),
|
|
88
|
-
)
|
|
120
|
+
DuoFloatingTabBar(layout, items, floatingButton, selectedIndex, onTabSelected, onTabLongPress, onTick)
|
|
89
121
|
}
|
|
90
122
|
}
|
|
91
123
|
|
|
92
|
-
// Vertical bar anchored to the bottom of the side bar,
|
|
93
|
-
// short it can shrink to one button showing the current tab (HIG "Tab bar compressed");
|
|
94
|
-
// expands the rail and compresses the toolbar.
|
|
124
|
+
// Vertical bar anchored to the bottom of the side bar, QR button below it (Figma MT1-C/E). When the
|
|
125
|
+
// side bar is short it can shrink to one button showing the current tab (HIG "Tab bar compressed");
|
|
126
|
+
// tapping it expands the rail and compresses the toolbar.
|
|
95
127
|
@Composable
|
|
96
128
|
private fun BoxScope.DuoRailTabBar(
|
|
97
129
|
layout: ScreenLayout,
|
|
@@ -100,104 +132,305 @@ private fun BoxScope.DuoRailTabBar(
|
|
|
100
132
|
selectedIndex: Int,
|
|
101
133
|
onTabSelected: (Int) -> Unit,
|
|
102
134
|
compression: DuoBarCompression,
|
|
135
|
+
onTabLongPress: ((Int) -> Unit)?,
|
|
136
|
+
onTick: () -> Unit,
|
|
103
137
|
) {
|
|
104
138
|
val sideBar = layout.sideBar ?: return
|
|
105
139
|
val isRight = sideBar.edge == SideBarEdge.RIGHT
|
|
106
140
|
|
|
107
|
-
// the rail lines up with the header buttons in the side bar: centered on a 48 lane kept Spacing.M
|
|
108
|
-
// from the strip's inner edge; the wider rail and center action overflow the lane evenly
|
|
109
141
|
Column(
|
|
110
142
|
modifier = Modifier
|
|
111
143
|
.align(if (isRight) AbsoluteAlignment.BottomRight else AbsoluteAlignment.BottomLeft)
|
|
112
144
|
.width(sideBar.width)
|
|
113
145
|
.padding(bottom = sideBar.bottom)
|
|
114
|
-
.absolutePadding(left = if (isRight) Spacing.M else 0.dp, right = if (isRight) 0.dp else Spacing.M)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
horizontalAlignment = Alignment.CenterHorizontally,
|
|
118
|
-
verticalArrangement = Arrangement.spacedBy(TabBarMetrics.railCtaGap),
|
|
146
|
+
.absolutePadding(left = if (isRight) Spacing.M else 0.dp, right = if (isRight) 0.dp else Spacing.M),
|
|
147
|
+
horizontalAlignment = if (isRight) AbsoluteAlignment.Left else AbsoluteAlignment.Right,
|
|
148
|
+
verticalArrangement = Arrangement.spacedBy(Spacing.M),
|
|
119
149
|
) {
|
|
120
150
|
val current = items.getOrNull(selectedIndex)
|
|
121
151
|
if (compression.tabBarCompressed && current != null) {
|
|
122
|
-
|
|
152
|
+
val interactionSource = remember { MutableInteractionSource() }
|
|
153
|
+
Box(
|
|
123
154
|
modifier = Modifier
|
|
124
|
-
.
|
|
125
|
-
.
|
|
126
|
-
.
|
|
155
|
+
.pressLift(interactionSource)
|
|
156
|
+
.size(ITEM_SIZE)
|
|
157
|
+
.tabBarMaterial(CircleShape)
|
|
158
|
+
.clickable(interactionSource = interactionSource, indication = null, onClick = compression.expandTabBar)
|
|
127
159
|
.setAutomationId("bottom_tab_bar"),
|
|
128
|
-
|
|
129
|
-
verticalArrangement = Arrangement.Center,
|
|
160
|
+
contentAlignment = Alignment.Center,
|
|
130
161
|
) {
|
|
131
|
-
|
|
162
|
+
DuoTabIcon(current, selected = true, badgeMaxWidth = RAIL_BADGE_MAX_WIDTH, inRail = true)
|
|
132
163
|
}
|
|
133
164
|
} else {
|
|
134
|
-
Rail(items, selectedIndex) {
|
|
165
|
+
Rail(items, selectedIndex, onTabLongPress, onTick) {
|
|
135
166
|
onTabSelected(it)
|
|
136
167
|
compression.onTabSelected()
|
|
137
168
|
}
|
|
138
169
|
}
|
|
139
170
|
if (floatingButton != null) {
|
|
140
|
-
|
|
171
|
+
QrButton(floatingButton, size = ITEM_SIZE)
|
|
141
172
|
}
|
|
142
173
|
}
|
|
143
174
|
}
|
|
144
175
|
|
|
145
|
-
// Column of
|
|
176
|
+
// Column of icon-only tab items with the sliding selection lens.
|
|
146
177
|
@Composable
|
|
147
|
-
private fun Rail(
|
|
148
|
-
|
|
178
|
+
private fun Rail(
|
|
179
|
+
items: List<BottomTabItem>,
|
|
180
|
+
selectedIndex: Int,
|
|
181
|
+
onTabLongPress: ((Int) -> Unit)?,
|
|
182
|
+
onTick: () -> Unit,
|
|
183
|
+
onItemClick: (Int) -> Unit,
|
|
184
|
+
) {
|
|
185
|
+
val selection = rememberDuoLiquidSelection(
|
|
186
|
+
count = items.size,
|
|
187
|
+
pitch = ITEM_SIZE + RAIL_GAP,
|
|
188
|
+
firstCenter = RAIL_PADDING + ITEM_SIZE / 2,
|
|
189
|
+
axis = LiquidAxis.Y,
|
|
190
|
+
index = selectedIndex,
|
|
191
|
+
onSelect = onItemClick,
|
|
192
|
+
onTick = onTick,
|
|
193
|
+
)
|
|
149
194
|
Box(
|
|
150
195
|
Modifier
|
|
151
|
-
.
|
|
152
|
-
.width(
|
|
153
|
-
.
|
|
154
|
-
.padding(horizontal = TabBarMetrics.railPaddingHorizontal)
|
|
155
|
-
.padding(bottom = TabBarMetrics.railPaddingBottom)
|
|
196
|
+
.then(selection.barTransform)
|
|
197
|
+
.width(ITEM_SIZE)
|
|
198
|
+
.tabBarMaterial(CircleShape)
|
|
156
199
|
.setAutomationId("bottom_tab_bar")
|
|
200
|
+
.then(selection.dragGesture)
|
|
157
201
|
) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
202
|
+
Box(
|
|
203
|
+
Modifier
|
|
204
|
+
.offset(
|
|
205
|
+
x = (ITEM_SIZE - RAIL_BUBBLE_WIDTH) / 2,
|
|
206
|
+
y = RAIL_PADDING - (RAIL_BUBBLE_HEIGHT - ITEM_SIZE) / 2,
|
|
207
|
+
)
|
|
208
|
+
.then(selection.bubbleTransform)
|
|
209
|
+
.size(RAIL_BUBBLE_WIDTH, RAIL_BUBBLE_HEIGHT)
|
|
210
|
+
.selectionTint()
|
|
163
211
|
)
|
|
164
|
-
Column
|
|
212
|
+
Column(
|
|
213
|
+
modifier = Modifier.padding(vertical = RAIL_PADDING),
|
|
214
|
+
verticalArrangement = Arrangement.spacedBy(RAIL_GAP),
|
|
215
|
+
) {
|
|
165
216
|
items.forEachIndexed { index, item ->
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
horizontalAlignment = Alignment.CenterHorizontally,
|
|
176
|
-
verticalArrangement = Arrangement.Center,
|
|
177
|
-
) {
|
|
178
|
-
TabItemContent(item, selected = index == selectedIndex, vertical = true, fixedFontScale = true)
|
|
217
|
+
LiquidTab(
|
|
218
|
+
selection = selection,
|
|
219
|
+
index = index,
|
|
220
|
+
onSelect = { onItemClick(index) },
|
|
221
|
+
onLongPress = onTabLongPress?.let { { it(index) } },
|
|
222
|
+
modifier = Modifier.size(ITEM_SIZE),
|
|
223
|
+
) { active ->
|
|
224
|
+
DuoTabIcon(item, active, badgeMaxWidth = RAIL_BADGE_MAX_WIDTH, inRail = true)
|
|
179
225
|
}
|
|
180
226
|
}
|
|
181
227
|
}
|
|
182
228
|
}
|
|
183
229
|
}
|
|
184
230
|
|
|
185
|
-
//
|
|
231
|
+
// Floating labelled bar for the unfolded portrait display, QR pinned in its own platter beside it.
|
|
186
232
|
@Composable
|
|
187
|
-
private fun
|
|
188
|
-
|
|
189
|
-
|
|
233
|
+
private fun BoxScope.DuoFloatingTabBar(
|
|
234
|
+
layout: ScreenLayout,
|
|
235
|
+
items: List<BottomTabItem>,
|
|
236
|
+
floatingButton: BottomTabFloatingButton?,
|
|
237
|
+
selectedIndex: Int,
|
|
238
|
+
onTabSelected: (Int) -> Unit,
|
|
239
|
+
onTabLongPress: ((Int) -> Unit)?,
|
|
240
|
+
onTick: () -> Unit,
|
|
241
|
+
) {
|
|
242
|
+
val density = LocalDensity.current
|
|
243
|
+
var rowWidth by remember { mutableStateOf(0.dp) }
|
|
244
|
+
val cellWidth = rowWidth / items.size.coerceAtLeast(1)
|
|
245
|
+
val selection = rememberDuoLiquidSelection(
|
|
246
|
+
count = items.size,
|
|
247
|
+
pitch = cellWidth,
|
|
248
|
+
firstCenter = cellWidth / 2,
|
|
249
|
+
axis = LiquidAxis.X,
|
|
250
|
+
index = selectedIndex,
|
|
251
|
+
onSelect = onTabSelected,
|
|
252
|
+
onTick = onTick,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
Row(
|
|
190
256
|
modifier = Modifier
|
|
191
|
-
.
|
|
192
|
-
.
|
|
193
|
-
.
|
|
194
|
-
|
|
257
|
+
.align(Alignment.BottomCenter)
|
|
258
|
+
.fillMaxWidth()
|
|
259
|
+
.absolutePadding(
|
|
260
|
+
left = layout.insetLeft + DuoMetrics.floatingTabBarMargin,
|
|
261
|
+
right = layout.insetRight + DuoMetrics.floatingTabBarMargin,
|
|
262
|
+
)
|
|
263
|
+
.padding(bottom = floatingTabBarBottom(layout.insetBottom)),
|
|
264
|
+
horizontalArrangement = Arrangement.spacedBy(Spacing.S, Alignment.CenterHorizontally),
|
|
265
|
+
) {
|
|
266
|
+
Box(
|
|
267
|
+
modifier = Modifier
|
|
268
|
+
.weight(1f, fill = false)
|
|
269
|
+
.width(FLOATING_ITEM_WIDTH * items.size + FLOATING_PADDING * 2)
|
|
270
|
+
.height(FLOATING_HEIGHT)
|
|
271
|
+
.then(selection.barTransform)
|
|
272
|
+
.tabBarMaterial(RoundedCornerShape(FLOATING_HEIGHT / 2))
|
|
273
|
+
.padding(FLOATING_PADDING)
|
|
274
|
+
.setAutomationId("bottom_tab_bar")
|
|
275
|
+
) {
|
|
276
|
+
Box(
|
|
277
|
+
Modifier
|
|
278
|
+
.fillMaxSize()
|
|
279
|
+
.onSizeChanged { rowWidth = with(density) { it.width.toDp() } }
|
|
280
|
+
.then(selection.dragGesture)
|
|
281
|
+
) {
|
|
282
|
+
if (rowWidth > 0.dp) {
|
|
283
|
+
Box(
|
|
284
|
+
Modifier
|
|
285
|
+
.then(selection.bubbleTransform)
|
|
286
|
+
.width(cellWidth)
|
|
287
|
+
.fillMaxHeight()
|
|
288
|
+
.selectionTint()
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
Row(Modifier.fillMaxSize()) {
|
|
292
|
+
items.forEachIndexed { index, item ->
|
|
293
|
+
LiquidTab(
|
|
294
|
+
selection = selection,
|
|
295
|
+
index = index,
|
|
296
|
+
onSelect = { onTabSelected(index) },
|
|
297
|
+
onLongPress = onTabLongPress?.let { { it(index) } },
|
|
298
|
+
modifier = Modifier.weight(1f).fillMaxHeight(),
|
|
299
|
+
) { active ->
|
|
300
|
+
FloatingCellContent(item, active, badgeMaxWidth = cellWidth / 2 - Spacing.XXS)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (floatingButton != null) {
|
|
307
|
+
QrButton(floatingButton, size = FLOATING_HEIGHT, Modifier.shadow(3.dp, CircleShape))
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// A tab drawn twice, inactive with the active layer over it fading in as the lens passes; the tab
|
|
313
|
+
// the lens lands on pops. A tap is the clickable's, a drag over the bar is the bar's.
|
|
314
|
+
@Composable
|
|
315
|
+
private fun LiquidTab(
|
|
316
|
+
selection: DuoLiquidSelection,
|
|
317
|
+
index: Int,
|
|
318
|
+
onSelect: () -> Unit,
|
|
319
|
+
onLongPress: (() -> Unit)?,
|
|
320
|
+
modifier: Modifier = Modifier,
|
|
321
|
+
content: @Composable (active: Boolean) -> Unit,
|
|
322
|
+
) {
|
|
323
|
+
val interactionSource = remember { MutableInteractionSource() }
|
|
324
|
+
val onLongClick = selection.rememberPressTracking(index, interactionSource, onSelect, onLongPress)
|
|
325
|
+
val pop = selection.rememberIconPop(index)
|
|
326
|
+
Box(
|
|
327
|
+
modifier = modifier
|
|
328
|
+
.combinedClickable(
|
|
329
|
+
interactionSource = interactionSource,
|
|
330
|
+
indication = null,
|
|
331
|
+
role = Role.Tab,
|
|
332
|
+
onLongClick = onLongClick,
|
|
333
|
+
onClick = onSelect,
|
|
334
|
+
)
|
|
335
|
+
.graphicsLayer {
|
|
336
|
+
scaleX = pop.value
|
|
337
|
+
scaleY = pop.value
|
|
338
|
+
},
|
|
339
|
+
contentAlignment = Alignment.Center,
|
|
340
|
+
) {
|
|
341
|
+
content(false)
|
|
342
|
+
Box(
|
|
343
|
+
Modifier
|
|
344
|
+
.matchParentSize()
|
|
345
|
+
.graphicsLayer { alpha = selection.activeAlpha(index) }
|
|
346
|
+
.clearAndSetSemantics {},
|
|
347
|
+
contentAlignment = Alignment.Center,
|
|
348
|
+
) {
|
|
349
|
+
content(true)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
@Composable
|
|
355
|
+
private fun FloatingCellContent(item: BottomTabItem, active: Boolean, badgeMaxWidth: Dp) {
|
|
356
|
+
val colors = AppTheme.current.colors
|
|
357
|
+
Column(
|
|
195
358
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
196
|
-
verticalArrangement = Arrangement.spacedBy(
|
|
359
|
+
verticalArrangement = Arrangement.spacedBy(Spacing.XXS),
|
|
197
360
|
) {
|
|
198
|
-
|
|
199
|
-
|
|
361
|
+
DuoTabIcon(item, active, badgeMaxWidth)
|
|
362
|
+
// like the system tab bar the label keeps its design size; Text grows it up to 5pt on the wide Duo displays
|
|
363
|
+
val context = LocalContext.current
|
|
364
|
+
val fixedScale = remember(context) {
|
|
365
|
+
(context ?: MiniAppContext()).copy(userScaleRate = 1f, useOSScaleRate = false)
|
|
366
|
+
}
|
|
367
|
+
CompositionLocalProvider(LocalContext provides fixedScale) {
|
|
368
|
+
Text(
|
|
369
|
+
text = item.label,
|
|
370
|
+
style = Typography.labelXsMedium,
|
|
371
|
+
color = if (active) colors.primary else colors.text.hint,
|
|
372
|
+
maxLines = 1,
|
|
373
|
+
overflow = TextOverflow.Ellipsis,
|
|
374
|
+
)
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private fun Modifier.selectionTint(): Modifier = composed {
|
|
380
|
+
background(AppTheme.current.colors.primary.copy(alpha = SELECTION_TINT_ALPHA), CircleShape)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Floating bar: the badge starts at the icon's center and grows toward the cell's end edge.
|
|
384
|
+
// Rail: the material clips to the capsule, so the badge ends just inside the rail and grows back
|
|
385
|
+
// over the icon (RN TabBarIcon `end: -3`). Either way it never resizes the icon box.
|
|
386
|
+
@Composable
|
|
387
|
+
private fun DuoTabIcon(item: BottomTabItem, selected: Boolean, badgeMaxWidth: Dp, inRail: Boolean = false) {
|
|
388
|
+
val colors = AppTheme.current.colors
|
|
389
|
+
val badgeLabel = item.badgeLabel?.takeUnless { it.toIntOrNull() == 0 }
|
|
390
|
+
Box {
|
|
391
|
+
Icon(
|
|
392
|
+
source = item.icon,
|
|
393
|
+
size = ICON_SIZE,
|
|
394
|
+
color = if (selected) colors.primary else colors.text.hint,
|
|
395
|
+
)
|
|
396
|
+
when {
|
|
397
|
+
badgeLabel == null && !item.showDot -> Unit
|
|
398
|
+
badgeLabel.isNullOrEmpty() -> BadgeDot(
|
|
399
|
+
size = DotSize.Small,
|
|
400
|
+
modifier = Modifier.align(Alignment.TopEnd),
|
|
401
|
+
)
|
|
402
|
+
else -> Badge(
|
|
403
|
+
badgeLabel,
|
|
404
|
+
modifier = Modifier
|
|
405
|
+
.matchParentSize()
|
|
406
|
+
.wrapContentSize(if (inRail) Alignment.TopEnd else Alignment.TopStart, unbounded = true)
|
|
407
|
+
.offset(x = if (inRail) RAIL_BADGE_END_OFFSET else ICON_SIZE / 2, y = -Spacing.XS)
|
|
408
|
+
.widthIn(max = badgeMaxWidth.coerceAtLeast(0.dp)),
|
|
409
|
+
)
|
|
200
410
|
}
|
|
201
|
-
CenterActionLabel(data.label, data.labelContent, vertical = true, fixedFontScale = true)
|
|
202
411
|
}
|
|
203
412
|
}
|
|
413
|
+
|
|
414
|
+
@Composable
|
|
415
|
+
private fun QrButton(data: BottomTabFloatingButton, size: Dp, modifier: Modifier = Modifier) {
|
|
416
|
+
Box(
|
|
417
|
+
modifier = modifier
|
|
418
|
+
.size(size)
|
|
419
|
+
.clip(CircleShape)
|
|
420
|
+
.background(AppTheme.current.colors.primary)
|
|
421
|
+
.noFeedbackClickable(onClick = data.onPress)
|
|
422
|
+
.setAutomationId(data.label),
|
|
423
|
+
contentAlignment = Alignment.Center,
|
|
424
|
+
) {
|
|
425
|
+
Icon(source = data.icon, color = Color.White, size = QR_ICON_SIZE)
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// RN BarMaterial: surface with a 1dp border.
|
|
430
|
+
@Composable
|
|
431
|
+
private fun Modifier.tabBarMaterial(shape: Shape): Modifier {
|
|
432
|
+
val colors = AppTheme.current.colors
|
|
433
|
+
return shadow(3.dp, shape)
|
|
434
|
+
.background(colors.background.surface)
|
|
435
|
+
.border(1.dp, colors.border.default, shape)
|
|
436
|
+
}
|
|
@@ -29,7 +29,6 @@ internal fun ComposeLottieAnimation(
|
|
|
29
29
|
isPlaying: Boolean,
|
|
30
30
|
onEvent: ((String) -> Unit)?,
|
|
31
31
|
modifier: Modifier,
|
|
32
|
-
progress: (() -> Float)? = null,
|
|
33
32
|
) {
|
|
34
33
|
val json = readJson(path)
|
|
35
34
|
|
|
@@ -56,7 +55,7 @@ internal fun ComposeLottieAnimation(
|
|
|
56
55
|
val lottieState = animateLottieCompositionAsState(
|
|
57
56
|
composition = composition,
|
|
58
57
|
iterations = iterations,
|
|
59
|
-
isPlaying = isPlaying
|
|
58
|
+
isPlaying = isPlaying,
|
|
60
59
|
restartOnPlay = false,
|
|
61
60
|
)
|
|
62
61
|
|
|
@@ -78,7 +77,7 @@ internal fun ComposeLottieAnimation(
|
|
|
78
77
|
Image(
|
|
79
78
|
painter = rememberLottiePainter(
|
|
80
79
|
composition = composition,
|
|
81
|
-
progress =
|
|
80
|
+
progress = lottieState::value,
|
|
82
81
|
dynamicProperties = dynamicProperties,
|
|
83
82
|
enableExpressions = false,
|
|
84
83
|
expressionEngineFactory = { _, _ ->
|
|
@@ -66,9 +66,7 @@ expect fun LottieAnimation(
|
|
|
66
66
|
isPlaying: Boolean = true,
|
|
67
67
|
onEvent: ((String) -> Unit)? = null,
|
|
68
68
|
modifier: Modifier = Modifier,
|
|
69
|
-
useCompose: Boolean = false
|
|
70
|
-
// drives the animation instead of playing it, so several animations stay in sync; needs useCompose
|
|
71
|
-
progress: (() -> Float)? = null,
|
|
69
|
+
useCompose: Boolean = false
|
|
72
70
|
)
|
|
73
71
|
|
|
74
72
|
expect fun NativePaint.setColor(
|
|
@@ -112,11 +112,10 @@ actual fun LottieAnimation(
|
|
|
112
112
|
isPlaying: Boolean,
|
|
113
113
|
onEvent: ((String) -> Unit)?,
|
|
114
114
|
modifier: Modifier,
|
|
115
|
-
useCompose: Boolean
|
|
116
|
-
progress: (() -> Float)?,
|
|
115
|
+
useCompose: Boolean
|
|
117
116
|
) {
|
|
118
117
|
if (useCompose) {
|
|
119
|
-
ComposeLottieAnimation(path, tintColor, bgColor, iterations, isPlaying, onEvent, modifier
|
|
118
|
+
ComposeLottieAnimation(path, tintColor, bgColor, iterations, isPlaying, onEvent, modifier)
|
|
120
119
|
return
|
|
121
120
|
}
|
|
122
121
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package vn.momo.kits.platform
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.DisposableEffect
|
|
5
|
+
import androidx.compose.runtime.mutableStateOf
|
|
6
|
+
import androidx.compose.runtime.remember
|
|
7
|
+
import kotlinx.cinterop.ExperimentalForeignApi
|
|
8
|
+
import kotlinx.cinterop.ObjCAction
|
|
9
|
+
import platform.Foundation.NSNotification
|
|
10
|
+
import platform.Foundation.NSNotificationCenter
|
|
11
|
+
import platform.Foundation.NSSelectorFromString
|
|
12
|
+
import platform.UIKit.UIAccessibilityIsReduceMotionEnabled
|
|
13
|
+
import platform.UIKit.UIAccessibilityReduceMotionStatusDidChangeNotification
|
|
14
|
+
import platform.darwin.NSObject
|
|
15
|
+
|
|
16
|
+
@OptIn(ExperimentalForeignApi::class)
|
|
17
|
+
@Composable
|
|
18
|
+
actual fun rememberReduceMotion(): Boolean {
|
|
19
|
+
val reduceMotion = remember { mutableStateOf(UIAccessibilityIsReduceMotionEnabled()) }
|
|
20
|
+
|
|
21
|
+
val listener = remember {
|
|
22
|
+
object : NSObject() {
|
|
23
|
+
@Suppress("unused")
|
|
24
|
+
@ObjCAction
|
|
25
|
+
fun reduceMotionChanged(arg: NSNotification) {
|
|
26
|
+
reduceMotion.value = UIAccessibilityIsReduceMotionEnabled()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
DisposableEffect(Unit) {
|
|
32
|
+
NSNotificationCenter.defaultCenter.addObserver(
|
|
33
|
+
observer = listener,
|
|
34
|
+
selector = NSSelectorFromString(listener::reduceMotionChanged.name + ":"),
|
|
35
|
+
name = UIAccessibilityReduceMotionStatusDidChangeNotification,
|
|
36
|
+
`object` = null,
|
|
37
|
+
)
|
|
38
|
+
onDispose {
|
|
39
|
+
NSNotificationCenter.defaultCenter.removeObserver(
|
|
40
|
+
observer = listener,
|
|
41
|
+
name = UIAccessibilityReduceMotionStatusDidChangeNotification,
|
|
42
|
+
`object` = null,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return reduceMotion.value
|
|
48
|
+
}
|
package/ios/Input/Input.swift
CHANGED
|
@@ -252,7 +252,9 @@ public struct Input: View {
|
|
|
252
252
|
}
|
|
253
253
|
.padding(.horizontal, Spacing.S)
|
|
254
254
|
.background(theme.colors.background.surface)
|
|
255
|
-
|
|
255
|
+
// A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
|
|
256
|
+
.fixedSize(horizontal: false, vertical: true)
|
|
257
|
+
.frame(height: 0)
|
|
256
258
|
.offset(x: Spacing.S)
|
|
257
259
|
}
|
|
258
260
|
}
|
|
@@ -279,7 +279,9 @@ public struct InputTextArea: View {
|
|
|
279
279
|
}
|
|
280
280
|
.padding(.horizontal, Spacing.S)
|
|
281
281
|
.background(theme.colors.background.surface)
|
|
282
|
-
|
|
282
|
+
// A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
|
|
283
|
+
.fixedSize(horizontal: false, vertical: true)
|
|
284
|
+
.frame(height: 0)
|
|
283
285
|
.offset(x: Spacing.S)
|
|
284
286
|
}
|
|
285
287
|
}
|