@momo-kits/native-kits 0.168.1-beta.25-debug → 0.168.1-beta.26-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 CHANGED
@@ -77,12 +77,11 @@ Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do
77
77
  - iPhone Duo with a side strip ≥ 60pt: back + toolkit leave the bar for `HeaderSideBar` (`navigation/component/SideBar.kt`, 48pt glass controls); custom header-right stays in the bar. `sideBar.top` is 170pt in portrait, 120pt on the inner display in landscape (height ≥ 600), 24pt on the outer display in landscape, or below the header when the status bar is on top; UIKit's `statusBarFrame` is useless on Duo. Unlike RN the column is clamped above footer (24pt gap) / rail (12pt gap).
78
78
  - Reserved regions (iOS 27.1 `reservedRegionsOfKind:`, reached through the ObjC runtime so older SDKs still build): a probe `UIView` (`platform/ReservedRegions.ios.kt` on the Compose root view; `ReservedRegionsProbe` inside SwiftUI `momoScreenLayout()`) re-reads them in `layoutSubviews`, which UIKit re-runs when they change. They push `sideBar.top` below the status cluster as it grows for calls / Live Activities, and `sideBar.bottom` (≥ 24pt) above a camera at the bottom end of the strip.
79
79
  - Tab bar on Duo is `bottomtab/DuoTabBar.kt`: a rail in the side strip (`sideBar.bottom` above the window bottom, QR below it) or, without a side bar, a floating bar spanning 6/8 grid columns. Both overlay the content; `duoFloatingTabBarInset` pads tab content, footer and FAB.
80
- - Duo tab selection motion (`bottomtab/DuoLiquidSelection.kt` / `ios/Navigation/BottomTab/DuoLiquidSelection.swift`, port of RN `useLiquidSelection.ts`, momo-kits !682): press lifts the lens, a drag past 10pt takes over (Compose: the bar's `pointerInput` consumes and so cancels the tab's clickable; SwiftUI: one `DragGesture` over the bar, tabs are not `Button`s), long press calls `BottomTab(onTabLongPress)` and release still selects, Reduce Motion (`platform/ReduceMotion`) falls back to a plain slide. SwiftUI integrates the lens spring on a display link because the stretch and the tabs' active tint read it every frame. Constants mirror RN — change both together.
81
80
  - Bar compression (`bottomtab/DuoBarCompression.kt`, HIG "Vertical controls"): when toolbar + rail don't fit in the strip, one is compressed — the toolkit into a `navigation_menu` button, the rail into one button showing the current tab — and tapping it swaps them; `BottomTab(compressionBehavior)` picks which starts compressed. If neither fits beside the other compressed, both rest compressed and a tap opens one for a moment. Side bar columns report their full height (0 when the screen puts nothing there) so the decision follows each screen's toolkit.
