Skip to content

Commit

Permalink
Add more configuration for bottomSheet navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifulSaif007 committed Dec 23, 2024
1 parent e4d44fb commit 16d3603
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class BottomSheetNavigator : Navigator<BottomSheetNavigator.Destination>(
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -66,6 +68,8 @@ public class BottomSheetNavigatorDestinationBuilder :
return super.build().also { destination ->
destination.securePolicy = securePolicy
destination.skipPartiallyExpanded = skipPartiallyExpanded
destination.confirmValueChange = confirmValueChange
destination.shouldDismissOnBackPress = shouldDismissOnBackPress
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public inline fun <reified T : Any> NavGraphBuilder.bottomSheet(
typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
deepLinks: List<NavDeepLink> = emptyList(),
securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit,
shouldDismissOnBackPress: Boolean = true,
skipPartiallyExpanded: Boolean = true,
confirmValueChange: Boolean = true,
noinline content: @Composable (NavBackStackEntry) -> Unit,
) {
destination(
Expand All @@ -28,7 +30,9 @@ public inline fun <reified T : Any> NavGraphBuilder.bottomSheet(
deepLink(deepLink)
}
this.securePolicy = securePolicy
this.shouldDismissOnBackPress = shouldDismissOnBackPress
this.skipPartiallyExpanded = skipPartiallyExpanded
this.confirmValueChange = confirmValueChange
},
)
}
Expand All @@ -38,7 +42,9 @@ public fun NavGraphBuilder.bottomSheet(
arguments: List<NamedNavArgument> = emptyList(),
deepLinks: List<NavDeepLink> = emptyList(),
securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit,
shouldDismissOnBackPress: Boolean = true,
skipPartiallyExpanded: Boolean = true,
confirmValueChange: Boolean = true,
content: @Composable (backstackEntry: NavBackStackEntry) -> Unit,
) {
destination(
Expand All @@ -54,7 +60,9 @@ public fun NavGraphBuilder.bottomSheet(
deepLink(deepLink)
}
this.securePolicy = securePolicy
this.shouldDismissOnBackPress = shouldDismissOnBackPress
this.skipPartiallyExpanded = skipPartiallyExpanded
this.confirmValueChange = confirmValueChange
},
)
}

0 comments on commit 16d3603

Please sign in to comment.