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

Billy Newman

07/17/2022, 3:54 PM
Hello all, I am struggling with maps compose and a recompose causing a TileOverlay to flicker. Wondering if someone could provide some insight. Code in reply.
I am waiting for the map to load before I change the camera location via an animation. However when I do that a recompose is happening, assuming this is what is causing the TileOverlay layer to flicker at the start.
Copy code
@Composable
private fun Map() {
  var isMapLoaded by remember { mutableStateOf(false) }

  GoogleMap(
    onMapLoaded = { isMapLoaded = true }  // This will cause recompose
  ) {
    if (isMapLoaded) {
      // Need to wait for map loaded to preform map camera location animation.
    }

    // Assume flicker here is caused by recompose and reload of TileOverlay
    TileOverlay(tileProvider = MyTileProvider())
  }
}
I was under the assumption that the GoogleMap composable would keep track of the TileOverlay and not reload it on recompose. Is that assumption wrong? Something else I am doing wrong? I can put the TileOverlay inside the isMapLoaded check to fix/workaround the issue. However at that point should I put everything map related inside that if statement?
@Colton Idle, @Chris Arriola any thoughts you can offer?
c

Chris Arriola

08/09/2022, 8:51 PM
@Billy Newman looks like you are creating a new instance of MyTileProvider() each time, if you want to use the same instance across recomposition you need to
remember
the
MyTileProvider
. sorry for the delay here.
b

Billy Newman

08/09/2022, 9:06 PM
Awesome and it goes without saying, no apologies necessary. I appreciate your time whenever you can give it!
4 Views