Hi <@UJBPFB3SN>, I was wondering if this is an int...
# compose
a
Hi @Ian Lake, I was wondering if this is an intended behavior?
Copy code
@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"
a
I haven't looked deeply at the code from the other thread yet, but in this snippet the snapshot state read of both number and modifier are happening in the navhost builder block, not a composable function. Does navigation-compose observe snapshot changes in the builder and rebuild the graph? It seems to go out of its way not to for changes in the builder lambda capture: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:na[…]in/java/androidx/navigation/compose/NavHost.kt;l=88?q=NavHost
i
The lambda of
composable(FIRST_SCREEN)
is a
@Composable
lambda that is added to the compose hierarchy when you select that destination
a
yes but the state read is happening earlier - when evaluating the parameters to the
myNavigation
call