82
81
  - Glass header: on Duo with a side bar, Default/Extended headers without search and with a `ScrollState` let content scroll under the bar (`usesDuoGlassHeader`); the bar fades in a translucent surface + hairline over 16pt (Compose has no backdrop blur — RN's fallback look), the gradient leaves with the content.
83
82
  - Quick return header: glass headers and Animated headers (with a `ScrollState`) on the Duo side bar layout slide out with the content and back in on a reverse scroll; a half-shown header settles in or out once the scroll stops. The side bar is drawn apart from the header, so it stays put.
84
83
  - Overlays on Duo: the modal sits inside the safe area (all four insets, so clear of the side toolbar strip) and caps its content at `duoModalMaxWidth` / `duoModalMaxHeight` (440 × 640pt, at least XL off the safe area); popups fill that width with radius XL and drop their own side padding (body scrolls, actions stay). Snackbars keep clear of the strip.
85
- - Bottom sheet on Duo: radius XL, window height less `duoTopInset` (it never passes the side status bar: unlike RN, nothing restyles the clock over it), centered when the short side ≥ 600 (inner display in either orientation, buttons stay in the header row; RN parity). Below that (outer display, landscape too) it floats `Spacing.M` off the side edges, pads header/content/footer by `inset − M`, and a `Title` header moves back / close into 48pt side bar buttons on the strip part of the sheet (HIG: sheet controls go vertical on the outer display) when the strip fits one; they follow the header row while the sheet is short and stay below `sideBar.top` when it is tall. `BottomHeader.Title(onBack)` / `.title(onBack:)` closes the sheet, then runs (RN `leftOptions.onPressIconLeft`).
84
+ - Bottom sheet on Duo: radius XL, window height less `duoTopInset` (it never passes the side status bar: unlike RN, nothing restyles the clock over it), centered when the short side ≥ 600 (inner display in either orientation, buttons stay in the header row; RN parity). Below that (outer display, landscape too) it floats `Spacing.M` off the side edges, pads header/content/footer by `inset − M` (the drag indicator still centers on the whole sheet), and a `Title` header moves back / close into 48pt side bar buttons on the strip part of the sheet (HIG: sheet controls go vertical on the outer display) when the strip fits one; they follow the header row while the sheet is short and stay below `sideBar.top` when it is tall. `BottomHeader.Title(onBack)` / `.title(onBack:)` closes the sheet, then runs (RN `leftOptions.onPressIconLeft`).
86
85
  - Font scale deliberately uses the short side (`min(w, h)`), unlike RN which reads the window width — landscape must not inflate every font.
87
86
  - Font scale measures the **window**, never `UIScreen.main`: on iPhone Duo the main screen stays on one display while the window follows the one in use. Compose iOS `getScreenDimensions()` reads `LocalWindowInfo.containerSize` (recomposes on fold/unfold); SwiftUI `DesignSystemKits` KVO-observes each `UIWindowScene.effectiveGeometry` and republishes `windowShortSide`.
88
87
  - `StackScreen` pads content/footer/search/FAB by the side insets and provides an inset-consumed layout to its content; a bottom-tab root stays full width (tab bar + each tab's StackScreen handle insets). Grid columns use `contentWidth`.
@@ -40,7 +40,7 @@ kotlin {
40
40
  }
41
41
 
42
42
  cocoapods {
43
- version = "0.168.1-beta.25-debug"
43
+ version = "0.168.1-beta.26-debug"
44
44
  summary = "IOS Shared module"
45
45
  homepage = "https://momo.vn"
46
46
  ios.deploymentTarget = "15.0"
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |spec|
2
2
  spec.name = 'compose'
3
- spec.version = '0.168.1-beta.8-debug'
3
+ spec.version = '0.168.1-beta.24-debug'
4
4
  spec.homepage = 'https://momo.vn'
5
5
  spec.source = { :http=> ''}
6
6
  spec.authors = ''
@@ -276,10 +276,10 @@ internal fun BottomSheet(
276
276
  }
277
277
  }
278
278
  ) {
279
+ // the indicator centers on the whole sheet, only the header row keeps clear of the strip
279
280
  Column(
280
281
  modifier = Modifier
281
282
  .fillMaxSize()
282
- .padding(sidePadding)
283
283
  .padding(horizontal = Spacing.M),
284
284
  horizontalAlignment = Alignment.CenterHorizontally
285
285
  ) {
@@ -294,7 +294,10 @@ internal fun BottomSheet(
294
294
  )
295
295
  )
296
296
  Spacer(Modifier.height(4.dp))
297
- Box(Modifier.fillMaxWidth().height(HEADER_ROW_HEIGHT), contentAlignment = Alignment.Center){
297
+ Box(
298
+ Modifier.padding(sidePadding).fillMaxWidth().height(HEADER_ROW_HEIGHT),
299
+ contentAlignment = Alignment.Center
300
+ ) {
298
301
  when (header) {
299
302
  is BottomHeader.Title -> BottomSheetTitle(
300
303
  text = header.data,
@@ -72,8 +72,6 @@ fun BottomTab(
72
72
  initialRouteName: String? = null,
73
73
  onTabPress: ((index: Int, switchTab: () -> Unit) -> Unit)? = null,
74
74
  backToInitialTab: Boolean = true,
75
- // RN tabLongPress; on iPhone Duo the held tab is still selected on release
76
- onTabLongPress: ((index: Int) -> Unit)? = null,
77
75
  ) {
78
76
  val navigation = LocalNavigation.current
79
77
  val navigator = LocalNavigator.current
@@ -197,7 +195,6 @@ fun BottomTab(
197
195
  selectedIndex = selectedIndex,
198
196
  onTabSelected = onTabSelected,
199
197
  compression = compression,
200
- onTabLongPress = onTabLongPress,
201
198
  )
202
199
  } else {
203
200
  Column {
@@ -206,7 +203,6 @@ fun BottomTab(
206
203
  floatingButton = floatingButton,
207
204
  selectedIndex = selectedIndex,
208
205
  onTabSelected = onTabSelected,
209
- onTabLongPress = onTabLongPress,
210
206
  )
211
207
  Spacer(modifier = Modifier.fillMaxWidth().height(AppNavigationBar.current + Spacing.S).background(AppTheme.current.colors.background.surface))
212
208
  }
@@ -1,12 +1,8 @@
1
1
  package vn.momo.kits.navigation.bottomtab
2
2
 
3
3
  import androidx.compose.animation.core.Animatable
4
- import androidx.compose.animation.core.animateFloatAsState
5
4
  import androidx.compose.foundation.background
6
5
  import androidx.compose.foundation.border
7
- import androidx.compose.foundation.combinedClickable
8
- import androidx.compose.foundation.interaction.MutableInteractionSource
9
- import androidx.compose.foundation.interaction.collectIsPressedAsState
10
6
  import androidx.compose.foundation.layout.*
11
7
  import androidx.compose.foundation.shape.CircleShape
12
8
  import androidx.compose.foundation.shape.RoundedCornerShape
@@ -22,8 +18,6 @@ import androidx.compose.ui.Modifier
22
18
  import androidx.compose.ui.draw.clip
23
19
  import androidx.compose.ui.graphics.Brush
24
20
  import androidx.compose.ui.graphics.Color
25
- import androidx.compose.ui.graphics.graphicsLayer
26
- import androidx.compose.ui.semantics.Role
27
21
  import androidx.compose.ui.text.style.TextAlign
28
22
  import androidx.compose.ui.text.style.TextOverflow
29
23
  import androidx.compose.ui.unit.Dp
@@ -47,7 +41,6 @@ internal fun BottomTabBar(
47
41
  floatingButton: BottomTabFloatingButton? = null,
48
42
  selectedIndex: Int,
49
43
  onTabSelected: (Int) -> Unit,
50
- onTabLongPress: ((Int) -> Unit)? = null,
51
44
  ) {
52
45
 
53
46
  val layout = getScreenLayout()
@@ -80,11 +73,11 @@ internal fun BottomTabBar(
80
73
  horizontalArrangement = Arrangement.SpaceAround,
81
74
  ) {
82
75
  if (floating == null) {
83
- RenderTabBarItem(items, 0, items.size, selectedIndex, onTabSelected, onTabLongPress)
76
+ RenderTabBarItem(items, 0, items.size, selectedIndex, onTabSelected)
84
77
  } else {
85
- RenderTabBarItem(items, 0, mid, selectedIndex, onTabSelected, onTabLongPress)
78
+ RenderTabBarItem(items, 0, mid, selectedIndex, onTabSelected)
86
79
  Spacer(modifier = Modifier.width(slotWidth))
87
- RenderTabBarItem(items, mid, items.size, selectedIndex, onTabSelected, onTabLongPress)
80
+ RenderTabBarItem(items, mid, items.size, selectedIndex, onTabSelected)
88
81
  }
89
82
  }
90
83
 
@@ -122,48 +115,37 @@ internal fun RowScope.RenderTabBarItem(
122
115
  fromIndex: Int,
123
116
  toIndex: Int,
124
117
  selectedIndex: Int,
125
- onTabSelected: (Int) -> Unit,
126
- onTabLongPress: ((Int) -> Unit)? = null,
118
+ onTabSelected: (Int) -> Unit
127
119
  ){
128
120
  for (index in fromIndex until toIndex) {
129
121
  Box(modifier = Modifier.weight(1f)) {
130
122
  TabBarItem(
131
123
  item = items[index],
132
124
  selected = index == selectedIndex,
133
- onClick = { onTabSelected(index) },
134
- onLongClick = onTabLongPress?.let { { it(index) } },
125
+ onClick = { onTabSelected(index) }
135
126
  )
136
127
  }
137
128
  }
138
129
  }
139
130
 
140
131
  @Composable
141
- internal fun TabBarItem(item: BottomTabItem, selected: Boolean, onClick: () -> Unit, onLongClick: (() -> Unit)? = null) {
132
+ internal fun TabBarItem(item: BottomTabItem, selected: Boolean, onClick: () -> Unit) {
142
133
  // RN parity: "0" hides the badge, "" renders a dot.
143
134
  val badgeLabel = item.badgeLabel?.takeUnless { it.toIntOrNull() == 0 }
135
+ val isNumber = badgeLabel?.toIntOrNull() != null
144
136
  val showDot = badgeLabel?.isEmpty() ?: item.showDot
145
- val interactionSource = remember { MutableInteractionSource() }
146
- val pressed by interactionSource.collectIsPressedAsState()
147
- val alpha by animateFloatAsState(if (pressed) 0.2f else 1f, label = "TabBarItemOpacity")
148
137
 
149
- BoxWithConstraints(modifier = Modifier
138
+ Box(modifier = Modifier
150
139
  .fillMaxSize()
151
140
  .padding(horizontal = Spacing.XXS)
152
141
  .conditional(IsShowBaseLineDebug) {
153
142
  border(1.dp, Colors.blue_03)
154
143
  }
155
- .graphicsLayer { this.alpha = alpha }
156
- .combinedClickable(
157
- interactionSource = interactionSource,
158
- indication = null,
159
- role = Role.Tab,
160
- onLongClick = onLongClick,
161
- onClick = onClick,
162
- ),
144
+ .activeOpacityClickable {
145
+ onClick()
146
+ },
163
147
  contentAlignment = Alignment.BottomStart
164
148
  ){
165
- // from the icon's center to the cell's end edge
166
- val badgeMaxWidth = (maxWidth / 2 - Spacing.XXS).coerceAtLeast(0.dp)
167
149
  Column(
168
150
  modifier = Modifier
169
151
  .fillMaxSize()
@@ -176,13 +158,11 @@ internal fun TabBarItem(item: BottomTabItem, selected: Boolean, onClick: () -> U
176
158
  source = item.icon,
177
159
  size = 28.dp,
178
160
  color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint)
161
+ val badgeAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopEnd, unbounded = true)
179
162
  if (showDot) {
180
- val dotAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopEnd, unbounded = true)
181
- BadgeDot(size = DotSize.Small, modifier = dotAnchor.offset(x = 4.dp, y = (-4).dp))
163
+ BadgeDot(size = DotSize.Small, modifier = badgeAnchor.offset(x = 4.dp, y = (-4).dp))
182
164
  } else if (!badgeLabel.isNullOrEmpty()) {
183
- // starts at the icon's center and grows toward the cell's end edge, ellipsized past it
184
- val badgeAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopStart, unbounded = true)
185
- Badge(badgeLabel, modifier = badgeAnchor.offset(x = 14.dp, y = (-8).dp).widthIn(max = badgeMaxWidth))
165
+ Badge(badgeLabel, modifier = badgeAnchor.offset(x = if (isNumber) 8.dp else 12.dp, y = (-8).dp))
186
166
  }
187
167
  }
188
168
  Text(
@@ -1,15 +1,21 @@
1
1
  package vn.momo.kits.navigation.bottomtab
2
2
 
3
+ import androidx.compose.animation.core.Spring
4
+ import androidx.compose.animation.core.animateDpAsState
5
+ import androidx.compose.animation.core.animateFloatAsState
6
+ import androidx.compose.animation.core.spring
3
7
  import androidx.compose.foundation.background
4
- import androidx.compose.foundation.border
5
8
  import androidx.compose.foundation.clickable
6
- import androidx.compose.foundation.combinedClickable
7
9
  import androidx.compose.foundation.interaction.MutableInteractionSource
10
+ import androidx.compose.foundation.interaction.collectIsPressedAsState
11
+ import androidx.compose.foundation.border
8
12
  import androidx.compose.foundation.layout.Arrangement
9
13
  import androidx.compose.foundation.layout.Box
10
14
  import androidx.compose.foundation.layout.BoxScope
15
+ import androidx.compose.foundation.layout.BoxWithConstraints
11
16
  import androidx.compose.foundation.layout.Column
12
17
  import androidx.compose.foundation.layout.Row
18
+ import androidx.compose.foundation.layout.RowScope
13
19
  import androidx.compose.foundation.layout.absolutePadding
14
20
  import androidx.compose.foundation.layout.fillMaxHeight
15
21
  import androidx.compose.foundation.layout.fillMaxSize
@@ -19,30 +25,25 @@ import androidx.compose.foundation.layout.offset
19
25
  import androidx.compose.foundation.layout.padding
20
26
  import androidx.compose.foundation.layout.size
21
27
  import androidx.compose.foundation.layout.width
22
- import androidx.compose.foundation.layout.widthIn
23
- import androidx.compose.foundation.layout.wrapContentSize
24
28
  import androidx.compose.foundation.shape.CircleShape
25
29
  import androidx.compose.foundation.shape.RoundedCornerShape
26
30
  import androidx.compose.runtime.Composable
27
31
  import androidx.compose.runtime.CompositionLocalProvider
32
+ import androidx.compose.runtime.LaunchedEffect
33
+ import androidx.compose.runtime.MutableState
28
34
  import androidx.compose.runtime.compositionLocalOf
29
35
  import androidx.compose.runtime.getValue
30
36
  import androidx.compose.runtime.mutableStateOf
31
37
  import androidx.compose.runtime.remember
32
- import androidx.compose.runtime.setValue
33
38
  import androidx.compose.ui.AbsoluteAlignment
34
39
  import androidx.compose.ui.Alignment
35
40
  import androidx.compose.ui.Modifier
36
- import androidx.compose.ui.composed
37
41
  import androidx.compose.ui.draw.clip
38
42
  import androidx.compose.ui.draw.shadow
43
+ import androidx.compose.ui.graphics.graphicsLayer
39
44
  import androidx.compose.ui.graphics.Color
40
45
  import androidx.compose.ui.graphics.Shape
41
- import androidx.compose.ui.graphics.graphicsLayer
42
- import androidx.compose.ui.layout.onSizeChanged
43
- import androidx.compose.ui.platform.LocalDensity
44
46
  import androidx.compose.ui.semantics.Role
45
- import androidx.compose.ui.semantics.clearAndSetSemantics
46
47
  import androidx.compose.ui.text.style.TextOverflow
47
48
  import androidx.compose.ui.unit.Dp
48
49
  import androidx.compose.ui.unit.dp
@@ -61,7 +62,6 @@ import vn.momo.kits.layout.ScreenLayout
61
62
  import vn.momo.kits.layout.SideBarEdge
62
63
  import vn.momo.kits.modifier.noFeedbackClickable
63
64
  import vn.momo.kits.modifier.setAutomationId
64
- import vn.momo.kits.navigation.LocalMaxApi
65
65
 
66
66
  // Figma Fold-Design-System MT1/MT2, mirrored from RN DuoTabBar.tsx.
67
67
  private val ITEM_SIZE = DuoMetrics.controlSize
@@ -76,11 +76,14 @@ private val FLOATING_HEIGHT = DuoMetrics.floatingTabBarHeight
76
76
  private val FLOATING_PADDING = Spacing.XS
77
77
  // the system bar sizes its pill to the tabs instead of stretching it across the display
78
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
79
+ // while pressed the selection bubble grows into a lens past the pill's edges
80
+ private const val LENS_SCALE_X = 1.2f
81
+ private const val LENS_SCALE_Y = 1.3f
82
82
  // Figma Home-2026 tab bar "Selection": brand pink at 8%
83
83
  private const val SELECTION_TINT_ALPHA = 0x14 / 255f
84
+ // RN reanimated spring { damping: 18, stiffness: 220, mass: 0.8 }
85
+ private val BUBBLE_SPRING = spring<Dp>(dampingRatio = 0.68f, stiffness = 275f, visibilityThreshold = Dp(0.5f))
86
+ private val LENS_SPRING = spring<Float>(dampingRatio = 0.68f, stiffness = 275f)
84
87
 
85
88
  // Space from the window bottom the rail stack and its gap take, so the header side bar stays above it.
86
89
  internal val LocalDuoRailReserve = compositionLocalOf { 0.dp }
@@ -109,15 +112,11 @@ internal fun BoxScope.DuoTabBar(
109
112
  selectedIndex: Int,
110
113
  onTabSelected: (Int) -> Unit,
111
114
  compression: DuoBarCompression = DuoBarCompression(),
112
- onTabLongPress: ((Int) -> Unit)? = null,
113
115
  ) {
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 } }
117
116
  if (layout.sideBar != null) {
118
- DuoRailTabBar(layout, items, floatingButton, selectedIndex, onTabSelected, compression, onTabLongPress, onTick)
117
+ DuoRailTabBar(layout, items, floatingButton, selectedIndex, onTabSelected, compression)
119
118
  } else {
120
- DuoFloatingTabBar(layout, items, floatingButton, selectedIndex, onTabSelected, onTabLongPress, onTick)
119
+ DuoFloatingTabBar(layout, items, floatingButton, selectedIndex, onTabSelected)
121
120
  }
122
121
  }
123
122
 
@@ -132,8 +131,6 @@ private fun BoxScope.DuoRailTabBar(
132
131
  selectedIndex: Int,
133
132
  onTabSelected: (Int) -> Unit,
134
133
  compression: DuoBarCompression,
135
- onTabLongPress: ((Int) -> Unit)?,
136
- onTick: () -> Unit,
137
134
  ) {
138
135
  val sideBar = layout.sideBar ?: return
139
136
  val isRight = sideBar.edge == SideBarEdge.RIGHT
@@ -149,20 +146,18 @@ private fun BoxScope.DuoRailTabBar(
149
146
  ) {
150
147
  val current = items.getOrNull(selectedIndex)
151
148
  if (compression.tabBarCompressed && current != null) {
152
- val interactionSource = remember { MutableInteractionSource() }
153
149
  Box(
154
150
  modifier = Modifier
155
- .pressLift(interactionSource)
156
151
  .size(ITEM_SIZE)
157
152
  .tabBarMaterial(CircleShape)
158
- .clickable(interactionSource = interactionSource, indication = null, onClick = compression.expandTabBar)
153
+ .noFeedbackClickable(onClick = compression.expandTabBar)
159
154
  .setAutomationId("bottom_tab_bar"),
160
155
  contentAlignment = Alignment.Center,
161
156
  ) {
162
- DuoTabIcon(current, selected = true, badgeMaxWidth = RAIL_BADGE_MAX_WIDTH, inRail = true)
157
+ DuoTabIcon(current, selected = true)
163
158
  }
164
159
  } else {
165
- Rail(items, selectedIndex, onTabLongPress, onTick) {
160
+ Rail(items, selectedIndex) {
166
161
  onTabSelected(it)
167
162
  compression.onTabSelected()
168
163
  }
@@ -173,55 +168,42 @@ private fun BoxScope.DuoRailTabBar(
173
168
  }
174
169
  }
175
170
 
176
- // Column of icon-only tab items with the sliding selection lens.
171
+ // Column of icon-only tab items with the sliding selection bubble.
177
172
  @Composable
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,
173
+ private fun Rail(items: List<BottomTabItem>, selectedIndex: Int, onItemClick: (Int) -> Unit) {
174
+ val pressedIndex = remember { mutableStateOf<Int?>(null) }
175
+ val bubbleOffset by animateDpAsState(
176
+ targetValue = (ITEM_SIZE + RAIL_GAP) * (pressedIndex.value ?: selectedIndex).coerceAtLeast(0),
177
+ animationSpec = BUBBLE_SPRING,
178
+ label = "DuoRailBubble",
193
179
  )
194
180
  Box(
195
181
  Modifier
196
- .then(selection.barTransform)
197
182
  .width(ITEM_SIZE)
198
183
  .tabBarMaterial(CircleShape)
199
184
  .setAutomationId("bottom_tab_bar")
200
- .then(selection.dragGesture)
201
185
  ) {
202
186
  Box(
203
187
  Modifier
204
188
  .offset(
205
189
  x = (ITEM_SIZE - RAIL_BUBBLE_WIDTH) / 2,
206
- y = RAIL_PADDING - (RAIL_BUBBLE_HEIGHT - ITEM_SIZE) / 2,
190
+ y = RAIL_PADDING - (RAIL_BUBBLE_HEIGHT - ITEM_SIZE) / 2 + bubbleOffset,
207
191
  )
208
- .then(selection.bubbleTransform)
209
192
  .size(RAIL_BUBBLE_WIDTH, RAIL_BUBBLE_HEIGHT)
210
- .selectionTint()
193
+ .selectionLens(pressedIndex.value != null)
211
194
  )
212
195
  Column(
213
196
  modifier = Modifier.padding(vertical = RAIL_PADDING),
214
197
  verticalArrangement = Arrangement.spacedBy(RAIL_GAP),
215
198
  ) {
216
199
  items.forEachIndexed { index, item ->
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)
200
+ Box(
201
+ modifier = Modifier
202
+ .size(ITEM_SIZE)
203
+ .tabClickable(index, pressedIndex) { onItemClick(index) },
204
+ contentAlignment = Alignment.Center,
205
+ ) {
206
+ DuoTabIcon(item, selected = index == selectedIndex)
225
207
  }
226
208
  }
227
209
  }
@@ -236,21 +218,8 @@ private fun BoxScope.DuoFloatingTabBar(
236
218
  floatingButton: BottomTabFloatingButton?,
237
219
  selectedIndex: Int,
238
220
  onTabSelected: (Int) -> Unit,
239
- onTabLongPress: ((Int) -> Unit)?,
240
- onTick: () -> Unit,
241
221
  ) {
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
- )
222
+ val pressedIndex = remember { mutableStateOf<Int?>(null) }
254
223
 
255
224
  Row(
256
225
  modifier = Modifier
@@ -268,36 +237,28 @@ private fun BoxScope.DuoFloatingTabBar(
268
237
  .weight(1f, fill = false)
269
238
  .width(FLOATING_ITEM_WIDTH * items.size + FLOATING_PADDING * 2)
270
239
  .height(FLOATING_HEIGHT)
271
- .then(selection.barTransform)
272
240
  .tabBarMaterial(RoundedCornerShape(FLOATING_HEIGHT / 2))
273
241
  .padding(FLOATING_PADDING)
274
242
  .setAutomationId("bottom_tab_bar")
275
243
  ) {
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
- }
244
+ BoxWithConstraints(Modifier.fillMaxSize()) {
245
+ val cellWidth = maxWidth / items.size.coerceAtLeast(1)
246
+ val bubbleOffset by animateDpAsState(
247
+ targetValue = cellWidth * (pressedIndex.value ?: selectedIndex).coerceAtLeast(0),
248
+ animationSpec = BUBBLE_SPRING,
249
+ label = "DuoFloatingBubble",
250
+ )
251
+ Box(
252
+ Modifier
253
+ .offset(x = bubbleOffset)
254
+ .width(cellWidth)
255
+ .fillMaxHeight()
256
+ .selectionLens(pressedIndex.value != null)
257
+ )
291
258
  Row(Modifier.fillMaxSize()) {
292
259
  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)
260
+ FloatingCell(item, selected = index == selectedIndex, index, pressedIndex) {
261
+ onTabSelected(index)
301
262
  }
302
263
  }
303
264
  }
@@ -309,56 +270,24 @@ private fun BoxScope.DuoFloatingTabBar(
309
270
  }
310
271
  }
311
272
 
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
273
  @Composable
315
- private fun LiquidTab(
316
- selection: DuoLiquidSelection,
274
+ private fun RowScope.FloatingCell(
275
+ item: BottomTabItem,
276
+ selected: Boolean,
317
277
  index: Int,
318
- onSelect: () -> Unit,
319
- onLongPress: (() -> Unit)?,
320
- modifier: Modifier = Modifier,
321
- content: @Composable (active: Boolean) -> Unit,
278
+ pressedIndex: MutableState<Int?>,
279
+ onClick: () -> Unit,
322
280
  ) {
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
281
  val colors = AppTheme.current.colors
357
282
  Column(
283
+ modifier = Modifier
284
+ .weight(1f)
285
+ .fillMaxHeight()
286
+ .tabClickable(index, pressedIndex, onClick),
358
287
  horizontalAlignment = Alignment.CenterHorizontally,
359
- verticalArrangement = Arrangement.spacedBy(Spacing.XXS),
288
+ verticalArrangement = Arrangement.spacedBy(Spacing.XXS, Alignment.CenterVertically),
360
289
  ) {
361
- DuoTabIcon(item, active, badgeMaxWidth)
290
+ DuoTabIcon(item, selected)
362
291
  // like the system tab bar the label keeps its design size; Text grows it up to 5pt on the wide Duo displays
363
292
  val context = LocalContext.current
364
293
  val fixedScale = remember(context) {
@@ -368,7 +297,7 @@ private fun FloatingCellContent(item: BottomTabItem, active: Boolean, badgeMaxWi
368
297
  Text(
369
298
  text = item.label,
370
299
  style = Typography.labelXsMedium,
371
- color = if (active) colors.primary else colors.text.hint,
300
+ color = if (selected) colors.primary else colors.text.hint,
372
301
  maxLines = 1,
373
302
  overflow = TextOverflow.Ellipsis,
374
303
  )
@@ -376,15 +305,31 @@ private fun FloatingCellContent(item: BottomTabItem, active: Boolean, badgeMaxWi
376
305
  }
377
306
  }
378
307
 
379
- private fun Modifier.selectionTint(): Modifier = composed {
380
- background(AppTheme.current.colors.primary.copy(alpha = SELECTION_TINT_ALPHA), CircleShape)
308
+ // Tracks the finger so the selection lens jumps to the pressed tab before it is selected.
309
+ @Composable
310
+ private fun Modifier.tabClickable(index: Int, pressedIndex: MutableState<Int?>, onClick: () -> Unit): Modifier {
311
+ val interactionSource = remember { MutableInteractionSource() }
312
+ val pressed by interactionSource.collectIsPressedAsState()
313
+ LaunchedEffect(pressed) {
314
+ if (pressed) pressedIndex.value = index
315
+ else if (pressedIndex.value == index) pressedIndex.value = null
316
+ }
317
+ return clickable(interactionSource = interactionSource, indication = null, role = Role.Tab, onClick = onClick)
318
+ }
319
+
320
+ // Selection bubble; while pressed it grows into a lens (80x54 to about 96x70).
321
+ @Composable
322
+ private fun Modifier.selectionLens(pressed: Boolean): Modifier {
323
+ val lens by animateFloatAsState(if (pressed) 1f else 0f, LENS_SPRING, label = "DuoSelectionLens")
324
+ val tint = AppTheme.current.colors.primary.copy(alpha = SELECTION_TINT_ALPHA)
325
+ return graphicsLayer {
326
+ scaleX = 1 + lens * (LENS_SCALE_X - 1)
327
+ scaleY = 1 + lens * (LENS_SCALE_Y - 1)
328
+ }.background(tint, CircleShape)
381
329
  }
382
330
 
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
331
  @Composable
387
- private fun DuoTabIcon(item: BottomTabItem, selected: Boolean, badgeMaxWidth: Dp, inRail: Boolean = false) {
332
+ private fun DuoTabIcon(item: BottomTabItem, selected: Boolean) {
388
333
  val colors = AppTheme.current.colors
389
334
  val badgeLabel = item.badgeLabel?.takeUnless { it.toIntOrNull() == 0 }
390
335
  Box {
@@ -401,11 +346,7 @@ private fun DuoTabIcon(item: BottomTabItem, selected: Boolean, badgeMaxWidth: Dp
401
346
  )
402
347
  else -> Badge(
403
348
  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)),
349
+ modifier = Modifier.align(Alignment.TopStart).offset(x = ICON_SIZE / 2, y = -Spacing.XS),
409
350
  )
410
351
  }
411
352
  }
package/gradle.properties CHANGED
@@ -18,7 +18,7 @@ kotlin.apple.xcodeCompatibility.nowarn=true
18
18
  name="ComposeKits"
19
19
  group=vn.momo.kits
20
20
  artifact.id=kits
21
- version=0.168.1-beta.8
21
+ version=0.168.1-beta.24
22
22
 
23
23
  repo=GitLab
24
24
  url=https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven
@@ -199,12 +199,13 @@ struct BottomSheetView<Content: View>: View {
199
199
  .fill(Colors.black06)
200
200
  .frame(width: 40, height: 4)
201
201
  Spacer().frame(height: 4)
202
+ // the handle centers on the whole sheet, only the header row keeps clear of the strip
202
203
  headerView
203
204
  .frame(height: headerRowHeight)
204
205
  .padding(.horizontal, Spacing.M)
206
+ .padding(.leading, sideInsetLeading)
207
+ .padding(.trailing, sideInsetTrailing)
205
208
  }
206
- .padding(.leading, sideInsetLeading)
207
- .padding(.trailing, sideInsetTrailing)
208
209
  .frame(maxWidth: .infinity)
209
210
  .frame(height: indicatorHeight + headerRowHeight)
210
211
  .contentShape(Rectangle())