@momo-kits/native-kits 0.168.1-beta.37-debug → 0.168.1-beta.38-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 +2 -3
- package/compose/build.gradle.kts +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +81 -72
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +13 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +163 -54
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +12 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -27
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +319 -167
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +93 -326
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -2
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +3 -9
- package/ios/Input/Input.swift +1 -3
- package/ios/Input/InputTextArea.swift +1 -3
- package/ios/Layout/ScreenLayout.swift +24 -28
- package/ios/Navigation/BottomSheet.swift +157 -29
- package/ios/Navigation/BottomTab/BottomTab.swift +48 -67
- package/ios/Navigation/BottomTab/BottomTabBar.swift +280 -132
- package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
- package/ios/Navigation/BottomTab/DuoTabBar.swift +72 -292
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/ModalScreen.swift +7 -18
- package/ios/Navigation/StackScreen.swift +3 -1
- package/ios/Popup/PopupDisplay.swift +2 -4
- package/ios/Popup/PopupInput.swift +2 -4
- package/ios/Popup/PopupLayout.swift +9 -10
- package/ios/Popup/PopupNotify.swift +23 -26
- package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
- package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +0 -103
- package/package.json +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -187
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +0 -380
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
- package/ios/Layout/ModalLayout.swift +0 -152
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
package vn.momo.kits.layout
|
|
2
|
-
|
|
3
|
-
import androidx.compose.foundation.background
|
|
4
|
-
import androidx.compose.foundation.border
|
|
5
|
-
import androidx.compose.foundation.layout.Box
|
|
6
|
-
import androidx.compose.foundation.layout.size
|
|
7
|
-
import androidx.compose.foundation.shape.CircleShape
|
|
8
|
-
import androidx.compose.runtime.Composable
|
|
9
|
-
import androidx.compose.runtime.Immutable
|
|
10
|
-
import androidx.compose.runtime.remember
|
|
11
|
-
import androidx.compose.ui.Alignment
|
|
12
|
-
import androidx.compose.ui.Modifier
|
|
13
|
-
import androidx.compose.ui.draw.clip
|
|
14
|
-
import androidx.compose.ui.unit.Dp
|
|
15
|
-
import androidx.compose.ui.unit.DpRect
|
|
16
|
-
import androidx.compose.ui.unit.dp
|
|
17
|
-
import androidx.compose.ui.unit.height
|
|
18
|
-
import androidx.compose.ui.unit.width
|
|
19
|
-
import vn.momo.kits.components.Icon
|
|
20
|
-
import vn.momo.kits.const.AppTheme
|
|
21
|
-
import vn.momo.kits.const.Radius
|
|
22
|
-
import vn.momo.kits.const.Spacing
|
|
23
|
-
import vn.momo.kits.modifier.noFeedbackClickable
|
|
24
|
-
import vn.momo.kits.modifier.setAutomationId
|
|
25
|
-
|
|
26
|
-
// Foldable spec for Popup and BottomSheet (Figma "Modal - Foldable Guideline"); mirrors RN and SwiftUI, keep in sync.
|
|
27
|
-
// Public so host apps can size their own (non-kits) popups and sheets the same way.
|
|
28
|
-
val POPUP_MAX_WIDTH = 450.dp
|
|
29
|
-
val POPUP_MIN_WIDTH = 280.dp
|
|
30
|
-
val POPUP_MAX_HEIGHT = 600.dp
|
|
31
|
-
val SHEET_MAX_WIDTH = 653.dp
|
|
32
|
-
val SHEET_MIN_WIDTH = 296.dp
|
|
33
|
-
val SHEET_MIN_HEIGHT = 230.dp
|
|
34
|
-
val FOLDABLE_MIN_WIDTH = 600.dp
|
|
35
|
-
internal val MODAL_ICON_BUTTON_SIZE = 32.dp
|
|
36
|
-
private val CLOSE_ICON_SIZE = 20.dp
|
|
37
|
-
private const val PHONE_SCRIM_OPACITY = 0.6f
|
|
38
|
-
private const val FOLDABLE_SCRIM_OPACITY = 0.2f
|
|
39
|
-
|
|
40
|
-
@Immutable
|
|
41
|
-
data class PopupGeometry(
|
|
42
|
-
val minWidth: Dp,
|
|
43
|
-
val maxWidth: Dp,
|
|
44
|
-
// null: as tall as the content, phones keep their own caps
|
|
45
|
-
val maxHeight: Dp?,
|
|
46
|
-
val margin: Dp,
|
|
47
|
-
val radius: Dp,
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
@Immutable
|
|
51
|
-
data class SheetGeometry(
|
|
52
|
-
// null: spans the window
|
|
53
|
-
val width: Dp?,
|
|
54
|
-
// null: phones keep their own cap
|
|
55
|
-
val maxHeight: Dp?,
|
|
56
|
-
val minHeight: Dp,
|
|
57
|
-
val margin: Dp,
|
|
58
|
-
val radius: Dp,
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
/** Popup / bottom sheet geometry for the current window; see [modalLayoutOf]. */
|
|
62
|
-
@Immutable
|
|
63
|
-
data class ModalLayout(
|
|
64
|
-
val isFoldable: Boolean,
|
|
65
|
-
// window coordinates of the area popups center in and sheets rest on the bottom of
|
|
66
|
-
val placement: DpRect,
|
|
67
|
-
val popup: PopupGeometry,
|
|
68
|
-
val sheet: SheetGeometry,
|
|
69
|
-
val scrimOpacity: Float,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
// Foldable = iPhone Duo or a window whose short side is at least FOLDABLE_MIN_WIDTH (RN parity),
|
|
73
|
-
// so phones in landscape keep their look.
|
|
74
|
-
@Composable
|
|
75
|
-
internal fun rememberModalLayout(): ModalLayout {
|
|
76
|
-
val layout = getScreenLayout()
|
|
77
|
-
return remember(layout) { modalLayoutOf(layout) }
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
internal fun modalLayoutOf(layout: ScreenLayout): ModalLayout = modalLayoutOf(
|
|
81
|
-
width = layout.width,
|
|
82
|
-
height = layout.height,
|
|
83
|
-
insetLeft = layout.insetLeft,
|
|
84
|
-
insetTop = layout.insetTop,
|
|
85
|
-
insetRight = layout.insetRight,
|
|
86
|
-
insetBottom = layout.insetBottom,
|
|
87
|
-
isIPhoneDuoDevice = layout.isIPhoneDuoDevice,
|
|
88
|
-
hinge = layout.hinge,
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Resolves popup / bottom sheet geometry from plain window metrics, for hosts without a kits screen.
|
|
93
|
-
*
|
|
94
|
-
* All values are in dp and window coordinates. The insets are the raw safe area (system bars and
|
|
95
|
-
* display cutout); on iPhone Duo they also carry the control column. [hinge] is the vertical hinge of
|
|
96
|
-
* a half-folded iPhone Duo, null while flat. Pure: no composition needed.
|
|
97
|
-
*/
|
|
98
|
-
fun modalLayoutOf(
|
|
99
|
-
width: Dp,
|
|
100
|
-
height: Dp,
|
|
101
|
-
insetLeft: Dp = 0.dp,
|
|
102
|
-
insetTop: Dp = 0.dp,
|
|
103
|
-
insetRight: Dp = 0.dp,
|
|
104
|
-
insetBottom: Dp = 0.dp,
|
|
105
|
-
isIPhoneDuoDevice: Boolean = false,
|
|
106
|
-
hinge: DpRect? = null,
|
|
107
|
-
): ModalLayout {
|
|
108
|
-
val isFoldable = isIPhoneDuoDevice || minOf(width, height) >= FOLDABLE_MIN_WIDTH
|
|
109
|
-
if (!isFoldable) {
|
|
110
|
-
val placement = DpRect(0.dp, 0.dp, width, height)
|
|
111
|
-
return ModalLayout(
|
|
112
|
-
isFoldable = false,
|
|
113
|
-
placement = placement,
|
|
114
|
-
popup = popupGeometry(placement.width, null, Spacing.XL, Radius.L),
|
|
115
|
-
sheet = SheetGeometry(width = null, maxHeight = null, minHeight = 0.dp, margin = 0.dp, radius = Radius.M),
|
|
116
|
-
scrimOpacity = PHONE_SCRIM_OPACITY,
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// the safe area keeps overlays clear of the iPhone Duo control column; half folded they move to the right half
|
|
121
|
-
val hinge = hinge?.takeIf { isIPhoneDuoDevice && it.left > 0.dp && it.right < width }
|
|
122
|
-
val placement = DpRect(
|
|
123
|
-
left = maxOf(insetLeft, hinge?.right ?: 0.dp),
|
|
124
|
-
top = insetTop,
|
|
125
|
-
right = width - insetRight,
|
|
126
|
-
bottom = height - insetBottom,
|
|
127
|
-
)
|
|
128
|
-
// outer display and half fold leave little room, so the margins tighten
|
|
129
|
-
val isCompact = isIPhoneDuoDevice && (hinge != null || minOf(width, height) < FOLDABLE_MIN_WIDTH)
|
|
130
|
-
val popupMargin = if (isCompact) Spacing.M else Spacing.XL
|
|
131
|
-
val sheetMargin = Spacing.M
|
|
132
|
-
val sheetMaxHeight = height - insetTop - sheetMargin
|
|
133
|
-
val sheetMinWidth = minOf(SHEET_MIN_WIDTH, placement.width)
|
|
134
|
-
return ModalLayout(
|
|
135
|
-
isFoldable = true,
|
|
136
|
-
placement = placement,
|
|
137
|
-
popup = popupGeometry(
|
|
138
|
-
placementWidth = placement.width,
|
|
139
|
-
maxHeight = minOf(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
140
|
-
margin = popupMargin,
|
|
141
|
-
radius = Radius.XL,
|
|
142
|
-
),
|
|
143
|
-
sheet = SheetGeometry(
|
|
144
|
-
width = minOf(placement.width - sheetMargin * 2, SHEET_MAX_WIDTH).coerceAtLeast(sheetMinWidth),
|
|
145
|
-
maxHeight = sheetMaxHeight,
|
|
146
|
-
minHeight = minOf(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
147
|
-
margin = sheetMargin,
|
|
148
|
-
radius = Radius.XL,
|
|
149
|
-
),
|
|
150
|
-
scrimOpacity = FOLDABLE_SCRIM_OPACITY,
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// clamp(placement - 2 margin, 280, 450); the 280 floor gives way to a narrower placement
|
|
155
|
-
private fun popupGeometry(placementWidth: Dp, maxHeight: Dp?, margin: Dp, radius: Dp): PopupGeometry {
|
|
156
|
-
val minWidth = minOf(POPUP_MIN_WIDTH, placementWidth)
|
|
157
|
-
return PopupGeometry(
|
|
158
|
-
minWidth = minWidth,
|
|
159
|
-
maxWidth = (placementWidth - margin * 2).coerceIn(minWidth, POPUP_MAX_WIDTH.coerceAtLeast(minWidth)),
|
|
160
|
-
maxHeight = maxHeight,
|
|
161
|
-
margin = margin,
|
|
162
|
-
radius = radius,
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Popup close and sheet header back / close: 32 circle on the surface with a border, 20 icon.
|
|
167
|
-
@Composable
|
|
168
|
-
fun ModalIconButton(
|
|
169
|
-
icon: String,
|
|
170
|
-
automationId: String,
|
|
171
|
-
onClick: () -> Unit,
|
|
172
|
-
modifier: Modifier = Modifier,
|
|
173
|
-
) {
|
|
174
|
-
val colors = AppTheme.current.colors
|
|
175
|
-
Box(
|
|
176
|
-
modifier
|
|
177
|
-
.size(MODAL_ICON_BUTTON_SIZE)
|
|
178
|
-
.clip(CircleShape)
|
|
179
|
-
.background(colors.background.surface)
|
|
180
|
-
.border(1.dp, colors.border.default, CircleShape)
|
|
181
|
-
.noFeedbackClickable(onClick = onClick)
|
|
182
|
-
.setAutomationId(automationId),
|
|
183
|
-
contentAlignment = Alignment.Center,
|
|
184
|
-
) {
|
|
185
|
-
Icon(source = icon, size = CLOSE_ICON_SIZE, color = colors.text.default)
|
|
186
|
-
}
|
|
187
|
-
}
|
package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt
DELETED
|
@@ -1,380 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
}
|