-
-
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.
Added keySaver property to ComposeNavigator
- Loading branch information
Showing
8 changed files
with
159 additions
and
43 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
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
84 changes: 84 additions & 0 deletions
84
navigation-compose/src/commonMain/kotlin/com.chrynan.navigation.compose/FlowStateUtils.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,84 @@ | ||
@file:Suppress("unused") | ||
|
||
package com.chrynan.navigation.compose | ||
|
||
import androidx.compose.runtime.* | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import kotlinx.coroutines.withContext | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
import kotlin.experimental.ExperimentalTypeInference | ||
|
||
/** | ||
* Similar to the [collectAsState] function but allows providing the [MutableState] to be used. | ||
* | ||
* @see [collectAsState] | ||
*/ | ||
@Composable | ||
internal fun <T : R, R> Flow<T>.collectAsStateIn( | ||
state: MutableState<R>, | ||
context: CoroutineContext = EmptyCoroutineContext | ||
): State<R> = produceStateIn(state = state, this, context) { | ||
if (context == EmptyCoroutineContext) { | ||
collect { value = it } | ||
} else withContext(context) { | ||