@momo-kits/native-kits 0.300.7 → 0.300.8-beta.1-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 +12 -8
- package/README.md +8 -7
- package/build.gradle.kts +13 -0
- package/compose/build.gradle.kts +195 -0
- package/compose/build.gradle.kts.backup +195 -0
- package/compose/compose.podspec +47 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
- 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 +6 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsBinding.kt +60 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsHost.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +55 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +130 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +208 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +315 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +212 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +750 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +244 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +398 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +387 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +33 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +38 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +135 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -0
- package/compose/src/commonTest/kotlin/vn/momo/kits/application/KitsHostTest.kt +44 -0
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +39 -0
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +53 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +31 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +65 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
- 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 +143 -0
- package/gradle/libs.versions.toml +66 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/gradle.properties +24 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- package/ios/Application/ApplicationEnvironment.swift +6 -4
- package/ios/Application/DesignSystemKits.swift +59 -13
- package/ios/Application/DesignSystemKitsPayload.swift +0 -8
- package/ios/Application/LanguageSource.swift +2 -11
- package/ios/Application/Localize.swift +8 -35
- package/ios/Application/LocalizeModifier.swift +2 -11
- package/ios/Application/MaxApi.swift +3 -11
- package/ios/Avatar/Avatar.swift +0 -1
- package/ios/Badge/Badge.swift +5 -8
- package/ios/Badge/BadgeRibbon.swift +2 -5
- package/ios/Button/Button.swift +4 -8
- package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +5 -7
- package/ios/Carousel/Carousel.swift +4 -17
- package/ios/Checkbox/Checkbox.swift +0 -2
- package/ios/Collapse/Collapse.swift +17 -11
- package/ios/Colors+Radius+Spacing/Theme.swift +0 -7
- package/ios/DateTimePicker/DateTimePicker.swift +4 -10
- package/ios/DateTimePicker/DateTimePickerTypes.swift +1 -3
- package/ios/DateTimePicker/DateTimePickerUtils.swift +0 -3
- package/ios/DateTimePicker/WheelPicker.swift +2 -4
- package/ios/Extensions/ActiveOpacityButtonStyle.swift +2 -3
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Extensions/SkeletonUICompat.swift +0 -8
- package/ios/Icon/Icon.swift +3 -6
- package/ios/IconButton/IconButton.swift +2 -5
- package/ios/Input/ErrorView.swift +0 -7
- package/ios/Input/Input.swift +9 -20
- package/ios/Input/InputPhoneNumber.swift +37 -20
- package/ios/Input/InputSearch.swift +23 -12
- package/ios/Input/InputTextArea.swift +4 -13
- package/ios/InputDropDown/InputDropDown.swift +1 -11
- package/ios/InputMoney/InputMoney.swift +9 -28
- package/ios/InputOTP/InputOTP.swift +2 -9
- package/ios/Layout/HeaderLayout.swift +72 -0
- package/ios/Layout/Item.swift +1 -2
- package/ios/Layout/ModalLayout.swift +144 -0
- package/ios/Layout/ScreenLayout.swift +48 -31
- package/ios/Layout/Section.swift +2 -3
- package/ios/Loader/Loader.swift +3 -12
- package/ios/Lottie/LottieView.swift +0 -11
- package/ios/Navigation/BottomSheet.swift +73 -94
- package/ios/Navigation/BottomTab/BottomTab.swift +58 -73
- package/ios/Navigation/BottomTab/BottomTabBar.swift +286 -121
- package/ios/Navigation/BottomTab/CurvedContainer.swift +52 -54
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +5 -12
- package/ios/Navigation/BottomTab/DuoTabBar.swift +67 -202
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +97 -0
- package/ios/Navigation/Component/FloatingButton.swift +4 -11
- package/ios/Navigation/Component/Header.swift +35 -54
- package/ios/Navigation/Component/HeaderBackground.swift +2 -8
- package/ios/Navigation/Component/HeaderJourney.swift +4 -8
- package/ios/Navigation/Component/HeaderLocation.swift +4 -8
- package/ios/Navigation/Component/HeaderRight.swift +20 -22
- package/ios/Navigation/Component/HeaderTitle.swift +1 -6
- package/ios/Navigation/Component/HeaderUser.swift +4 -10
- package/ios/Navigation/Component/SideBar.swift +6 -21
- package/ios/Navigation/Component/SnackBar.swift +9 -13
- package/ios/Navigation/HostBackGestureBridge.swift +2 -9
- package/ios/Navigation/ModalScreen.swift +24 -13
- package/ios/Navigation/Navigation.swift +35 -19
- package/ios/Navigation/NavigationContainer.swift +4 -15
- package/ios/Navigation/Navigator.swift +21 -39
- package/ios/Navigation/StackScreen.swift +64 -51
- package/ios/Navigation/StackTransition.swift +7 -14
- package/ios/Navigation/SwipeBackHaptic.swift +2 -7
- package/ios/Navigation/Tracking/ScreenTracker.swift +2 -7
- package/ios/Pagination/PaginationDot.swift +0 -9
- package/ios/Pagination/PaginationNumber.swift +1 -9
- package/ios/Pagination/PaginationScroll.swift +2 -14
- package/ios/Pagination/PaginationWhiteDot.swift +1 -10
- package/ios/Popup/PopupDisplay.swift +7 -5
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -9
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/PopupView/FullscreenPopup.swift +3 -4
- package/ios/PopupView/PopupView.swift +2 -2
- package/ios/PopupView/Utils++.swift +1 -2
- package/ios/ProgressInfo/ProgressInfo.swift +2 -13
- package/ios/Skeleton/Skeleton.swift +5 -16
- package/ios/Slider/Slider.swift +5 -12
- package/ios/StatusBarTap/StatusBarTap.h +2 -3
- package/ios/StatusBarTap/StatusBarTap.m +3 -16
- package/ios/Stepper/Stepper.swift +8 -27
- package/ios/Steps/Steps.swift +29 -26
- package/ios/Swipeable/SwipeCell.swift +2 -2
- package/ios/Swipeable/SwipeCellModel.swift +3 -6
- package/ios/TabView/TabView.swift +14 -28
- package/ios/Template/TrustBanner/TrustBanner.swift +2 -9
- package/ios/Title/Title.swift +1 -3
- package/ios/Tooltip/Tooltip.swift +4 -9
- package/ios/Typography/FontScale.swift +79 -24
- package/ios/Typography/Text.swift +6 -12
- package/ios/Typography/Typography.swift +8 -11
- package/ios/Uploader/Uploader.swift +2 -17
- package/ios-demo/README.md +120 -0
- 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/AnimatedHeaderDemo.swift +11 -2
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +296 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputPhoneNumberDemo.swift +15 -4
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LocalizeDemo.swift +0 -8
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +114 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +16 -0
- package/package.json +1 -1
- package/publish.sh +8 -2
- package/scripts/ci/build-swiftui.sh +22 -0
- package/scripts/ci/resolve-version.mjs +144 -0
- package/settings.gradle.kts +63 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
import androidx.compose.foundation.layout.Box
|
|
4
|
+
import androidx.compose.foundation.layout.absolutePadding
|
|
5
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
6
|
+
import androidx.compose.runtime.Composable
|
|
7
|
+
import androidx.compose.runtime.MutableState
|
|
8
|
+
import androidx.compose.runtime.key
|
|
9
|
+
import androidx.compose.runtime.mutableStateOf
|
|
10
|
+
import androidx.compose.runtime.staticCompositionLocalOf
|
|
11
|
+
import androidx.compose.ui.Alignment
|
|
12
|
+
import androidx.compose.ui.Modifier
|
|
13
|
+
import androidx.navigation.NavController
|
|
14
|
+
import androidx.navigation.toRoute
|
|
15
|
+
import kotlinx.coroutines.CoroutineScope
|
|
16
|
+
import kotlinx.coroutines.Dispatchers
|
|
17
|
+
import kotlinx.coroutines.SupervisorJob
|
|
18
|
+
import kotlinx.coroutines.cancel
|
|
19
|
+
import kotlinx.coroutines.delay
|
|
20
|
+
import kotlinx.coroutines.launch
|
|
21
|
+
import kotlinx.serialization.Serializable
|
|
22
|
+
import vn.momo.kits.components.PopupAction
|
|
23
|
+
import vn.momo.kits.components.PopupNotify
|
|
24
|
+
import vn.momo.kits.layout.getScreenLayout
|
|
25
|
+
import vn.momo.kits.modifier.conditional
|
|
26
|
+
import vn.momo.kits.navigation.BottomHeader.*
|
|
27
|
+
import vn.momo.kits.navigation.component.SnackBar
|
|
28
|
+
import vn.momo.kits.application.KitsBinding
|
|
29
|
+
import vn.momo.kits.application.KitsDismissTarget
|
|
30
|
+
import kotlin.time.Duration.Companion.milliseconds
|
|
31
|
+
|
|
32
|
+
class Navigator(
|
|
33
|
+
private val navController: NavController,
|
|
34
|
+
private val binding: KitsBinding?,
|
|
35
|
+
private val registry: DynamicScreenRegistry
|
|
36
|
+
) {
|
|
37
|
+
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
38
|
+
|
|
39
|
+
// currentScreen() reads the root back stack, so it never sees the nested tab NavHost.
|
|
40
|
+
internal var tabBackHandler: (() -> Unit)? = null
|
|
41
|
+
|
|
42
|
+
private fun currentScreen(): DynamicScreen? {
|
|
43
|
+
val entry = navController.currentBackStackEntry ?: return null
|
|
44
|
+
val id = runCatching { entry.toRoute<DynamicScreenRoute>().id }.getOrNull()
|
|
45
|
+
?: runCatching { entry.toRoute<DynamicDialogRoute>().id }.getOrNull()
|
|
46
|
+
?: return null
|
|
47
|
+
return registry.getScreen(id)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fun push(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
51
|
+
val route = registry.register(screenName, content, options)
|
|
52
|
+
navController.navigate(DynamicScreenRoute(route.id))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fun replace(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
56
|
+
val replacedScreen = currentScreen()
|
|
57
|
+
replacedScreen?.let { registry.unregisterScreen(it.id) }
|
|
58
|
+
navController.popBackStack()
|
|
59
|
+
push(screenName, content, options)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fun onBackSafe(callBack: (() -> Unit)? = null) {
|
|
63
|
+
// An open modal or bottom sheet takes the back first, as its BackHandler does for gestures.
|
|
64
|
+
val overplayType = OverplayComponentRegistry.getOverplayType()
|
|
65
|
+
if (overplayType != null && overplayType != OverplayComponentType.SNACK_BAR) {
|
|
66
|
+
pop(1, callBack)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
tabBackHandler?.let {
|
|
70
|
+
it()
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
val currentScreen = currentScreen()
|
|
74
|
+
val options = currentScreen?.options
|
|
75
|
+
if (options?.onBackHandler != null) {
|
|
76
|
+
options.onBackHandler.invoke()
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
val preventBack = options?.headerBackProps?.preventBack
|
|
80
|
+
if (preventBack != null) {
|
|
81
|
+
showModal(
|
|
82
|
+
content = {
|
|
83
|
+
PopupNotify(preventBack.copy(
|
|
84
|
+
primary = PopupAction(
|
|
85
|
+
title = preventBack.primary?.title ?: "",
|
|
86
|
+
onPress = {
|
|
87
|
+
preventBack.primary?.onPress?.invoke()
|
|
88
|
+
pop(2, callBack) // close popup notify, then close the screen
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
))
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
} else {
|
|
95
|
+
pop(1, callBack)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Public for the iOS host (does the kit own this swipe?). False on the root, so StackScreen keeps custom
|
|
100
|
+
// back handling and the back still reaches binding.dismiss.
|
|
101
|
+
fun canPop(): Boolean = navController.previousBackStackEntry != null
|
|
102
|
+
|
|
103
|
+
fun pop(count: Int = 1, callBack: (() -> Unit)? = null) {
|
|
104
|
+
scope.launch {
|
|
105
|
+
repeat(count) {
|
|
106
|
+
if (OverplayComponentRegistry.getOverplayType() == OverplayComponentType.SNACK_BAR){
|
|
107
|
+
dismissScreen()
|
|
108
|
+
OverplayComponentRegistry.hardClearAfterDismiss()
|
|
109
|
+
}
|
|
110
|
+
else if (OverplayComponentRegistry.isOverplayShowing()){
|
|
111
|
+
dismissOverplay()
|
|
112
|
+
} else {
|
|
113
|
+
dismissScreen()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
callBack?.invoke()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
private suspend fun dismissOverplay(isDelay: Boolean = true) {
|
|
120
|
+
val dismissing = OverplayComponentRegistry.current()
|
|
121
|
+
OverplayComponentRegistry.clear()
|
|
122
|
+
if (isDelay) delay(300L.milliseconds)
|
|
123
|
+
OverplayComponentRegistry.hardClearAfterDismiss(dismissing)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private suspend fun dismissScreen() {
|
|
127
|
+
if (navController.previousBackStackEntry != null){
|
|
128
|
+
val dismissing = currentScreen()
|
|
129
|
+
navController.popBackStack()
|
|
130
|
+
delay(STACK_TRANSITION_DURATION.milliseconds)
|
|
131
|
+
dismissing?.let { registry.unregisterScreen(it.id) }
|
|
132
|
+
} else {
|
|
133
|
+
binding?.dismiss(KitsDismissTarget.Current)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fun present(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
138
|
+
val route = registry.register(screenName, content, options)
|
|
139
|
+
navController.navigate(DynamicDialogRoute(route.id))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fun reset(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
143
|
+
registry.unregisterAll()
|
|
144
|
+
|
|
145
|
+
val route = registry.register(screenName, content, options)
|
|
146
|
+
navController.navigate(DynamicScreenRoute(route.id)) {
|
|
147
|
+
popUpTo(0) { inclusive = true }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fun showModal(
|
|
152
|
+
content: @Composable () -> Unit,
|
|
153
|
+
barrierDismissible: Boolean = true,
|
|
154
|
+
onDismiss: (() -> Unit)? = null
|
|
155
|
+
){
|
|
156
|
+
val id = currentScreen()?.id ?: -1
|
|
157
|
+
OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.MODAL, false, barrierDismissible, onDismiss)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
fun showBottomSheet(
|
|
161
|
+
content: @Composable () -> Unit,
|
|
162
|
+
isSurface: Boolean = false,
|
|
163
|
+
barrierDismissible: Boolean = true,
|
|
164
|
+
onDismiss: (() -> Unit)? = null,
|
|
165
|
+
bottomSheetHeader: BottomHeader? = null,
|
|
166
|
+
draggable: Boolean = true,
|
|
167
|
+
useBottomInset: Boolean = true,
|
|
168
|
+
footerComponent: (@Composable () -> Unit)? = null
|
|
169
|
+
){
|
|
170
|
+
val id = currentScreen()?.id ?: -1
|
|
171
|
+
OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.BOTTOM_SHEET, isSurface, barrierDismissible, onDismiss, bottomSheetHeader, draggable, useBottomInset, footerComponent)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fun showSnackBar(snackBar: SnackBar, onDismiss: (() -> Unit)? = null) {
|
|
175
|
+
val id = currentScreen()?.id ?: -1
|
|
176
|
+
scope.launch {
|
|
177
|
+
OverplayComponentRegistry.registerOverplay(
|
|
178
|
+
id = id,
|
|
179
|
+
content = {
|
|
180
|
+
SnackBar(snackBar, onDismiss)
|
|
181
|
+
},
|
|
182
|
+
type = OverplayComponentType.SNACK_BAR,
|
|
183
|
+
onDismiss = onDismiss
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
fun hideSnackBar() {
|
|
189
|
+
scope.launch {
|
|
190
|
+
val dismissing = OverplayComponentRegistry.current()
|
|
191
|
+
OverplayComponentRegistry.clear()
|
|
192
|
+
delay(250L.milliseconds)
|
|
193
|
+
OverplayComponentRegistry.hardClearAfterDismiss(dismissing)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
fun dispose(){
|
|
198
|
+
scope.cancel()
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
val LocalNavigator = staticCompositionLocalOf<Navigator> {
|
|
203
|
+
error("No NavigationStack provided")
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
@Serializable
|
|
207
|
+
data class DynamicScreenRoute(val id: Int)
|
|
208
|
+
|
|
209
|
+
@Serializable
|
|
210
|
+
data class DynamicDialogRoute(val id: Int)
|
|
211
|
+
|
|
212
|
+
data class DynamicScreen(
|
|
213
|
+
val id: Int,
|
|
214
|
+
val name: String,
|
|
215
|
+
val content: @Composable () -> Unit,
|
|
216
|
+
var options: NavigationOptions? = null
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
class DynamicScreenRegistry {
|
|
220
|
+
private val screens = mutableMapOf<Int, DynamicScreen>()
|
|
221
|
+
|
|
222
|
+
fun register(screenName: String, content: @Composable () -> Unit, options: NavigationOptions?): DynamicScreenRoute {
|
|
223
|
+
val id = nextGlobalId()
|
|
224
|
+
screens[id] = DynamicScreen(
|
|
225
|
+
id = id,
|
|
226
|
+
name = screenName,
|
|
227
|
+
content = content,
|
|
228
|
+
options = options
|
|
229
|
+
)
|
|
230
|
+
return DynamicScreenRoute(id)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
fun nextId(): Int = nextGlobalId()
|
|
234
|
+
|
|
235
|
+
fun bind(id: Int, screenName: String, content: @Composable () -> Unit, options: NavigationOptions?) {
|
|
236
|
+
screens[id] = DynamicScreen(
|
|
237
|
+
id = id,
|
|
238
|
+
name = screenName,
|
|
239
|
+
content = content,
|
|
240
|
+
options = options
|
|
241
|
+
)
|
|
242
|
+
advanceGlobalIdPast(id) // keep counter ahead after process-death restore
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
fun unregisterScreen(id: Int) {
|
|
246
|
+
screens.remove(id)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Gesture pops go through composeNavigator.popBackStack() inside NavHost and never reach
|
|
250
|
+
// Navigator.dismissScreen(), so screens would leak without a stack-driven prune.
|
|
251
|
+
fun retainOnly(ids: Set<Int>) {
|
|
252
|
+
val stale = screens.keys.filter { it !in ids }
|
|
253
|
+
for (id in stale) {
|
|
254
|
+
screens.remove(id)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
fun unregisterAll(){
|
|
259
|
+
val ids = screens.keys.toList()
|
|
260
|
+
for (id in ids) {
|
|
261
|
+
unregisterScreen(id)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fun getScreen(id: Int): DynamicScreen? = screens[id]
|
|
266
|
+
|
|
267
|
+
fun setOptions(id: Int, options: NavigationOptions){
|
|
268
|
+
screens[id]?.options = options
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
companion object {
|
|
272
|
+
private var globalIdCounter = 1
|
|
273
|
+
|
|
274
|
+
private fun nextGlobalId(): Int = globalIdCounter++
|
|
275
|
+
|
|
276
|
+
private fun advanceGlobalIdPast(id: Int) {
|
|
277
|
+
if (id >= globalIdCounter) globalIdCounter = id + 1
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
val LocalDynamicScreenRegistry = staticCompositionLocalOf<DynamicScreenRegistry?> { null }
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
sealed class OverplayComponentParams {
|
|
286
|
+
class Modal(
|
|
287
|
+
val onDismiss: (() -> Unit)? = null,
|
|
288
|
+
val barrierDismissible: Boolean = true
|
|
289
|
+
) : OverplayComponentParams()
|
|
290
|
+
|
|
291
|
+
class BottomSheet(
|
|
292
|
+
val isSurface: Boolean = false,
|
|
293
|
+
val onDismiss: (() -> Unit)? = null,
|
|
294
|
+
val barrierDismissible: Boolean = true,
|
|
295
|
+
val bottomSheetHeader: BottomHeader? = null,
|
|
296
|
+
val draggable: Boolean = true,
|
|
297
|
+
val useBottomInset: Boolean = true,
|
|
298
|
+
val footerComponent: (@Composable () -> Unit)? = null,
|
|
299
|
+
) : OverplayComponentParams()
|
|
300
|
+
|
|
301
|
+
class SnackBar : OverplayComponentParams()
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
data class OverplayComponent(
|
|
305
|
+
val id: Int,
|
|
306
|
+
val type: OverplayComponentType? = null,
|
|
307
|
+
val content: @Composable () -> Unit,
|
|
308
|
+
val params: OverplayComponentParams? = null
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
enum class OverplayComponentType {
|
|
312
|
+
MODAL, BOTTOM_SHEET, SNACK_BAR
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
object OverplayComponentRegistry {
|
|
316
|
+
private var currentOverlayComponent : MutableState<OverplayComponent?> = mutableStateOf(null)
|
|
317
|
+
private var requestClose: (() -> Unit)? = null
|
|
318
|
+
internal fun bindClose(handler: (() -> Unit)?) {
|
|
319
|
+
requestClose = handler
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
fun registerOverplay(
|
|
323
|
+
id: Int,
|
|
324
|
+
content: @Composable () -> Unit,
|
|
325
|
+
type: OverplayComponentType,
|
|
326
|
+
isSurface: Boolean = false,
|
|
327
|
+
barrierDismissible: Boolean = true,
|
|
328
|
+
onDismiss: (() -> Unit)?,
|
|
329
|
+
bottomSheetHeader: BottomHeader? = null,
|
|
330
|
+
draggable: Boolean = true,
|
|
331
|
+
useBottomInset: Boolean = true,
|
|
332
|
+
footerComponent: (@Composable () -> Unit)? = null,
|
|
333
|
+
){
|
|
334
|
+
val params = when(type){
|
|
335
|
+
OverplayComponentType.MODAL -> OverplayComponentParams.Modal(onDismiss, barrierDismissible)
|
|
336
|
+
OverplayComponentType.BOTTOM_SHEET -> OverplayComponentParams.BottomSheet(isSurface, onDismiss, barrierDismissible, bottomSheetHeader, draggable, useBottomInset, footerComponent)
|
|
337
|
+
OverplayComponentType.SNACK_BAR -> OverplayComponentParams.SnackBar()
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
currentOverlayComponent.value = OverplayComponent(
|
|
341
|
+
id = id,
|
|
342
|
+
type = type,
|
|
343
|
+
content = content,
|
|
344
|
+
params = params
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
fun isOverplayShowing(): Boolean = currentOverlayComponent.value != null
|
|
349
|
+
|
|
350
|
+
fun getOverplayType(): OverplayComponentType? = currentOverlayComponent.value?.type
|
|
351
|
+
|
|
352
|
+
fun currentRootId(): Int? = currentOverlayComponent.value?.id
|
|
353
|
+
|
|
354
|
+
fun clear(){
|
|
355
|
+
if (requestClose != null) {
|
|
356
|
+
requestClose?.invoke()
|
|
357
|
+
} else {
|
|
358
|
+
currentOverlayComponent.value = null
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
internal fun hardClearAfterDismiss() {
|
|
363
|
+
currentOverlayComponent.value = null
|
|
364
|
+
requestClose = null
|
|
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
|
+
|
|
374
|
+
@Composable
|
|
375
|
+
internal fun OverlayComponent(){
|
|
376
|
+
val overplay = currentOverlayComponent.value ?: return
|
|
377
|
+
|
|
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
|
+
}
|
|
394
|
+
|
|
395
|
+
is OverplayComponentParams.Modal -> {
|
|
396
|
+
ModalScreen(
|
|
397
|
+
content = overplay.content,
|
|
398
|
+
barrierDismissible = params.barrierDismissible,
|
|
399
|
+
onDismiss = params.onDismiss
|
|
400
|
+
)
|
|
401
|
+
}
|
|
402
|
+
|
|
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
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
null -> {}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|