Skip to content

Desktop: MaplibreMap persists even when Composable should no longer be visible #625

@watbe

Description

@watbe

What happened?

Hi, thanks for your work on this library.

I'm running into a problem on MacOS desktop, where the MaplibreMap remains drawn on top of other composables, even when it should no longer be visible. Even with forced recompositions, the map persists (and I think it creates new instances).

The map does redraw correctly on the screen when it is scrolled. It's only when it should be disposed that it doesn't seem to disappear.

On Android, this doesn't seem to be an issue.

Unfortunately I'm having difficulty building the demo-app to reproduce this, running in to an unrelated native compilation issue.

I've put some sample code below - on desktop, when the button is pressed, the map does not disappear but a recomposition is triggered. On android, the map disappears as expected.

Do you have any suggestions on what I should look for to try and debug this issue? Thanks.

Affected Platforms

  • Android
  • iOS
  • Desktop (JVM)
  • Browser (JS)
  • Browser (Wasm)

Platform Version

macOS 26.0

Library Version

0.11.1

Sample Code

@Composable
fun MapView(modifier: Modifier) {
    val mapVisible = remember { mutableStateOf(true) }
    Button(onClick = { mapVisible.value = !mapVisible.value }) {
        if (mapVisible.value) {
            Text(text = "Hide map")
        } else {
            Text(text = "Show map")
        }
    }

    if (mapVisible.value) {
        MaplibreMap(
            baseStyle = BaseStyle.Uri("https://tiles.openfreemap.org/styles/liberty"),
            cameraState = CameraState(
                CameraPosition(
                    target = Position(latitude = 0.0, longitude = 0.0),
                    zoom = 1.0,
                )
            ),
            modifier = modifier,
        )
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    desktopAffects Desktop in particular, or relates to Desktop specific code

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions