Skip to content

Commit e14eaed

Browse files
authored
Refactor BottomSheetSceneStrategy to use SceneStrategyScope (#109)
* Refactor BottomSheetSceneStrategy to use SceneStrategyScope Update it to use the APIs from beta01 * Simplify onDismissRequest lambda in BottomSheetScene
1 parent fb87b8d commit e14eaed

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

app/src/main/java/com/example/nav3recipes/bottomsheet/BottomSheetSceneStrategy.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.navigation3.runtime.NavEntry
88
import androidx.navigation3.scene.OverlayScene
99
import androidx.navigation3.scene.Scene
1010
import androidx.navigation3.scene.SceneStrategy
11+
import androidx.navigation3.scene.SceneStrategyScope
1112

1213
/** An [OverlayScene] that renders an [entry] within a [ModalBottomSheet]. */
1314
@OptIn(ExperimentalMaterial3Api::class)
@@ -17,14 +18,14 @@ internal class BottomSheetScene<T : Any>(
1718
override val overlaidEntries: List<NavEntry<T>>,
1819
private val entry: NavEntry<T>,
1920
private val modalBottomSheetProperties: ModalBottomSheetProperties,
20-
private val onBack: (count: Int) -> Unit,
21+
private val onBack: () -> Unit,
2122
) : OverlayScene<T> {
2223

2324
override val entries: List<NavEntry<T>> = listOf(entry)
2425

2526
override val content: @Composable (() -> Unit) = {
2627
ModalBottomSheet(
27-
onDismissRequest = { onBack(1) },
28+
onDismissRequest = onBack,
2829
properties = modalBottomSheetProperties,
2930
) {
3031
entry.Content()
@@ -41,11 +42,7 @@ internal class BottomSheetScene<T : Any>(
4142
@OptIn(ExperimentalMaterial3Api::class)
4243
class BottomSheetSceneStrategy<T : Any> : SceneStrategy<T> {
4344

44-
@Composable
45-
override fun calculateScene(
46-
entries: List<NavEntry<T>>,
47-
onBack: (Int) -> Unit
48-
): Scene<T>? {
45+
override fun SceneStrategyScope<T>.calculateScene(entries: List<NavEntry<T>>): Scene<T>? {
4946
val lastEntry = entries.lastOrNull()
5047
val bottomSheetProperties = lastEntry?.metadata?.get(BOTTOM_SHEET_KEY) as? ModalBottomSheetProperties
5148
return bottomSheetProperties?.let { properties ->

0 commit comments

Comments
 (0)