Home > Enterprise >  How can I use LaunchEffect in the AndroidView in the Jetpack Compose?
How can I use LaunchEffect in the AndroidView in the Jetpack Compose?

Time:11-18

I want to use a LaunchEffect to the AndroidView for collecting data from the ViewModel Stateflow but I get an error. how can I fix it?

enter image description here

CodePudding user response:

You can run the LaunchedEffect only inside a @Composable function, this means that your lamba should me annotated with @Composable () -> Unit in order to be compatibile. But I'm not pretty sure that is a good practice.

CodePudding user response:

You are trying to use composable LaunchedEffect not inside composable scope. Move launched effect outside of getMapAsync.

You can do something like.

@Composable
fun MapViewContainer {
   ...

   var mapIsReady by remember { mutableStateOf(false) }

   ...

    mapView.getMapAsync {
       mapIsReady = true
       ...
    }

    ...

    if (mapIsReady) {
       // do some compose things
    }
  }
}
  • Related