@momo-kits/native-kits 0.168.1-beta.4-debug → 0.168.1-beta.40-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 +15 -10
- package/README.md +2 -10
- package/build.gradle.kts +1 -3
- package/compose/build.gradle.kts +20 -19
- package/compose/build.gradle.kts.backup +19 -18
- package/compose/compose.podspec +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +4 -3
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +14 -23
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +84 -82
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +18 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +20 -13
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +117 -62
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +22 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -26
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +54 -36
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +1 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +35 -29
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +89 -198
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +30 -44
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +32 -40
- 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/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +12 -3
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +3 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +2 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -10
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +60 -10
- package/gradle/libs.versions.toml +4 -11
- package/gradle/wrapper/gradle-wrapper.properties +1 -3
- package/gradle.properties +3 -3
- package/ios/Application/ApplicationEnvironment.swift +7 -6
- package/ios/Application/DesignSystemKits.swift +163 -0
- package/ios/Application/DesignSystemKitsPayload.swift +68 -0
- package/ios/Badge/BadgeRibbon.swift +8 -1
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Input/Input.swift +16 -4
- package/ios/Input/InputPhoneNumber.swift +1 -3
- package/ios/Input/InputSearch.swift +1 -2
- package/ios/Input/InputTextArea.swift +8 -4
- package/ios/InputMoney/InputMoney.swift +6 -7
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +77 -18
- package/ios/Navigation/BottomSheet.swift +56 -53
- package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
- package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
- package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
- package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderBackground.swift +22 -1
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/Component/SnackBar.swift +4 -0
- package/ios/Navigation/ModalScreen.swift +20 -5
- package/ios/Navigation/StackScreen.swift +6 -8
- package/ios/Popup/PopupDisplay.swift +6 -4
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -11
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/Stepper/Stepper.swift +1 -2
- package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
- package/ios/Typography/FontScale.swift +29 -15
- package/ios/Typography/Text.swift +88 -14
- package/ios/Typography/Typography.swift +2 -2
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- 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 +103 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/package.json +1 -1
- package/publish.sh +2 -33
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +0 -37
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -41
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +0 -44
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -62
- package/ios/Typography/FontScaleStore.swift +0 -58
- package/ios/Typography/KitDesignSystem.swift +0 -17
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
package vn.momo.kits.navigation
|
|
2
2
|
|
|
3
3
|
import androidx.compose.foundation.layout.Box
|
|
4
|
+
import androidx.compose.foundation.layout.absolutePadding
|
|
4
5
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
5
6
|
import androidx.compose.runtime.Composable
|
|
6
7
|
import androidx.compose.runtime.MutableState
|
|
8
|
+
import androidx.compose.runtime.key
|
|
7
9
|
import androidx.compose.runtime.mutableStateOf
|
|
8
10
|
import androidx.compose.runtime.staticCompositionLocalOf
|
|
9
11
|
import androidx.compose.ui.Alignment
|
|
@@ -19,12 +21,11 @@ import kotlinx.coroutines.launch
|
|
|
19
21
|
import kotlinx.serialization.Serializable
|
|
20
22
|
import vn.momo.kits.components.PopupAction
|
|
21
23
|
import vn.momo.kits.components.PopupNotify
|
|
24
|
+
import vn.momo.kits.layout.getScreenLayout
|
|
25
|
+
import vn.momo.kits.modifier.conditional
|
|
22
26
|
import vn.momo.kits.navigation.BottomHeader.*
|
|
23
27
|
import vn.momo.kits.navigation.component.SnackBar
|
|
24
28
|
import vn.momo.maxapi.IMaxApi
|
|
25
|
-
// AI-GENERATED START: dismiss through the typed navigator target
|
|
26
|
-
import vn.momo.maxapi.contract.navigation.model.DismissTarget
|
|
27
|
-
// AI-GENERATED END: dismiss through the typed navigator target
|
|
28
29
|
import kotlin.time.Duration.Companion.milliseconds
|
|
29
30
|
|
|
30
31
|
class Navigator(
|
|
@@ -116,9 +117,10 @@ class Navigator(
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
private suspend fun dismissOverplay(isDelay: Boolean = true) {
|
|
120
|
+
val dismissing = OverplayComponentRegistry.current()
|
|
119
121
|
OverplayComponentRegistry.clear()
|
|
120
122
|
if (isDelay) delay(300L.milliseconds)
|
|
121
|
-
OverplayComponentRegistry.hardClearAfterDismiss()
|
|
123
|
+
OverplayComponentRegistry.hardClearAfterDismiss(dismissing)
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
private suspend fun dismissScreen() {
|
|
@@ -128,9 +130,7 @@ class Navigator(
|
|
|
128
130
|
delay(STACK_TRANSITION_DURATION.milliseconds)
|
|
129
131
|
dismissing?.let { registry.unregisterScreen(it.id) }
|
|
130
132
|
} else {
|
|
131
|
-
|
|
132
|
-
maxApi?.dismiss(DismissTarget.Current()) {}
|
|
133
|
-
// AI-GENERATED END: preserve root-screen dismissal
|
|
133
|
+
maxApi?.dismiss { }
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -187,9 +187,10 @@ class Navigator(
|
|
|
187
187
|
|
|
188
188
|
fun hideSnackBar() {
|
|
189
189
|
scope.launch {
|
|
190
|
+
val dismissing = OverplayComponentRegistry.current()
|
|
190
191
|
OverplayComponentRegistry.clear()
|
|
191
192
|
delay(250L.milliseconds)
|
|
192
|
-
OverplayComponentRegistry.hardClearAfterDismiss()
|
|
193
|
+
OverplayComponentRegistry.hardClearAfterDismiss(dismissing)
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
@@ -363,42 +364,59 @@ object OverplayComponentRegistry {
|
|
|
363
364
|
requestClose = null
|
|
364
365
|
}
|
|
365
366
|
|
|
367
|
+
internal fun current(): OverplayComponent? = currentOverlayComponent.value
|
|
368
|
+
|
|
369
|
+
// An overlay shown from the dismissed one's onDismiss, before the delayed clear, stays.
|
|
370
|
+
internal fun hardClearAfterDismiss(dismissing: OverplayComponent?) {
|
|
371
|
+
if (currentOverlayComponent.value === dismissing) hardClearAfterDismiss()
|
|
372
|
+
}
|
|
373
|
+
|
|
366
374
|
@Composable
|
|
367
375
|
internal fun OverlayComponent(){
|
|
368
376
|
val overplay = currentOverlayComponent.value ?: return
|
|
369
377
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
378
|
+
// every registration is its own composition (params are new instances), as SwiftUI's `.id(item.id)`:
|
|
379
|
+
// a sheet shown from another one's close must not inherit its finished animation and effects
|
|
380
|
+
key(overplay) {
|
|
381
|
+
when (val params = overplay.params) {
|
|
382
|
+
is OverplayComponentParams.BottomSheet -> {
|
|
383
|
+
BottomSheet(
|
|
384
|
+
content = overplay.content,
|
|
385
|
+
header = params.bottomSheetHeader ?: Title(),
|
|
386
|
+
isSurface = params.isSurface,
|
|
387
|
+
barrierDismissible = params.barrierDismissible,
|
|
388
|
+
draggable = params.draggable,
|
|
389
|
+
useBottomInset = params.useBottomInset,
|
|
390
|
+
footerComponent = params.footerComponent,
|
|
391
|
+
onDismiss = params.onDismiss
|
|
392
|
+
)
|
|
393
|
+
}
|
|
383
394
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
395
|
+
is OverplayComponentParams.Modal -> {
|
|
396
|
+
ModalScreen(
|
|
397
|
+
content = overplay.content,
|
|
398
|
+
barrierDismissible = params.barrierDismissible,
|
|
399
|
+
onDismiss = params.onDismiss
|
|
400
|
+
)
|
|
401
|
+
}
|
|
391
402
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
403
|
+
is OverplayComponentParams.SnackBar -> {
|
|
404
|
+
val layout = getScreenLayout()
|
|
405
|
+
Box(
|
|
406
|
+
modifier = Modifier
|
|
407
|
+
.fillMaxSize()
|
|
408
|
+
// iPhone Duo: clear of the side toolbar strip, like the screen content
|
|
409
|
+
.conditional(layout.isIPhoneDuo) {
|
|
410
|
+
absolutePadding(left = layout.insetLeft, right = layout.insetRight)
|
|
411
|
+
},
|
|
412
|
+
contentAlignment = Alignment.BottomCenter
|
|
413
|
+
) {
|
|
414
|
+
overplay.content()
|
|
415
|
+
}
|
|
398
416
|
}
|
|
399
|
-
}
|
|
400
417
|
|
|
401
|
-
|
|
418
|
+
null -> {}
|
|
419
|
+
}
|
|
402
420
|
}
|
|
403
421
|
}
|
|
404
422
|
}
|
|
@@ -29,6 +29,7 @@ import androidx.compose.foundation.verticalScroll
|
|
|
29
29
|
import androidx.compose.material.ExperimentalMaterialApi
|
|
30
30
|
import androidx.compose.runtime.Composable
|
|
31
31
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
32
|
+
import androidx.compose.foundation.layout.PaddingValues
|
|
32
33
|
import androidx.compose.runtime.LaunchedEffect
|
|
33
34
|
import androidx.compose.runtime.State
|
|
34
35
|
import androidx.compose.runtime.getValue
|
|
@@ -61,7 +62,6 @@ import vn.momo.kits.const.Colors
|
|
|
61
62
|
import vn.momo.kits.const.Spacing
|
|
62
63
|
import vn.momo.kits.modifier.conditional
|
|
63
64
|
import vn.momo.kits.modifier.hideKeyboardOnTap
|
|
64
|
-
import vn.momo.kits.navigation.bottomtab.BOTTOM_TAB_BAR_HEIGHT
|
|
65
65
|
import vn.momo.kits.navigation.component.FABPosition
|
|
66
66
|
import vn.momo.kits.navigation.component.FloatingButton
|
|
67
67
|
import vn.momo.kits.navigation.component.HEADER_HEIGHT
|
|
@@ -70,6 +70,7 @@ import vn.momo.kits.navigation.component.HeaderBackground
|
|
|
70
70
|
import vn.momo.kits.navigation.component.HeaderRight
|
|
71
71
|
import vn.momo.kits.navigation.component.HeaderSideBar
|
|
72
72
|
import vn.momo.kits.navigation.bottomtab.LocalDuoRailReserve
|
|
73
|
+
import vn.momo.kits.navigation.bottomtab.LocalTabBarHasCenterAction
|
|
73
74
|
import vn.momo.kits.navigation.bottomtab.duoFloatingTabBarInset
|
|
74
75
|
import vn.momo.kits.navigation.component.HeaderType
|
|
75
76
|
import vn.momo.kits.navigation.component.InputSearchType
|
|
@@ -90,21 +91,27 @@ import kotlin.time.Clock
|
|
|
90
91
|
import kotlin.time.Duration.Companion.milliseconds
|
|
91
92
|
import kotlin.time.ExperimentalTime
|
|
92
93
|
|
|
94
|
+
@Composable
|
|
95
|
+
fun floatingTabBarContentPadding(): PaddingValues {
|
|
96
|
+
val navigation = LocalNavigation.current
|
|
97
|
+
LaunchedEffect(navigation) { navigation.bottomTabEdgeToEdge = true }
|
|
98
|
+
val reserve = navigation.bottomTabIndex != -1 && navigation.bottomTabEdgeToEdge
|
|
99
|
+
return PaddingValues(bottom = if (reserve) bottomTabChildInset() else 0.dp)
|
|
100
|
+
}
|
|
101
|
+
|
|
93
102
|
internal val LocalFooterHeightPx = staticCompositionLocalOf { mutableIntStateOf(0) }
|
|
94
103
|
internal val LocalHeaderRightWidthPx = staticCompositionLocalOf { mutableIntStateOf(0) }
|
|
95
104
|
|
|
96
|
-
// Space a tab's content leaves for the tab bar and home indicator
|
|
97
|
-
//
|
|
105
|
+
// Space a tab's content leaves for the tab bar and home indicator: the horizontal bar floats over the
|
|
106
|
+
// content (phone and unfolded Duo); the Duo rail lives in the side strip, so only the home indicator.
|
|
98
107
|
@Composable
|
|
99
108
|
private fun bottomTabChildInset(): Dp {
|
|
100
109
|
val keyboard = keyboardSizeState().value
|
|
101
110
|
val navigationBar = AppNavigationBar.current
|
|
102
111
|
val layout = getScreenLayout()
|
|
103
112
|
return when {
|
|
104
|
-
layout.isIPhoneDuo && layout.sideBar
|
|
105
|
-
|
|
106
|
-
else -> (BOTTOM_TAB_BAR_HEIGHT.dp + Spacing.S - keyboard).coerceAtLeast(0.dp) +
|
|
107
|
-
(navigationBar - keyboard).coerceAtLeast(0.dp)
|
|
113
|
+
layout.isIPhoneDuo && layout.sideBar != null -> (navigationBar - keyboard).coerceAtLeast(0.dp)
|
|
114
|
+
else -> (duoFloatingTabBarInset(layout, LocalTabBarHasCenterAction.current) - keyboard).coerceAtLeast(0.dp)
|
|
108
115
|
}
|
|
109
116
|
}
|
|
110
117
|
|
|
@@ -333,7 +340,6 @@ internal fun ColumnScope.MainContent(content: @Composable () -> Unit, isBottomTa
|
|
|
333
340
|
|
|
334
341
|
Spacer(Modifier.height((HEADER_HEIGHT.dp - scrollDp).coerceIn(0.dp, HEADER_HEIGHT.dp)))
|
|
335
342
|
}
|
|
336
|
-
// a bottom tab root stays full width: the tab bar and each tab's own StackScreen handle the insets
|
|
337
343
|
val insetContent = !isBottomTabRoot
|
|
338
344
|
Column(
|
|
339
345
|
Modifier
|
|
@@ -351,7 +357,8 @@ internal fun ColumnScope.MainContent(content: @Composable () -> Unit, isBottomTa
|
|
|
351
357
|
.padding(
|
|
352
358
|
bottom = when {
|
|
353
359
|
options.hasFooter() || isBottomTabRoot -> 0.dp
|
|
354
|
-
|
|
360
|
+
// 0 when the tab pads itself via floatingTabBarContentPadding(), else the kit reserves the bar space
|
|
361
|
+
isBottomTabChild -> if (LocalNavigation.current.bottomTabEdgeToEdge) 0.dp else bottomTabChildInset()
|
|
355
362
|
!options.scrollData.scrollable && options.scrollData.scrollState == null -> 0.dp
|
|
356
363
|
else -> navigationBar
|
|
357
364
|
}
|
|
@@ -401,8 +408,8 @@ internal fun FooterContent() {
|
|
|
401
408
|
val options = LocalOptions.current
|
|
402
409
|
if (options.hasFooter()) {
|
|
403
410
|
val keyboardSize = keyboardSizeState()
|
|
404
|
-
// the
|
|
405
|
-
val duoTabInset = if (LocalNavigation.current.bottomTabIndex != -1) duoFloatingTabBarInset(getScreenLayout()) else 0.dp
|
|
411
|
+
// the floating tab bar overlays tab content, so a tab's footer sits above it
|
|
412
|
+
val duoTabInset = if (LocalNavigation.current.bottomTabIndex != -1) duoFloatingTabBarInset(getScreenLayout(), LocalTabBarHasCenterAction.current) else 0.dp
|
|
406
413
|
val bottomPadding = (maxOf(AppNavigationBar.current, duoTabInset) - keyboardSize.value).coerceAtLeast(0.dp)
|
|
407
414
|
Footer(
|
|
408
415
|
footerComponent = options.footerComponent,
|
|
@@ -6,9 +6,6 @@ import androidx.compose.runtime.snapshotFlow
|
|
|
6
6
|
import vn.momo.kits.platform.getScreenDimensions
|
|
7
7
|
import vn.momo.kits.platform.rememberBackGestureProgress
|
|
8
8
|
import vn.momo.maxapi.IMaxApi
|
|
9
|
-
// AI-GENERATED START: use the typed light vibration pattern
|
|
10
|
-
import vn.momo.maxapi.contract.device.vibration.model.VibrateStyle
|
|
11
|
-
// AI-GENERATED END: use the typed light vibration pattern
|
|
12
9
|
|
|
13
10
|
// Unscaled, so the tick lands at the same physical distance on every device.
|
|
14
11
|
private const val SWIPE_BACK_HAPTIC_THRESHOLD_DP = 50f
|
|
@@ -28,9 +25,7 @@ internal fun SwipeBackHaptic(maxApi: IMaxApi?) {
|
|
|
28
25
|
snapshotFlow { progress.value }.collect { fraction ->
|
|
29
26
|
val travelled = fraction ?: 0f
|
|
30
27
|
if (travelled >= threshold && !isSendHaptic) {
|
|
31
|
-
|
|
32
|
-
runCatching { maxApi.vibrate(VibrateStyle.LIGHT) }
|
|
33
|
-
// AI-GENERATED END: keep one light tick per threshold crossing
|
|
28
|
+
runCatching { maxApi.triggerEventVibration("light", callback = null) }
|
|
34
29
|
isSendHaptic = true
|
|
35
30
|
} else if (travelled < threshold && isSendHaptic) {
|
|
36
31
|
isSendHaptic = false
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
package vn.momo.kits.navigation.bottomtab
|
|
2
2
|
|
|
3
|
+
import androidx.compose.runtime.getValue
|
|
4
|
+
import androidx.compose.runtime.setValue
|
|
3
5
|
import androidx.compose.animation.core.Animatable
|
|
4
6
|
import androidx.compose.animation.core.AnimationVector1D
|
|
7
|
+
import androidx.compose.animation.core.CubicBezierEasing
|
|
5
8
|
import androidx.compose.animation.core.Easing
|
|
6
9
|
import androidx.compose.animation.core.tween
|
|
7
10
|
import androidx.compose.foundation.background
|
|
@@ -10,14 +13,12 @@ import androidx.compose.runtime.Composable
|
|
|
10
13
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
11
14
|
import androidx.compose.runtime.DisposableEffect
|
|
12
15
|
import androidx.compose.runtime.LaunchedEffect
|
|
13
|
-
import androidx.compose.runtime.getValue
|
|
14
16
|
import androidx.compose.runtime.key
|
|
15
17
|
import androidx.compose.runtime.mutableIntStateOf
|
|
16
18
|
import androidx.compose.runtime.mutableStateOf
|
|
17
19
|
import androidx.compose.runtime.remember
|
|
18
20
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
19
21
|
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
|
|
20
|
-
import androidx.compose.runtime.setValue
|
|
21
22
|
import androidx.compose.runtime.staticCompositionLocalOf
|
|
22
23
|
import androidx.compose.ui.Alignment
|
|
23
24
|
import androidx.compose.ui.Modifier
|
|
@@ -25,9 +26,8 @@ import androidx.compose.ui.graphics.graphicsLayer
|
|
|
25
26
|
import androidx.compose.ui.layout.layout
|
|
26
27
|
import androidx.compose.ui.unit.dp
|
|
27
28
|
import androidx.compose.ui.zIndex
|
|
28
|
-
import
|
|
29
|
+
import kotlin.math.abs
|
|
29
30
|
import vn.momo.kits.const.AppTheme
|
|
30
|
-
import vn.momo.kits.const.Spacing
|
|
31
31
|
import vn.momo.kits.navigation.KeyboardOptions
|
|
32
32
|
import vn.momo.kits.navigation.LocalMaxApi
|
|
33
33
|
import vn.momo.kits.navigation.LocalNavigation
|
|
@@ -39,12 +39,13 @@ import vn.momo.kits.platform.BackHandler
|
|
|
39
39
|
import vn.momo.kits.platform.reportFloatingArrowBack
|
|
40
40
|
import vn.momo.kits.layout.getScreenLayout
|
|
41
41
|
import kotlinx.coroutines.launch
|
|
42
|
-
// AI-GENERATED START: use the typed tab haptic pattern
|
|
43
|
-
import vn.momo.maxapi.contract.device.vibration.model.VibrateStyle
|
|
44
|
-
// AI-GENERATED END: use the typed tab haptic pattern
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
internal val inOutQuad = Easing { t -> if (t < 0.5f) 2 * t * t else 1 - 2 * (1 - t) * (1 - t) }
|
|
44
|
+
// the tab screens slide in index order over 280ms, CSS `ease`
|
|
45
|
+
private val tabSwitchSpec = tween<Float>(durationMillis = 280, easing = CubicBezierEasing(0.25f, 0.1f, 0.25f, 1f))
|
|
46
|
+
|
|
47
|
+
// -1 for tabs before the selected one, 1 for tabs after it: they wait a full width off screen on their side
|
|
48
|
+
private fun tabPosition(index: Int, selected: Int) = (index - selected).coerceIn(-1, 1).toFloat()
|
|
48
49
|
|
|
49
50
|
internal val LocalBottomTabFocused = staticCompositionLocalOf { true }
|
|
50
51
|
|
|
@@ -108,14 +109,21 @@ fun BottomTab(
|
|
|
108
109
|
var lastFocusedIndex by rememberSaveable { mutableStateOf<Int?>(null) }
|
|
109
110
|
val tabProgress = remember { mutableMapOf<Int, Animatable<Float, AnimationVector1D>>() }
|
|
110
111
|
fun progressOf(index: Int) = tabProgress.getOrPut(index) {
|
|
111
|
-
Animatable(
|
|
112
|
+
Animatable(tabPosition(index, lastFocusedIndex ?: index))
|
|
112
113
|
}
|
|
113
114
|
LaunchedEffect(selectedIndex) {
|
|
115
|
+
val previousIndex = lastFocusedIndex
|
|
114
116
|
lastFocusedIndex = selectedIndex
|
|
115
117
|
tabProgress.forEach { (index, progress) ->
|
|
116
|
-
|
|
118
|
+
val target = tabPosition(index, selectedIndex)
|
|
119
|
+
launch {
|
|
120
|
+
if (index == selectedIndex || index == previousIndex) {
|
|
121
|
+
progress.animateTo(target, tabSwitchSpec)
|
|
122
|
+
} else {
|
|
123
|
+
progress.snapTo(target)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
117
126
|
}
|
|
118
|
-
progressOf(selectedIndex).animateTo(1f, tabTimingSpec)
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
DisposableEffect(isFirstTab) {
|
|
@@ -135,9 +143,7 @@ fun BottomTab(
|
|
|
135
143
|
it.bottom + duoRailHeight(items.size, hasQr, compressed = compression.tabBarCompressed) + DUO_GROUP_GAP
|
|
136
144
|
} ?: 0.dp
|
|
137
145
|
val onTabSelected: (Int) -> Unit = { index ->
|
|
138
|
-
|
|
139
|
-
runCatching { maxApi?.vibrate(VibrateStyle.LIGHT) }
|
|
140
|
-
// AI-GENERATED END: preserve the light haptic on tab selection
|
|
146
|
+
runCatching { maxApi?.triggerEventVibration("light", callback = null) }
|
|
141
147
|
val switchTab = {
|
|
142
148
|
if (index != selectedIndex) selectTab(index)
|
|
143
149
|
}
|
|
@@ -152,21 +158,20 @@ fun BottomTab(
|
|
|
152
158
|
CompositionLocalProvider(
|
|
153
159
|
LocalDuoRailReserve provides railReserve,
|
|
154
160
|
LocalDuoBarCompression provides compression,
|
|
161
|
+
LocalTabBarHasCenterAction provides hasCenterAction(floatingButton, items.size),
|
|
155
162
|
) {
|
|
156
163
|
loadedTabs.forEach { index ->
|
|
157
164
|
val item = items.getOrNull(index) ?: return@forEach
|
|
158
165
|
val focused = index == selectedIndex
|
|
159
166
|
val progress = progressOf(index)
|
|
167
|
+
// the leaving tab stays drawn until it has slid off screen
|
|
168
|
+
val visible = focused || abs(progress.value) < 1f
|
|
160
169
|
key(index) {
|
|
161
170
|
Box(
|
|
162
171
|
Modifier
|
|
163
172
|
.fillMaxSize()
|
|
164
173
|
.zIndex(if (focused) 0f else -1f)
|
|
165
|
-
.then(if (
|
|
166
|
-
alpha = 0.3f + 0.7f * progress.value
|
|
167
|
-
scaleX = 0.97f + 0.03f * progress.value
|
|
168
|
-
scaleY = scaleX
|
|
169
|
-
} else Hidden)
|
|
174
|
+
.then(if (visible) Modifier.graphicsLayer { translationX = progress.value * size.width } else Hidden)
|
|
170
175
|
) {
|
|
171
176
|
CompositionLocalProvider(LocalBottomTabFocused provides focused) {
|
|
172
177
|
tabStateHolder.SaveableStateProvider(index) {
|
|
@@ -202,15 +207,12 @@ fun BottomTab(
|
|
|
202
207
|
compression = compression,
|
|
203
208
|
)
|
|
204
209
|
} else {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
)
|
|
212
|
-
Spacer(modifier = Modifier.fillMaxWidth().height(AppNavigationBar.current + Spacing.S).background(AppTheme.current.colors.background.surface))
|
|
213
|
-
}
|
|
210
|
+
BottomTabBar(
|
|
211
|
+
items = items,
|
|
212
|
+
floatingButton = floatingButton,
|
|
213
|
+
selectedIndex = selectedIndex,
|
|
214
|
+
onTabSelected = onTabSelected,
|
|
215
|
+
)
|
|
214
216
|
}
|
|
215
217
|
}
|
|
216
218
|
}
|
|
@@ -230,4 +232,8 @@ data class BottomTabFloatingButton(
|
|
|
230
232
|
val icon: String,
|
|
231
233
|
val label: String,
|
|
232
234
|
val onPress: () -> Unit,
|
|
235
|
+
// replaces the icon inside the 48 button, e.g. the button part of a Lottie; centered, unclipped
|
|
236
|
+
val iconContent: (@Composable () -> Unit)? = null,
|
|
237
|
+
// drawn over the label text, which stays, e.g. the label part of a Lottie; centered, unclipped
|
|
238
|
+
val labelContent: (@Composable () -> Unit)? = null,
|
|
233
239
|
)
|