1616
1717package androidx.navigation.compose.material
1818
19- import android.os.Bundle
2019import androidx.compose.foundation.layout.ColumnScope
2120import androidx.compose.material.ExperimentalMaterialApi
2221import androidx.compose.material.ModalBottomSheetState
2322import androidx.compose.material.ModalBottomSheetValue
23+ import androidx.compose.material.rememberModalBottomSheetState
2424import androidx.compose.runtime.Composable
25- import androidx.compose.runtime.LaunchedEffect
2625import androidx.compose.runtime.collectAsState
2726import androidx.compose.runtime.getValue
2827import androidx.compose.runtime.mutableStateOf
2928import androidx.compose.runtime.remember
3029import androidx.compose.runtime.saveable.rememberSaveableStateHolder
3130import androidx.compose.runtime.setValue
32- import androidx.core.os.bundleOf
3331import androidx.lifecycle.Lifecycle
3432import androidx.navigation.FloatingWindow
3533import androidx.navigation.NavBackStackEntry
@@ -50,7 +48,7 @@ import kotlinx.coroutines.flow.StateFlow
5048@Composable
5149public fun rememberBottomSheetNavigator (
5250 sheetState : ModalBottomSheetState =
53- remember { ModalBottomSheetState (ModalBottomSheetValue .Hidden ) }
51+ rememberModalBottomSheetState (ModalBottomSheetValue .Hidden )
5452): BottomSheetNavigator = remember(sheetState) {
5553 BottomSheetNavigator (sheetState = sheetState)
5654}
@@ -78,7 +76,6 @@ public class BottomSheetNavigator(
7876) : Navigator<BottomSheetNavigator.Destination>() {
7977
8078 private var attached by mutableStateOf(false )
81- private var stateToRestore by mutableStateOf<ModalBottomSheetValue ?>(null )
8279
8380 /* *
8481 * Get the back stack from the [state]. NavHost will compose at least
@@ -109,12 +106,6 @@ public class BottomSheetNavigator(
109106 // these
110107 entry.lifecycle.currentState.isAtLeast(Lifecycle .State .STARTED )
111108 }
112- LaunchedEffect (stateToRestore, latestEntry) {
113- if (stateToRestore != null && latestEntry != null ) {
114- sheetState.snapTo(stateToRestore!! )
115- stateToRestore = null
116- }
117- }
118109 SheetContentHost (
119110 columnHost = columnScope,
120111 backStackEntry = latestEntry,
@@ -129,14 +120,6 @@ public class BottomSheetNavigator(
129120 attached = true
130121 }
131122
132- override fun onSaveState (): Bundle = bundleOf(
133- KEY_SHEET_STATE to sheetState.currentValue
134- )
135-
136- override fun onRestoreState (savedState : Bundle ) {
137- stateToRestore = savedState.get(KEY_SHEET_STATE ) as ModalBottomSheetValue ?
138- }
139-
140123 override fun createDestination (): Destination = Destination (navigator = this , content = {})
141124
142125 /* *
@@ -147,8 +130,4 @@ public class BottomSheetNavigator(
147130 navigator : BottomSheetNavigator ,
148131 internal val content : @Composable ColumnScope .(NavBackStackEntry ) -> Unit
149132 ) : NavDestination(navigator), FloatingWindow
150-
151- private companion object {
152- private const val KEY_SHEET_STATE = " sheetState"
153- }
154133}
0 commit comments