From 16d360302b4a6ee7106da05a64a9f9d4c496364a Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Tue, 24 Dec 2024 00:58:16 +0600 Subject: [PATCH] Add more configuration for bottomSheet navigation --- .../dev/hrach/navigation/bottomsheet/BottomSheetHost.kt | 6 +++++- .../hrach/navigation/bottomsheet/BottomSheetNavigator.kt | 2 ++ .../bottomsheet/BottomSheetNavigatorDestinationBuilder.kt | 4 ++++ .../dev/hrach/navigation/bottomsheet/NavGraphBuilder.kt | 8 ++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetHost.kt b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetHost.kt index 14c8ecc..df69eae 100644 --- a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetHost.kt +++ b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetHost.kt @@ -105,6 +105,7 @@ private fun BottomSheetHost( val destination = targetBackStackEntry?.destination as? BottomSheetNavigator.Destination val sheetState = rememberModalBottomSheetState( skipPartiallyExpanded = destination?.skipPartiallyExpanded ?: true, + confirmValueChange = { destination?.confirmValueChange ?: true }, ) @Suppress("ProduceStateDoesNotAssignValue") // false positive @@ -175,7 +176,10 @@ private fun BottomSheetHost( scrimColor = scrimColor, dragHandle = dragHandle, contentWindowInsets = contentWindowInsets, - properties = ModalBottomSheetProperties(securePolicy = destination.securePolicy), + properties = ModalBottomSheetProperties( + securePolicy = destination.securePolicy, + shouldDismissOnBackPress = destination.shouldDismissOnBackPress, + ), ) { LaunchedEffect(backStackEntry) { navigator.onTransitionComplete(backStackEntry) diff --git a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigator.kt b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigator.kt index abd4692..32a6c81 100644 --- a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigator.kt +++ b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigator.kt @@ -54,6 +54,8 @@ public class BottomSheetNavigator : Navigator( internal val content: @Composable (NavBackStackEntry) -> Unit, ) : NavDestination(navigator), FloatingWindow { internal var securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit + internal var shouldDismissOnBackPress: Boolean = true + internal var confirmValueChange: Boolean = true internal var skipPartiallyExpanded: Boolean = true } } diff --git a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigatorDestinationBuilder.kt b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigatorDestinationBuilder.kt index 3f80e77..21986a2 100644 --- a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigatorDestinationBuilder.kt +++ b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/BottomSheetNavigatorDestinationBuilder.kt @@ -21,7 +21,9 @@ public class BottomSheetNavigatorDestinationBuilder : private val content: @Composable (NavBackStackEntry) -> Unit public var securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit + public var shouldDismissOnBackPress: Boolean = true public var skipPartiallyExpanded: Boolean = true + public var confirmValueChange: Boolean = true /** * DSL for constructing a new [BottomSheetNavigator.Destination] @@ -66,6 +68,8 @@ public class BottomSheetNavigatorDestinationBuilder : return super.build().also { destination -> destination.securePolicy = securePolicy destination.skipPartiallyExpanded = skipPartiallyExpanded + destination.confirmValueChange = confirmValueChange + destination.shouldDismissOnBackPress = shouldDismissOnBackPress } } } diff --git a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/NavGraphBuilder.kt b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/NavGraphBuilder.kt index 41b4a18..e08af6b 100644 --- a/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/NavGraphBuilder.kt +++ b/bottomsheet/src/main/kotlin/dev/hrach/navigation/bottomsheet/NavGraphBuilder.kt @@ -14,7 +14,9 @@ public inline fun NavGraphBuilder.bottomSheet( typeMap: Map> = emptyMap(), deepLinks: List = emptyList(), securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit, + shouldDismissOnBackPress: Boolean = true, skipPartiallyExpanded: Boolean = true, + confirmValueChange: Boolean = true, noinline content: @Composable (NavBackStackEntry) -> Unit, ) { destination( @@ -28,7 +30,9 @@ public inline fun NavGraphBuilder.bottomSheet( deepLink(deepLink) } this.securePolicy = securePolicy + this.shouldDismissOnBackPress = shouldDismissOnBackPress this.skipPartiallyExpanded = skipPartiallyExpanded + this.confirmValueChange = confirmValueChange }, ) } @@ -38,7 +42,9 @@ public fun NavGraphBuilder.bottomSheet( arguments: List = emptyList(), deepLinks: List = emptyList(), securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit, + shouldDismissOnBackPress: Boolean = true, skipPartiallyExpanded: Boolean = true, + confirmValueChange: Boolean = true, content: @Composable (backstackEntry: NavBackStackEntry) -> Unit, ) { destination( @@ -54,7 +60,9 @@ public fun NavGraphBuilder.bottomSheet( deepLink(deepLink) } this.securePolicy = securePolicy + this.shouldDismissOnBackPress = shouldDismissOnBackPress this.skipPartiallyExpanded = skipPartiallyExpanded + this.confirmValueChange = confirmValueChange }, ) }