-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created ComposeNavigator.currentKeyAsState() function
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
navigation-compose/src/commonMain/kotlin/com.chrynan.navigation.compose/StateUtils.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,24 @@ | ||
@file:Suppress("unused") | ||
|
||
package com.chrynan.navigation.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.collectAsState | ||
|
||
/** | ||
* Obtains the changes to the [ComposeNavigator.currentKey] value and returns it as a [State]. This allows it to be | ||
* used in a [Composable] and cause recomposition when the value changes. | ||
* | ||
* If you just need to get the current key value and do not need to cause recomposition when the value changes, simply | ||
* use the [ComposeNavigator.currentKey] property. | ||
* | ||
* **Note:** Internally this function uses the [ComposeNavigator.keyChanges] Flow and the [collectAsState] function | ||
* using the [ComposeNavigator.currentKey] as the initial value. | ||
* | ||
* @see [ComposeNavigator.currentKey] | ||
* @see [ComposeNavigator.keyChanges] | ||
* @see [collectAsState] | ||
*/ | ||
@ExperimentalNavigationApi | ||
fun <T> ComposeNavigator<T>.currentKeyAsState(): State<T?> = keyChanges.collectAsState(initial = currentKey) |