https://kotlinlang.org logo
#compose
Title
# compose
m

mattinger

05/06/2022, 4:03 PM
Copy code
var startBluetoothFlow by remember { mutableStateOf(false) }
    LaunchedEffect(key1 = true) {
        if (!host.bleManager.isReadyForScanning) {
            startBluetoothFlow = true
        }
    }

    if (startBluetoothFlow) {
        BluetoothController(
            permissionState = permissionState,
            bluetooth = host.bleManager,
            navHostController = navController,
        )
    }
The problem is that BluetoothController is getting evaluated multiple times
I feel like permissionState is triggering recomposition even when it’s not actually changing state
f

Francesc

05/06/2022, 4:27 PM
once you turn the flag to
true
, it will remain
true
and trigger your
if
block at each composition. You could wrap your
if
block in a
LaunchedEffect
with
key
startBluetothFlow
or maybe just move this block into the existing
LaunchedEffect
m

mattinger

05/06/2022, 5:14 PM
well, i can’t move the block inside LaunchedEffect, because BluetoothController is a composable. I think my issue was with using SideEffect in the BluetoothController to trigger things. I switched to using LaunchedEffect in there so that things only fire a single time.
2 Views