@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.
Files changed (31) hide show
  1. package/CLAUDE.md +1 -0
  2. package/compose/build.gradle.kts +1 -1
  3. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +2 -3
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +9 -9
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +26 -34
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +167 -319
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +71 -79
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +326 -93
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +2 -3
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +1 -3
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  14. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +2 -3
  15. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  16. package/ios/Input/Input.swift +3 -1
  17. package/ios/Input/InputTextArea.swift +3 -1
  18. package/ios/Navigation/BottomTab/BottomTab.swift +67 -48
  19. package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -281
  20. package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
  21. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
  22. package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -72
  23. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  24. package/ios/Navigation/StackScreen.swift +1 -3
  25. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -272
  26. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +90 -0
  27. package/package.json +1 -1
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -106
  29. package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
  30. package/ios-demo/Resources/tabbar_scan_qr_button.json +0 -1
  31. package/ios-demo/Resources/tabbar_scan_qr_label.json +0 -1
@@ -1,94 +1,86 @@
1
1
  package vn.momo.kits.navigation.bottomtab
2
2
 
3
+ import androidx.compose.foundation.Canvas
4
+ import androidx.compose.foundation.layout.Box
5
+ import androidx.compose.foundation.layout.height
6
+ import androidx.compose.foundation.layout.offset
7
+ import androidx.compose.foundation.layout.width
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.ui.Alignment
3
10
  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
11
  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
12
+ import androidx.compose.ui.platform.LocalDensity
17
13
  import androidx.compose.ui.unit.Dp
18
- import androidx.compose.ui.unit.DpOffset
19
- import androidx.compose.ui.unit.LayoutDirection
14
+ import androidx.compose.ui.unit.IntOffset
20
15
  import androidx.compose.ui.unit.dp
21
- import androidx.compose.foundation.background
22
- import androidx.compose.runtime.Composable
16
+ import androidx.compose.ui.zIndex
23
17
  import vn.momo.kits.const.AppTheme
24
18
 
