-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Add ability to save/restore navController's state manually at any …
…time -> Add custom state saver example -> Rename `StorageMode` to better represent actual place of data storing -> `rememberNavController` with navArgs/freeArgs will only receive NON-nullable `startDestination` -> `nextEntryNavId` renamed to `pendingEntryNavId` to better represent self -> `NavController.saveToSaveState` will only provide necessary data based on `storageMode` -> update README.md
- Loading branch information
Showing
7 changed files
with
131 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/CustomStateSaver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package composegears.tiamat.example | ||
|
||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.composegears.tiamat.Navigation | ||
import com.composegears.tiamat.StorageMode | ||
import com.composegears.tiamat.navDestination | ||
import com.composegears.tiamat.rememberNavController | ||
import composegears.tiamat.example.ui.core.SimpleScreen | ||
import composegears.tiamat.example.ui.core.TextBody | ||
import composegears.tiamat.example.ui.core.TextButton | ||
|
||
val CustomStateSaverRoot by navDestination<Unit> { | ||
SimpleScreen("Custom state saver") { | ||
Column(horizontalAlignment = Alignment.CenterHorizontally) { | ||
var savedState by remember { mutableStateOf<Map<String, Any?>>(emptyMap()) } | ||
var showNavController by remember { mutableStateOf(true) } | ||
|
||
TextButton("Toggle navigation -> ${if (showNavController) "Hide" else "Show"}") { | ||
showNavController = !showNavController | ||
} | ||
|
||
Box( | ||
modifier = Modifier | ||
.weight(1f) | ||
.fillMaxWidth() | ||
.padding(8.dp) | ||
.border(4.dp, MaterialTheme.colorScheme.onSurface) | ||
.padding(4.dp), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
if (showNavController) { | ||
val savableNavController = rememberNavController( | ||
storageMode = StorageMode.Memory, | ||
startDestination = DataPassingParamsRoot, | ||
destinations = arrayOf( | ||
DataPassingParamsRoot, | ||
DataPassingParamsScreen, | ||
) | ||
) { | ||
// restore state from custom storage | ||
if (savedState.isNotEmpty()) | ||
loadFromSavedState(savedState) | ||
} | ||
Navigation(navController = savableNavController) | ||
DisposableEffect(Unit) { | ||
onDispose { | ||
// save state into custom storage | ||
savedState = savableNavController.getSavedState() | ||
} | ||
} | ||
} else TextBody("Nothing") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters