Took 2 months off to work on production code. Gett...
# compose-android
t
Took 2 months off to work on production code. Getting back to compose, I feel like I've regressed half way back to the beginning. Sigh. Wanted to do this in a "zoom to edge" button:
Copy code
action = { cameraState.animate(CameraUpdateFactory.newLatLngBounds(sortedRegions.map { region -> region.coordinateBounds }
      .reduce { accum, box -> accum.union(box) }, 20))
},
But the compiler complains about that `animate`:
Suspend function 'animate' should be called only from a coroutine or another suspend function
So I get it. I need to fork/coroutine/whatever this block to not happen here, but in another execution context somehow. What is the idomatic way to do it? Is it a LaunchedEffect? Is there a decent primer on these "alternate/parallel execution contexts" for Compose that any can recommend?
I wrapped my action block contents with a scope.launch { }. And it works. But I don't know if that's the RightWay(tm) to do it 😕
s
If you're getting your scope through
rememberCoroutineScope
then that sounds about right. This action needs to know in which scope it will run in so that it knows when it no longer is relevant and should be cancelled, and this scope should accomplish that properly. Btw curious, this cameraState, where does it come from?
t
The ComposeMaps stuff
specifically:
Copy code
com.google.maps.android:maps-compose:2.11.4