mapbox / mapbox/mapbox-maps-android

rememberMapViewportState not working on 11.5.0

Open
#2,430 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle: compose
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

## Environment

- Android OS version: 13
- Devices affected: Xiaomi Mi9T Pro
- Maps SDK Version: 11.5.0

## Observed behavior and steps to reproduce

In version 11.3.1, I was able to create the MapboxMap composable with
```kotlin
MapboxMap(
modifier.fillMaxSize(),
mapViewportState = mapViewportState,
locationComponentSettings = LocationComponentSettings
.Builder(createDefault2DPuck(withBearing = true))
.setEnabled(true)
.setPuckBearingEnabled(true)
.setPuckBearing(PuckBearing.HEADING)
.build(),
style = { MapStyle(style = Style.MAPBOX_STREETS) },
scaleBar = { }, // no scale bar
)
```
But with the lastest version (11.5.0), the localComponentSettings had been moved. Omitting it will turn my code into
```kotlin
MapboxMap(
modifier.fillMaxSize(),
mapViewportState = mapViewportState,
style = { MapStyle(style = Style.MAPBOX_STREETS) },
scaleBar = { }, // no scale bar
)
```
But these changes also seem to have changed the behavior of rememberMapViewportState. The state is no longer maintained, for example, by switching between screens with a NavController. Am I missing somethings?

## Expected behavior

The viewportState is preserved across recompositions.

## Notes / preliminary analysis

The code above works for version 11.3.1. I might be adapting my old code in a way that breaks rememberMapViewportState.
With version 11.5.0, navigation causes recomposition of my Nav composable.
With version 11.3.1, the Nav component my Map is placed in is not recomposed.

## Additional links and references

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MapboxMap composable and rememberMapViewportState usage, then reproduce navigation between screens on Android 13 with Maps SDK 11.5.0 and compare the behavior with 11.3.1. Done means the viewportState remains preserved across recompositions caused by NavController navigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.