Skip to content

[compose] Usage of rememberRasterSourceState does not reset remembered value when key changes #2678

@bamsbamx

Description

@bamsbamx

Environment

  • Android OS version: Android 16, Compose (Multiplatform) 1.10.0 alpha 01
  • Devices affected: (Tested on) Samsung Galaxy S25
  • Maps SDK Version: 11.14.6

Observed behavior and steps to reproduce

In the following code, when mapLayer changes, the content of myCustomSourceState is not reset, even if re-composition is triggered due to a change of instance of the mapLayer. So the tiles URL cannot be changed even if map layer is different.

    @Composable
    fun rasterSourceExample(
        mapLayer: MapLayer,
    ) {
        val myCustomSourceState = rememberRasterSourceState(
            key = mapLayer.toString(),    //  if this changes, the myCustomSourceState does not reset
            sourceId = MAPBOX_SOURCE_CUSTOM_ID,
        ) {
            tileSize = LongValue(MAPBOX_SOURCE_TILE_SIZE)
            tiles = StringListValue(mapLayer.rasterLayerSourceUrl)
        }
    }

Expected behavior

myCustomSourceState should be updated with the new tiles URL from the new value of mapLayer

Notes / preliminary analysis

One can say the reason is that the value passed as key argument is the same, but is not, since mapLayer is a data class. After doing some manual implementations, seems like the Mapbox implementation of rememberRasterSourceState makes use of a deprecated overload. Instead of using key argument, inputs argument should be used to check for the remembered value invalidation. The following code works and could be the fix for the Mapbox implementation

Additional links and references

The problem:
Image

The solution

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions