Fernando
11/08/2024, 3:16 PMFernando
11/08/2024, 3:18 PMkey
would trigger the re-render, but nop...
@Composable
actual fun MapView(
geoJSON: Pair<String,String>?
) {
geoJSON?.let { (id, datas) ->
println(">> Re render?")
recomposition when the data changes
var geoJsonData by remember { mutableStateOf(datas) }
val mapViewportState = remember { MapViewportState() }
val mapState = rememberMapState(key = id)
val geoJsonSource = rememberGeoJsonSourceState(key = id) {
data = GeoJSONData(datas)
}
recomposition
Scaffold { padding ->
MapboxMap(
modifier = Modifier.fillMaxSize(),
scaleBar = {},
mapViewportState = mapViewportState,
compass = {
Compass(Modifier.padding(top = padding.calculateTopPadding()))
},
style = {
MapboxStandardSatelliteStyle {
lightPreset = LightPresetValue.DAWN
showRoadsAndTransit = BooleanValue(false)
showPointOfInterestLabels = BooleanValue(false)
showPlaceLabels = BooleanValue(false)
}
},
) {
val sourceState = rememberGeoJsonSourceState(key = "geojson-source") {
data = GeoJSONData(geoJsonData)
}
LineLayer(sourceState = sourceState) {
lineColor = ColorValue(Color.Blue)
lineWidth = DoubleValue(2.0)
}
}
}
}
}
Pablichjenkov
11/08/2024, 3:46 PMrememberGeoJsonSourceState()
does internally but hardcoding the value of key
seems to me could trigger this type of issues due to positional memoization. Try using geoJsonData as key and see what happens