Anyone familiar with MapView + AndroidView. I just...
# compose
c
Anyone familiar with MapView + AndroidView. I just have a simple map, and I hit a network call to get the lat + long of 5 places. When the network call returns I add those 5 items to a
Copy code
var list = mutableStateListOf<Location>()
but my map never updates until I reload that page. I believe I'm doing everything correclty, because if I comment out my MapView code and replace it with a Column + forEach then all of my items show when the network call completes. Is there some sort of thing you need to hook into with AndroidView + mapView to have it respond to mutableState?
Note: I'm not using the compose maps composable because it doesn't support clustering.
a
@Chris Arriola might be able to help; there's really not enough info here about your own code to go on but re. Maps Compose feature support he's the expert 🙂
c
Damn. Okay. I might just try to use a TextView in an Android view and see if I can make it react to changes. If so, then it's definitely map view
y
What does your AndroidView look like? Are you setting these locations in update lambda?
c
y
I suspect the mapView.getAsync(callback) isn't involved in state tracking. Try doing reads of state in the update lambda outside the getAsync call.
Can you update state externally when the markers change and then read them from the update lambda before you call mapView.getAsync?
Docs on this point https://developer.android.com/jetpack/compose/interop/interop-apis
Copy code
AndroidView(
        modifier = Modifier.fillMaxSize(), // Occupy the max size in the Compose UI tree
        factory = { context ->
            // Creates custom view
            CustomView(context).apply {
                // Sets up listeners for View -> Compose communication
                myView.setOnClickListener {
                    selectedItem.value = 1
                }
            }
        },
        update = { view ->
            // View's been inflated or state read in this block has been updated
            // Add logic here if necessary

            // As selectedItem is read here, AndroidView will recompose
            // whenever the state changes
            // Example of Compose -> View communication
            view.coordinator.selectedItem = selectedItem.value
        }