25
- // Rounded container, with the notch dipped into the top edge around `notchCenterX` (from the left).
26
- internal class NotchedBarShape(
27
- private val radius: Dp,
28
- private val notchCenterX: Dp? = null,
29
- ) : Shape {
30
- override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
31
- val r = minOf(with(density) { radius.toPx() }, size.height / 2, size.width / 2)
32
- val path = Path()
33
- if (notchCenterX == null) {
34
- path.addRoundRect(RoundRect(Rect(0f, 0f, size.width, size.height), CornerRadius(r)))
35
- return Outline.Generic(path)
36
- }
37
- val cx = with(density) { notchCenterX.toPx() }
38
- val unit = density.density
39
- path.apply {
40
- moveTo(r, 0f)
41
- lineTo(cx - NOTCH_HALF_WIDTH * unit, 0f)
42
- NOTCH_CURVES.forEach { (c1, c2, end) ->
43
- cubicTo(
44
- cx + c1.first * unit, c1.second * unit,
45
- cx + c2.first * unit, c2.second * unit,
46
- cx + end.first * unit, end.second * unit,
47
- )
48
- }
49
- lineTo(size.width - r, 0f)
50
- arcTo(Rect(size.width - 2 * r, 0f, size.width, 2 * r), -90f, 90f, false)
51
- lineTo(size.width, size.height - r)
52
- arcTo(Rect(size.width - 2 * r, size.height - 2 * r, size.width, size.height), 0f, 90f, false)
53
- lineTo(r, size.height)
54
- arcTo(Rect(0f, size.height - 2 * r, 2 * r, size.height), 90f, 90f, false)
55
- lineTo(0f, r)
56
- arcTo(Rect(0f, 0f, 2 * r, 2 * r), 180f, 90f, false)
57
- close()
58
- }
59
- return Outline.Generic(path)
60
- }
61
- }
19
+ @Composable
20
+ internal fun CurvedContainer(
21
+ circleSize: Dp = 48.dp,
22
+ tabBarItemIconSize: Dp = 28.dp,
23
+ circleOverSize: Dp = 2.dp,
24
+ width: Dp = 71.dp,
25
+ height: Dp = 16.dp
26
+ ) {
27
+ val theme = AppTheme.current
28
+ val density = LocalDensity.current
29
+ val widthPx = with(density) { width.toPx()}
30
+
31
+ val circleSizePx = with(density) { circleSize.toPx() }
32
+ val tabBarItemIconSizePx = with(density) { tabBarItemIconSize.toPx() }
33
+ val circleOverSizePx = with(density) { circleOverSize.toPx() }
34
+
35
+ val circlePositionTop = circleSizePx - tabBarItemIconSizePx - 10f
36
+ val circleOverTop = circlePositionTop + circleOverSizePx
37
+ val circleR = circleSizePx / 2
38
+ val circleOverR = circleR + circleOverSizePx
62
39
 
63
- // The shape shrunk by `inset` on every side. A shadow cast from it with no spread is a shadow of the
64
- // shape with spread -inset; dropShadow's own negative spread clips the blur of path outlines.
65
- internal class InsetShape(private val shape: Shape, private val inset: Dp) : Shape {
66
- override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
67
- val insetPx = with(density) { inset.toPx() }
68
- val inner = Size((size.width - 2 * insetPx).coerceAtLeast(0f), (size.height - 2 * insetPx).coerceAtLeast(0f))
69
- val path = Path().apply {
70
- addOutline(shape.createOutline(inner, layoutDirection, density))
71
- translate(Offset(insetPx, insetPx))
40
+ val centerX = widthPx / 2
41
+
42
+ val curvedPath = getPath(
43
+ circleOverTop = circleOverTop,
44
+ centerX = centerX,
45
+ circleOverR = circleOverR,
46
+ widthPx = widthPx
47
+ )
48
+
49
+ Box(
50
+ contentAlignment = Alignment.BottomCenter
51
+ ){
52
+ Canvas(
53
+ modifier = Modifier
54
+ .width(width)
55
+ .height(height)
56
+ .offset{ IntOffset(x = 0, y = 24) }
57
+ .zIndex(-1f)
58
+ ) {
59
+ drawPath(path = curvedPath, color = theme.colors.background.surface)
72
60
  }
73
- return Outline.Generic(path)
74
61
  }
75
62
  }
76
63
 
77
- // Shadow with a negative spread, cast from the shrunk shape.
78
- internal fun Modifier.spreadShadow(shape: Shape, shadow: Shadow): Modifier =
79
- if (shadow.spread < 0.dp) dropShadow(
80
- InsetShape(shape, -shadow.spread),
81
- Shadow(radius = shadow.radius, color = shadow.color, offset = shadow.offset, alpha = shadow.alpha),
82
- )
83
- else dropShadow(shape, shadow)
64
+ private fun getPath(circleOverTop: Float, centerX: Float, circleOverR: Float, widthPx: Float): Path{
65
+ return Path().apply {
66
+ moveTo(0f, circleOverTop)
67
+ lineTo(centerX - circleOverR - 40f, circleOverTop)
84
68
 
85
- // Navigation bar container: surface fill with the floating shadow following the shape (Figma
86
- // Shadow/floating: 12% blur 24, 4% y12 blur 32 spread -16).
87
- @Composable
88
- internal fun Modifier.tabBarContainer(shape: Shape): Modifier =
89
- dropShadow(shape, Shadow(radius = 24.dp, color = Color.Black, alpha = 0.12f))
90
- .spreadShadow(
91
- shape,
92
- Shadow(radius = 32.dp, spread = (-16).dp, color = Color.Black, alpha = 0.04f, offset = DpOffset(0.dp, 12.dp)),
69
+ cubicTo(
70
+ centerX - circleOverR, circleOverTop,
71
+ centerX - circleOverR, 0f,
72
+ centerX, 0f
93
73
  )
94
- .background(AppTheme.current.colors.background.surface, shape)
74
+
75
+ cubicTo(
76
+ centerX + circleOverR, 0f,
77
+ centerX + circleOverR, circleOverTop,
78
+ centerX + circleOverR + 40f, circleOverTop
79
+ )
80
+
81
+ lineTo(widthPx, circleOverTop)
82
+ lineTo(widthPx, 60f)
83
+ lineTo(0f, 60f)
84
+ close()
85
+ }
86
+ }
@@ -0,0 +1,380 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.animation.core.Animatable
4
+ import androidx.compose.animation.core.SpringSpec
5
+ import androidx.compose.animation.core.spring
6
+ import androidx.compose.animation.core.tween
7
+ import androidx.compose.foundation.gestures.awaitEachGesture
8
+ import androidx.compose.foundation.gestures.awaitFirstDown
9
+ import androidx.compose.foundation.interaction.MutableInteractionSource
10
+ import androidx.compose.foundation.interaction.PressInteraction
11
+ import androidx.compose.runtime.Composable
12
+ import androidx.compose.runtime.LaunchedEffect
13
+ import androidx.compose.runtime.Stable
14
+ import androidx.compose.runtime.getValue
15
+ import androidx.compose.runtime.mutableFloatStateOf
16
+ import androidx.compose.runtime.mutableIntStateOf
17
+ import androidx.compose.runtime.mutableStateOf
18
+ import androidx.compose.runtime.remember
19
+ import androidx.compose.runtime.rememberCoroutineScope
20
+ import androidx.compose.runtime.rememberUpdatedState
21
+ import androidx.compose.runtime.setValue
22
+ import androidx.compose.runtime.snapshotFlow
23
+ import androidx.compose.ui.Modifier
24
+ import androidx.compose.ui.geometry.Offset
25
+ import androidx.compose.ui.graphics.graphicsLayer
26
+ import androidx.compose.ui.input.pointer.pointerInput
27
+ import androidx.compose.ui.input.pointer.util.VelocityTracker
28
+ import androidx.compose.ui.platform.LocalDensity
29
+ import androidx.compose.ui.unit.Dp
30
+ import androidx.compose.ui.unit.dp
31
+ import kotlinx.coroutines.CoroutineScope
32
+ import kotlinx.coroutines.Job
33
+ import kotlinx.coroutines.delay
34
+ import kotlinx.coroutines.launch
35
+ import vn.momo.kits.platform.rememberReduceMotion
36
+ import kotlin.math.abs
37
+ import kotlin.math.min
38
+ import kotlin.math.roundToInt
39
+
40
+ // iOS 26 tab bar selection motion without the glass material, port of RN useLiquidSelection.ts.
41
+ // Constants mirror RN; springs are RN (mass, stiffness, damping) converted to mass 1.
42
+ private val SPRING = spring<Float>(dampingRatio = 0.68f, stiffness = 275f)
43
+ // the lens trails the finger a little while dragged (RN damping 24, stiffness 600, mass 0.6)
44
+ private val DRAG_SPRING = spring<Float>(dampingRatio = 0.63f, stiffness = 1000f)
45
+ private val REDUCED_TWEEN = tween<Float>(durationMillis = 200)
46
+ // while pressed the selection bubble grows into a lens past the bar's edges (80x54 to about 96x70)
47
+ private const val LENS_SCALE_X = 1.2f
48
+ private const val LENS_SCALE_Y = 1.3f
49
+ // a moving lens stretches along its path and thins across it, eased per frame
50
+ private const val STRETCH_PER_POINT = 0.012f
51
+ private const val MAX_STRETCH = 0.25f
52
+ private const val STRETCH_EASING = 0.25f
53
+ private const val REST_STRETCH = 0.002f
54
+ // a tap is shorter than the lift: the lens finishes rising, then settles, one smooth pulse
55
+ private const val TAP_LIFT_MILLIS = 120
56
+ private const val BAR_SWELL = 0.04f
57
+ private const val ICON_POP = 1.15f
58
+ private const val ICON_POP_MILLIS = 120
59
+ // below it the tab's clickable handles the press as a tap
60
+ private val DRAG_SLOP = 10.dp
61
+ // UIScrollView rubber band constant
62
+ private const val RUBBER_BAND = 0.55f
63
+ // a cancelled press or a vetoed switch: the lens returns to the selected tab after this
64
+ private const val RESYNC_DELAY_MILLIS = 100L
65
+
66
+ internal enum class LiquidAxis { X, Y }
67
+
68
+ // resistance past the first and last tab, the further the finger goes the less the lens follows
69
+ private fun rubberBand(value: Float, max: Float, dimension: Float): Float {
70
+ fun band(overshoot: Float) = (1 - 1 / (overshoot * RUBBER_BAND / dimension + 1)) * dimension
71
+ return when {
72
+ value < 0 -> -band(-value)
73
+ value > max -> max + band(value - max)
74
+ else -> value
75
+ }
76
+ }
77
+
78
+ @Stable
79
+ internal class DuoLiquidSelection(
80
+ private val scope: CoroutineScope,
81
+ private val axis: LiquidAxis,
82
+ private val density: Float,
83
+ ) {
84
+ var count = 0
85
+ // px between two neighbouring tab centers / to the first tab's center inside the drag modifier
86
+ var pitch = 0f
87
+ var firstCenter = 0f
88
+ var reduceMotion = false
89
+ var onSelect: (Int) -> Unit = {}
90
+ var onTick: () -> Unit = {}
91
+
92
+ val offset = Animatable(0f)
93
+ val lift = Animatable(0f)
94
+ var stretch by mutableFloatStateOf(0f)
95
+ private set
96
+ var selectedIndex by mutableIntStateOf(0)
97
+ private set
98
+
99
+ // where the lens is heading, so a recomposition doesn't restart a spring already going there
100
+ private var destination = 0f
101
+ private var dragging = false
102
+ private var hovered = 0
103
+ private var measured = false
104
+ private var resyncJob: Job? = null
105
+
106
+ private fun move(target: Float, velocity: Float? = null, spec: SpringSpec<Float> = SPRING) {
107
+ if (destination == target && velocity == null) return
108
+ destination = target
109
+ scope.launch {
110
+ if (reduceMotion) offset.animateTo(target, REDUCED_TWEEN)
111
+ else offset.animateTo(target, spec, initialVelocity = velocity ?: offset.velocity)
112
+ }
113
+ }
114
+
115
+ private fun animateLift(target: Float) {
116
+ scope.launch { if (reduceMotion) lift.snapTo(0f) else lift.animateTo(target, SPRING) }
117
+ }
118
+
119
+ suspend fun sync(index: Int) {
120
+ selectedIndex = index
121
+ val target = index * pitch
122
+ // snap on first layout so the lens doesn't slide in from the leading edge
123
+ if (measured) {
124
+ move(target)
125
+ } else {
126
+ destination = target
127
+ offset.snapTo(target)
128
+ }
129
+ measured = pitch > 0
130
+ }
131
+
132
+ suspend fun trackStretch() {
133
+ var previous = offset.value
134
+ snapshotFlow { offset.value }.collect { current ->
135
+ if (reduceMotion) {
136
+ stretch = 0f
137
+ } else {
138
+ val target = min(abs(current - previous) / density * STRETCH_PER_POINT, MAX_STRETCH)
139
+ // eased both ways: a slow frame (the spring turning at its overshoot) must not snap the shape
140
+ val next = stretch + (target - stretch) * STRETCH_EASING
141
+ stretch = if (next < REST_STRETCH) 0f else next
142
+ }
143
+ previous = current
144
+ }
145
+ }
146
+
147
+ // returns the lens to the selected tab unless a switch to where it is heading happened
148
+ private fun resync() {
149
+ resyncJob?.cancel()
150
+ resyncJob = scope.launch {
151
+ delay(RESYNC_DELAY_MILLIS)
152
+ val target = selectedIndex * pitch
153
+ if (!dragging && destination != target) move(target)
154
+ }
155
+ }
156
+
157
+ fun pressIn(index: Int) {
158
+ resyncJob?.cancel()
159
+ // the lens heads to the pressed tab, not only the selected one
160
+ move(index * pitch)
161
+ animateLift(1f)
162
+ }
163
+
164
+ // false when a drag took the press over
165
+ fun pressOut(): Boolean {
166
+ if (dragging) return false
167
+ if (!reduceMotion) {
168
+ scope.launch {
169
+ lift.animateTo(1f, tween(TAP_LIFT_MILLIS))
170
+ lift.animateTo(0f, SPRING)
171
+ }
172
+ }
173
+ // the lens keeps heading to the pressed tab: onClick switches to it, a cancelled press brings it back
174
+ resync()
175
+ return true
176
+ }
177
+
178
+ private fun position(point: Offset) = (if (axis == LiquidAxis.X) point.x else point.y) - firstCenter
179
+
180
+ private fun nearest(value: Float): Int =
181
+ if (pitch > 0) (value / pitch).roundToInt().coerceIn(0, (count - 1).coerceAtLeast(0)) else 0
182
+
183
+ private fun dragStart(point: Offset) {
184
+ dragging = true
185
+ resyncJob?.cancel()
186
+ hovered = nearest(position(point))
187
+ animateLift(1f)
188
+ }
189
+
190
+ private fun dragUpdate(point: Offset) {
191
+ val value = position(point)
192
+ val target = nearest(value)
193
+ if (target != hovered) {
194
+ hovered = target
195
+ onTick()
196
+ }
197
+ val follow = rubberBand(value, (count - 1) * pitch, pitch)
198
+ if (reduceMotion) {
199
+ destination = follow
200
+ scope.launch { offset.snapTo(follow) }
201
+ } else {
202
+ move(follow, spec = DRAG_SPRING)
203
+ }
204
+ }
205
+
206
+ private fun dragEnd(point: Offset?, velocity: Float) {
207
+ dragging = false
208
+ animateLift(0f)
209
+ if (point == null) {
210
+ move(selectedIndex * pitch, velocity)
211
+ return
212
+ }
213
+ val target = nearest(position(point))
214
+ move(target * pitch, velocity)
215
+ onSelect(target)
216
+ resync()
217
+ }
218
+
219
+ // The drag consumes the pointer once past the slop, which cancels the tab's clickable,
220
+ // so a press is either a tap or a drag.
221
+ val dragGesture: Modifier = Modifier.pointerInput(Unit) {
222
+ val slop = DRAG_SLOP.toPx()
223
+ awaitEachGesture {
224
+ val down = awaitFirstDown(requireUnconsumed = false)
225
+ val tracker = VelocityTracker()
226
+ tracker.addPosition(down.uptimeMillis, down.position)
227
+ var active = false
228
+ var last = down.position
229
+ while (true) {
230
+ val change = awaitPointerEvent().changes.firstOrNull { it.id == down.id }
231
+ if (change == null) {
232
+ if (active) dragEnd(null, 0f)
233
+ break
234
+ }
235
+ tracker.addPosition(change.uptimeMillis, change.position)
236
+ if (!change.pressed) {
237
+ if (active) {
238
+ change.consume()
239
+ val velocity = tracker.calculateVelocity()
240
+ dragEnd(change.position, if (axis == LiquidAxis.X) velocity.x else velocity.y)
241
+ }
242
+ break
243
+ }
244
+ last = change.position
245
+ if (!active && (last - down.position).getDistance() > slop) {
246
+ active = true
247
+ dragStart(last)
248
+ }
249
+ if (active) {
250
+ change.consume()
251
+ dragUpdate(last)
252
+ }
253
+ }
254
+ }
255
+ }
256
+
257
+ val bubbleTransform: Modifier = Modifier.graphicsLayer {
258
+ val along = 1 + stretch
259
+ val across = 1 - stretch * 0.5f
260
+ val lensX = 1 + lift.value * (LENS_SCALE_X - 1)
261
+ val lensY = 1 + lift.value * (LENS_SCALE_Y - 1)
262
+ if (axis == LiquidAxis.X) {
263
+ translationX = offset.value
264
+ scaleX = lensX * along
265
+ scaleY = lensY * across
266
+ } else {
267
+ translationY = offset.value
268
+ scaleX = lensX * across
269
+ scaleY = lensY * along
270
+ }
271
+ }
272
+
273
+ val barTransform: Modifier = Modifier.graphicsLayer {
274
+ scaleX = 1 + lift.value * BAR_SWELL
275
+ scaleY = scaleX
276
+ }
277
+
278
+ // active tint of a tab follows the lens over it
279
+ fun activeAlpha(index: Int): Float {
280
+ if (pitch <= 0) return if (selectedIndex == index) 1f else 0f
281
+ return (1 - abs(offset.value - index * pitch) / pitch).coerceIn(0f, 1f)
282
+ }
283
+ }
284
+
285
+ @Composable
286
+ internal fun rememberDuoLiquidSelection(
287
+ count: Int,
288
+ pitch: Dp,
289
+ firstCenter: Dp,
290
+ axis: LiquidAxis,
291
+ index: Int,
292
+ onSelect: (Int) -> Unit,
293
+ onTick: () -> Unit,
294
+ ): DuoLiquidSelection {
295
+ val scope = rememberCoroutineScope()
296
+ val density = LocalDensity.current
297
+ val selection = remember(axis) { DuoLiquidSelection(scope, axis, density.density) }
298
+ val reduceMotion = rememberReduceMotion()
299
+ val pitchPx = with(density) { pitch.toPx() }
300
+ selection.count = count
301
+ selection.pitch = pitchPx
302
+ selection.firstCenter = with(density) { firstCenter.toPx() }
303
+ selection.reduceMotion = reduceMotion
304
+ selection.onSelect = onSelect
305
+ selection.onTick = onTick
306
+
307
+ LaunchedEffect(selection, index, pitchPx) { selection.sync(index) }
308
+ LaunchedEffect(selection) { selection.trackStretch() }
309
+ return selection
310
+ }
311
+
312
+ // Press tracking for one tab: lifts the lens over it and, like the system tab bar, still picks a
313
+ // held tab when released. Returns the long-press handler for the tab's combinedClickable.
314
+ @Composable
315
+ internal fun DuoLiquidSelection.rememberPressTracking(
316
+ index: Int,
317
+ interactionSource: MutableInteractionSource,
318
+ onSelect: () -> Unit,
319
+ onLongPress: (() -> Unit)?,
320
+ ): () -> Unit {
321
+ val longPressed = remember { mutableStateOf(false) }
322
+ val currentOnSelect by rememberUpdatedState(onSelect)
323
+ val currentOnLongPress by rememberUpdatedState(onLongPress)
324
+ LaunchedEffect(interactionSource, index) {
325
+ interactionSource.interactions.collect {
326
+ when (it) {
327
+ is PressInteraction.Press -> {
328
+ longPressed.value = false
329
+ pressIn(index)
330
+ }
331
+ is PressInteraction.Release -> if (pressOut() && longPressed.value) currentOnSelect()
332
+ is PressInteraction.Cancel -> pressOut()
333
+ }
334
+ }
335
+ }
336
+ return remember {
337
+ {
338
+ longPressed.value = true
339
+ currentOnLongPress?.invoke()
340
+ }
341
+ }
342
+ }
343
+
344
+ // The tab the lens lands on pops.
345
+ @Composable
346
+ internal fun DuoLiquidSelection.rememberIconPop(index: Int): Animatable<Float, *> {
347
+ val pop = remember { Animatable(1f) }
348
+ val isSelected = selectedIndex == index
349
+ val initial = remember { mutableStateOf(true) }
350
+ LaunchedEffect(isSelected) {
351
+ if (initial.value) {
352
+ initial.value = false
353
+ return@LaunchedEffect
354
+ }
355
+ if (isSelected && !reduceMotion) {
356
+ pop.animateTo(ICON_POP, tween(ICON_POP_MILLIS))
357
+ pop.animateTo(1f, SPRING)
358
+ }
359
+ }
360
+ return pop
361
+ }
362
+
363
+ // Single button version of the lift, e.g. the compressed rail.
364
+ @Composable
365
+ internal fun Modifier.pressLift(interactionSource: MutableInteractionSource): Modifier {
366
+ val lift = remember { Animatable(0f) }
367
+ val reduceMotion by rememberUpdatedState(rememberReduceMotion())
368
+ LaunchedEffect(interactionSource) {
369
+ interactionSource.interactions.collect {
370
+ when (it) {
371
+ is PressInteraction.Press -> if (!reduceMotion) launch { lift.animateTo(1f, SPRING) }
372
+ is PressInteraction.Release, is PressInteraction.Cancel -> launch { lift.animateTo(0f, SPRING) }
373
+ }
374
+ }
375
+ }
376
+ return graphicsLayer {
377
+ scaleX = 1 + lift.value * (LENS_SCALE_X - 1) * 0.5f
378
+ scaleY = scaleX
379
+ }
380
+ }