Skip to content

Commit

Permalink
RUM-3460: Fix padding and resizing issue for image view mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ambushwork committed Nov 5, 2024
1 parent b1d6ebb commit 39c3e59
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ internal class ImageViewMapper(

val resources = view.resources
val density = resources.displayMetrics.density
val clipping = imageViewUtils.calculateClipping(parentRect, contentRect, density)

val clipping = if (view.cropToPadding) {
imageViewUtils.calculateClipping(parentRect, contentRect, density)
} else {
null
}
val contentXPosInDp = contentRect.left.densityNormalized(density).toLong()
val contentYPosInDp = contentRect.top.densityNormalized(density).toLong()
val contentWidthPx = contentRect.width()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.datadog.android.sessionreplay.internal.recorder.resources

import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.InsetDrawable
import android.graphics.drawable.LayerDrawable
import android.view.View
Expand Down Expand Up @@ -238,7 +237,6 @@ internal class DefaultImageWireframeHelper(
}
}

is GradientDrawable -> DrawableProperties(drawable, view.width, view.height)
else -> DrawableProperties(drawable, width, height)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ internal object ImageViewUtils {
// this will always have size >= 2
@Suppress("UnsafeThirdPartyFunctionCall")
view.getLocationOnScreen(coords)

val leftPadding = view.paddingLeft
val rightPadding = view.paddingRight
val topPadding = view.paddingTop
val bottomPadding = view.paddingBottom
return Rect(
coords[0],
coords[1],
coords[0] + view.width,
coords[1] + view.height
coords[0] + leftPadding,
coords[1] + topPadding,
coords[0] + view.width - rightPadding,
coords[1] + view.height - bottomPadding
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ internal class ImageViewUtilsTest {
val fakeGlobalY = forge.aPositiveInt()
val fakeWidth = forge.aPositiveInt()
val fakeHeight = forge.aPositiveInt()
val fakeTopPadding = forge.aPositiveInt()
val fakeBottomPadding = forge.aPositiveInt()
val fakeLeftPadding = forge.aPositiveInt()
val fakeRightPadding = forge.aPositiveInt()
val mockView: View = mock {
whenever(it.getLocationOnScreen(any())).thenAnswer {
val coords = it.arguments[0] as IntArray
Expand All @@ -221,16 +225,20 @@ internal class ImageViewUtilsTest {
}
whenever(it.width).thenReturn(fakeWidth)
whenever(it.height).thenReturn(fakeHeight)
whenever(it.paddingTop).thenReturn(fakeTopPadding)
whenever(it.paddingLeft).thenReturn(fakeLeftPadding)
whenever(it.paddingRight).thenReturn(fakeRightPadding)
whenever(it.paddingBottom).thenReturn(fakeBottomPadding)
}

// When
val result = testedImageViewUtils.resolveParentRectAbsPosition(mockView)

// Then
assertThat(result.left).isEqualTo(fakeGlobalX)
assertThat(result.top).isEqualTo(fakeGlobalY)
assertThat(result.right).isEqualTo(fakeGlobalX + fakeWidth)
assertThat(result.bottom).isEqualTo(fakeGlobalY + fakeHeight)
assertThat(result.left).isEqualTo(fakeGlobalX + fakeLeftPadding)
assertThat(result.top).isEqualTo(fakeGlobalY + fakeTopPadding)
assertThat(result.right).isEqualTo(fakeGlobalX + fakeWidth - fakeRightPadding)
assertThat(result.bottom).isEqualTo(fakeGlobalY + fakeHeight - fakeBottomPadding)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,20 @@
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
},
{
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
},
{
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,23 @@
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "shape"
},
{
"type": "placeholder",
"label": "Image"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "shape"
},
{
"type": "placeholder",
"label": "Image"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "shape"
},
{
"type": "placeholder",
"label": "Image"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,20 @@
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
},
{
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
},
{
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,10 @@
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,10 @@
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "placeholder",
"label": "Image"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "placeholder",
"label": "Image"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,10 @@
"type": "shape"
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
},
{
"clip": {
"top": 2,
"bottom": 3,
"left": 0,
"right": 0
},
"type": "image",
"isEmpty": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@
<ImageView
android:id="@+id/imageView_remote"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_height="160dp"
android:padding="32dp"
android:scaleType="fitCenter"
android:contentDescription="@null"
android:layout_marginEnd="8dp"
Expand Down

0 comments on commit 39c3e59

Please sign in to comment.