reactormonk
04/05/2024, 2:08 PMvar connectionFlow: MutableStateFlow<GattConnectionState> = MutableStateFlow(GattConnectionState.STATE_DISCONNECTED)
val bluetoothConnectionState by connectionFlow.collectAsState()
val isConnected = bluetoothConnectionState == GattConnectionState.STATE_CONNECTED
LaunchedEffect(address) {
connectionFlow = viewModel.connect(address)
}
I think it's not recomposing when I replace connectionFlow
, what's the correct way to implement this?Stylianos Gakis
04/05/2024, 2:20 PMconnectionFlow
on each recomposition with the code you provide here at least. Is that what you want here?
Also, it’s not inside a MutableState, so if you change a var like that compose has no reason to recompose at all
@Composable
fun asd() {
var x = 1
...
LaunchedEffect(Unit) { x = x + 1 }
}
This will of course not trigger a recomposition as a normal var which is not backed by MutableState won’t inform composition that there’s something that has changed and a recomposition needs to happen.reactormonk
04/05/2024, 2:21 PM