Archie
01/09/2021, 10:31 AM@ExperimentalAnimationApi
@Composable
fun FillingIssues() {
val navController = rememberNavController()
val number by sampleFlow.collectAsState(initial = 0)
Scaffold(
topBar = {
// This recomposes just fine
// Gets 0, 1, 2, 3
Text(text = "Top Bar: $number")
}
) { padding ->
val modifier = Modifier.padding(padding)
NavHost(navController, startDestination = FIRST_SCREEN) {
myNavigation(modifier, number)
}
}
}
fun NavGraphBuilder.myNavigation(
modifier: Modifier,
number: Int,
) {
composable(FIRST_SCREEN) {
// This Doesn't recompose
// So it remains displaying
// Number: 0
// Even when 1, 2, 3 are emitted
// This only happens when I make it
// as an extension function
Column(
modifier.fillMaxSize(),
Arrangement.Center,
Alignment.CenterHorizontally
) {
Text("Number: $number")
}
}
}
val sampleFlow = flow {
emit(1)
delay(1000)
emit(2)
delay(3000)
emit(3)
}
private const val FIRST_SCREEN = "FIRST_SCREEN"
Ian Lake
01/09/2021, 3:29 PMAdam Powell
01/09/2021, 4:34 PMIan Lake
01/09/2021, 5:37 PMcomposable(FIRST_SCREEN)
is a @Composable
lambda that is added to the compose hierarchy when you select that destinationAdam Powell
01/09/2021, 5:38 PMmyNavigation
call