Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
m3-ra opened this issue Sep 19, 2024 · 3 comments
Open

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

m3-ra opened this issue Sep 19, 2024 · 3 comments
Labels
bug 🪲 Something isn't working

Comments

@m3-ra
Copy link

m3-ra commented Sep 19, 2024

Environment

  • Android OS version: 14
  • Devices affected: Pixel 5
  • Maps SDK Version: 11.4.0

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 m3-ra added the bug 🪲 Something isn't working label Sep 19, 2024
@m3-ra
Copy link
Author

m3-ra commented Sep 20, 2024

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
Copy link
Author

m3-ra commented Sep 20, 2024

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?

@kiryldz
Copy link
Contributor

kiryldz commented Sep 23, 2024

@m3-ra thanks for reporting, we'll take a look and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants