Skip to content

Commit 08f6fc5

Browse files
committed
Revert "Experiment with custom-restoring state"
Keeping d67415c in the commit history but looking at other approaches now! This reverts commit d67415c Change-Id: I35e3dc49417fed7380b723c0cd99bf3d88533e79
1 parent f6435a9 commit 08f6fc5

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

‎navigation/navigation-compose-material/src/main/java/androidx/navigation/compose/material/BottomSheetNavigator.kt‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@
1616

1717
package androidx.navigation.compose.material
1818

19-
import android.os.Bundle
2019
import androidx.compose.foundation.layout.ColumnScope
2120
import androidx.compose.material.ExperimentalMaterialApi
2221
import androidx.compose.material.ModalBottomSheetState
2322
import androidx.compose.material.ModalBottomSheetValue
23+
import androidx.compose.material.rememberModalBottomSheetState
2424
import androidx.compose.runtime.Composable
25-
import androidx.compose.runtime.LaunchedEffect
2625
import androidx.compose.runtime.collectAsState
2726
import androidx.compose.runtime.getValue
2827
import androidx.compose.runtime.mutableStateOf
2928
import androidx.compose.runtime.remember
3029
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
3130
import androidx.compose.runtime.setValue
32-
import androidx.core.os.bundleOf
3331
import androidx.lifecycle.Lifecycle
3432
import androidx.navigation.FloatingWindow
3533
import androidx.navigation.NavBackStackEntry
@@ -50,7 +48,7 @@ import kotlinx.coroutines.flow.StateFlow
5048
@Composable
5149
public 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

Comments
 (0)