-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
30 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
core/ui/src/iosMain/kotlin/io/github/droidkaigi/confsched/ui/presenterStateFlow.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,43 @@ | ||
package io.github.droidkaigi.confsched.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
import app.cash.molecule.RecompositionMode | ||
import app.cash.molecule.moleculeFlow | ||
import io.github.droidkaigi.confsched.compose.CompositionLocalProviderWithReturnValue | ||
import io.github.droidkaigi.confsched.model.compositionlocal.LocalRepositories | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.filterNotNull | ||
import kotlin.reflect.KClass | ||
|
||
@Suppress("unused") | ||
fun <EVENT, UISTATE> presenterStateFlow( | ||
repositories: Map<KClass<*>, Any>, | ||
events: Flow<EVENT>, | ||
presenter: @Composable (events: Flow<EVENT>) -> UISTATE, | ||
): Flow<UISTATE> { | ||
return moleculeFlow(RecompositionMode.Immediate) { | ||
var uiState by remember { mutableStateOf<UISTATE?>(null) } | ||
CompositionLocalProviderWithReturnValue(LocalRepositories provides repositories) { | ||
NavHost(rememberNavController(), startDestination = "root") { | ||
composable("root") { | ||
val newUiState = presenter(events) | ||
LaunchedEffect(Unit) { | ||
uiState = newUiState | ||
} | ||
} | ||
} | ||
} | ||
uiState | ||
} | ||
.filterNotNull() | ||
} | ||
|
||
|
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