Skip to content

Commit

Permalink
[widget] Fix BitmapWidget.setTranslation API to offset relative to it…
Browse files Browse the repository at this point in the history
…s original position. (#1833)

* [widget] Fix BitmapWidget.setTranslation API.

publish_android_snapshot

* Update CHANGELOG.md

* Update api files.
  • Loading branch information
pengdev authored Nov 15, 2022
1 parent 0a2438b commit 651553f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Mapbox welcomes participation and contributions from everyone.
* Trigger repaint after `BitmapWidget` is updated. ([1797](https://github.com/mapbox/mapbox-maps-android/pull/1797))
* Fix a crash after removing the view annotation if view has an attached animation or transition. ([1831](https://github.com/mapbox/mapbox-maps-android/pull/1831))
* Emit the last indicator state when new listeners are added to the location component. ([1827](https://github.com/mapbox/mapbox-maps-android/pull/1827))
* Fix a regression from v10.10.0-beta.1 release, the BitmapWidget.setTranslation API should offset relative to its original position. ([1833](https://github.com/mapbox/mapbox-maps-android/pull/1833))

# 10.9.1 November 7, 2022

Expand Down
2 changes: 1 addition & 1 deletion sdk/api/metalava.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ package com.mapbox.maps.renderer {
package com.mapbox.maps.renderer.widget {

@com.mapbox.maps.MapboxExperimental public class BitmapWidget extends com.mapbox.maps.renderer.widget.Widget {
ctor public BitmapWidget(android.graphics.Bitmap bitmap, com.mapbox.maps.renderer.widget.WidgetPosition position = WidgetPosition({
ctor public BitmapWidget(android.graphics.Bitmap bitmap, com.mapbox.maps.renderer.widget.WidgetPosition originalPosition = WidgetPosition({
verticalAlignment = WidgetPosition.Vertical.TOP
horizontalAlignment = WidgetPosition.Horizontal.LEFT
offsetX = 0.0
Expand Down
19 changes: 9 additions & 10 deletions sdk/src/main/java/com/mapbox/maps/renderer/widget/BitmapWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import com.mapbox.maps.MapboxExperimental
* Widget displaying bitmap within specified position and margins.
*
* @param bitmap bitmap used to draw widget
* @param position position of widget
* @param originalPosition position of widget
*/
@MapboxExperimental
open class BitmapWidget @JvmOverloads constructor(
bitmap: Bitmap,
position: WidgetPosition = WidgetPosition {
private val originalPosition: WidgetPosition = WidgetPosition {
verticalAlignment = WidgetPosition.Vertical.TOP
horizontalAlignment = WidgetPosition.Horizontal.LEFT
offsetX = 0f
Expand Down Expand Up @@ -42,7 +42,7 @@ open class BitmapWidget @JvmOverloads constructor(
marginY: Float = 0f,
) : this(
bitmap = bitmap,
position = WidgetPosition {
originalPosition = WidgetPosition {
horizontalAlignment = position.horizontalAlignment
verticalAlignment = position.verticalAlignment
offsetX = when (position.horizontalAlignment) {
Expand Down Expand Up @@ -85,7 +85,7 @@ open class BitmapWidget @JvmOverloads constructor(

override val renderer = BitmapWidgetRenderer(
bitmap = bitmap,
position = position
position = originalPosition
)

/**
Expand All @@ -112,7 +112,7 @@ open class BitmapWidget @JvmOverloads constructor(
override fun getPosition() = renderer.getPosition()

/**
* Set the translation of the widget in pixels, relative to it's current position.
* Set the translation of the widget in pixels, relative to it's original position.
*
* @param translateX the offset in pixels towards the right of the screen.
* @param translateY the offset in pixels towards the bottom of the screen.
Expand All @@ -122,13 +122,12 @@ open class BitmapWidget @JvmOverloads constructor(
replaceWith = ReplaceWith("setPosition")
)
override fun setTranslation(translationX: Float, translationY: Float) {
val currentPosition = getPosition()
setPosition(
WidgetPosition {
horizontalAlignment = currentPosition.horizontalAlignment
verticalAlignment = currentPosition.verticalAlignment
offsetX = currentPosition.offsetX + translationX
offsetY = currentPosition.offsetY + translationY
horizontalAlignment = originalPosition.horizontalAlignment
verticalAlignment = originalPosition.verticalAlignment
offsetX = originalPosition.offsetX + translationX
offsetY = originalPosition.offsetY + translationY
}
)
}
Expand Down

0 comments on commit 651553f

Please sign in to comment.