hey I'm struggling to find the way to do handle onClick between composable...
I have a screen with a mapView (used the Crane sample), and I want to have a Center location FAB, I'm not sure how to handle the click to make the mapView center on the wanted location, sample in comment
nitrog42
05/04/2021, 2:39 PM
Copy code
@Composable
private fun Map(latitude: Double, longitude: Double) {
val mapView = rememberMapViewWithLifecycle()
LaunchedEffect(map, mapInitialized) {
if (!mapInitialized) {
val googleMap = map.awaitMap()
val position = LatLng(latitude, longitude)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 16f))
mapInitialized = true
}
AndroidView({ map })
}
}
Box {
Map {
}
FloatingActionButton(onClick = {
//what to do here ?
}) {
}
}
nitrog42
05/04/2021, 2:39 PM
sample has been simplified, but here it's not really a state but an event, I'm not sure how to represent it from a compose POV ?
nitrog42
05/04/2021, 2:40 PM
it would of course be easy if the FloatingActionButton would be in the Map Composable but I want to find a way outside this
nitrog42
05/04/2021, 2:57 PM
I think I have to put
Copy code
val mapView = rememberMapViewWithLifecycle()
in the Box block actually, so that I can do something on the mapview from the FloatingActionButton