mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
464 stars 131 forks source link

Automirrored vector drawables do not get mirrored when layout is RTL #2484

Open m3-ra opened 23 hours ago

m3-ra commented 23 hours ago

Environment

Observed behavior and steps to reproduce

Mapbox doesn't seem to honor the autoMirrored attribute on vector drawables when rendering, which result in icons not being mirrored when the layout is RTL. Map used is mapbox compose and images are displayed with point annotations.

Expected behavior

Icons should be mirrored

Notes / preliminary analysis

Now that I think about it, images are added with style.addImage which takes a bitmap... Could it be that the auto mirror info is lost when doing Drawable -> Bitmap?

Additional links and references

m3-ra commented 2 hours ago

Quick update: I tried to bump the sdk to the latest Mapbox compose version and use the method described here: https://docs.mapbox.com/android/maps/examples/compose/add-point-annotations/

val marker = rememberIconImage(key = markerResourceId, painter = painterResource(markerResourceId))
PointAnnotation(point = CityLocations.HELSINKI) {
    iconImage = marker
    textField = text
}

Which directly takes a drawable and no luck, icon is not mirrored when displayed

m3-ra commented 2 hours ago

Further update after exploring the source code a bit. rememberIconImage converts the drawable to a bitmap with this:

internal fun Painter.drawToBitmap(): ImageBitmap {
  val drawScope = CanvasDrawScope()
  val bitmap = ImageBitmap(intrinsicSize.width.toInt(), intrinsicSize.height.toInt())
  val canvas = Canvas(bitmap)
  drawScope.draw(
    density = Density(1f),
    layoutDirection = LayoutDirection.Ltr,
    canvas = canvas,
    size = intrinsicSize
  ) {
    draw(intrinsicSize)
  }
  return bitmap
}

With a clear hardcoded Ltr direction which seems it could be the cultprit?