Skip to content

Commit

Permalink
Merge pull request #2351 from DataDog/jmoskovich/new-fix-frozen-images
Browse files Browse the repository at this point in the history
RUM-6897: Fix scrolling issue
  • Loading branch information
jonathanmos authored Oct 28, 2024
2 parents 178771e + 1f6307b commit f024089
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,25 @@ internal class ImageViewMapper(
val contentYPosInDp = contentRect.top.densityNormalized(density).toLong()
val contentWidthPx = contentRect.width()
val contentHeightPx = contentRect.height()
val contentDrawable = drawable.constantState?.newDrawable(resources)

if (contentDrawable != null) {
// resolve foreground
mappingContext.imageWireframeHelper.createImageWireframe(
view = view,
imagePrivacy = mappingContext.imagePrivacy,
currentWireframeIndex = wireframes.size,
x = contentXPosInDp,
y = contentYPosInDp,
width = contentWidthPx,
height = contentHeightPx,
usePIIPlaceholder = true,
drawable = contentDrawable,
asyncJobStatusCallback = asyncJobStatusCallback,
clipping = clipping,
shapeStyle = null,
border = null,
prefix = ImageWireframeHelper.DRAWABLE_CHILD_NAME
)?.let {
wireframes.add(it)
}
// resolve foreground
mappingContext.imageWireframeHelper.createImageWireframe(
view = view,
imagePrivacy = mappingContext.imagePrivacy,
currentWireframeIndex = wireframes.size,
x = contentXPosInDp,
y = contentYPosInDp,
width = contentWidthPx,
height = contentHeightPx,
usePIIPlaceholder = true,
drawable = drawable,
asyncJobStatusCallback = asyncJobStatusCallback,
clipping = clipping,
shapeStyle = null,
border = null,
prefix = ImageWireframeHelper.DRAWABLE_CHILD_NAME
)?.let {
wireframes.add(it)
}

return wireframes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ internal class DefaultImageWireframeHelper(
resources = resources,
applicationContext = applicationContext,
displayMetrics = displayMetrics,
drawable = drawableProperties.drawable,
originalDrawable = drawableProperties.drawable,
drawableWidth = width,
drawableHeight = height,
resourceResolverCallback = object : ResourceResolverCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ internal class ResourceResolver(
resources: Resources,
applicationContext: Context,
displayMetrics: DisplayMetrics,
drawable: Drawable,
originalDrawable: Drawable,
drawableWidth: Int,
drawableHeight: Int,
resourceResolverCallback: ResourceResolverCallback
) {
bitmapCachesManager.registerCallbacks(applicationContext)

val resourceId = tryToGetResourceFromCache(drawable = drawable)
val resourceId = tryToGetResourceFromCache(drawable = originalDrawable)

if (resourceId != null) {
// if we got here it means we saw the bitmap before,
Expand All @@ -61,9 +61,11 @@ internal class ResourceResolver(
return
}

val copiedDrawable = originalDrawable.constantState?.newDrawable(resources) ?: return

val bitmapFromDrawable =
if (drawable is BitmapDrawable && shouldUseDrawableBitmap(drawable)) {
drawable.bitmap // cannot be null - we already checked in shouldUseDrawableBitmap
if (copiedDrawable is BitmapDrawable && shouldUseDrawableBitmap(copiedDrawable)) {
copiedDrawable.bitmap // cannot be null - we already checked in shouldUseDrawableBitmap
} else {
null
}
Expand All @@ -72,7 +74,7 @@ internal class ResourceResolver(
threadPoolExecutor.executeSafe("resolveResourceId", logger) {
createBitmap(
resources = resources,
drawable = drawable,
drawable = originalDrawable,
drawableWidth = drawableWidth,
drawableHeight = drawableHeight,
displayMetrics = displayMetrics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,23 @@ abstract class BaseAsyncBackgroundWireframeMapper<in T : View> internal construc
mappingContext: MappingContext,
asyncJobStatusCallback: AsyncJobStatusCallback
): MobileSegment.Wireframe? {
val resources = view.resources

val drawableCopy = view.background?.constantState?.newDrawable(resources)

return if (drawableCopy != null) {
mappingContext.imageWireframeHelper.createImageWireframe(
view = view,
imagePrivacy = mappingContext.imagePrivacy,
currentWireframeIndex = 0,
x = bounds.x,
y = bounds.y,
width = width,
height = height,
usePIIPlaceholder = false,
drawable = drawableCopy,
asyncJobStatusCallback = asyncJobStatusCallback,
clipping = MobileSegment.WireframeClip(),
shapeStyle = null,
border = null,
prefix = PREFIX_BACKGROUND_DRAWABLE
)
} else {
null
}
val background = view.background ?: return null
return mappingContext.imageWireframeHelper.createImageWireframe(
view = view,
imagePrivacy = mappingContext.imagePrivacy,
currentWireframeIndex = 0,
x = bounds.x,
y = bounds.y,
width = width,
height = height,
usePIIPlaceholder = false,
drawable = background,
asyncJobStatusCallback = asyncJobStatusCallback,
clipping = MobileSegment.WireframeClip(),
shapeStyle = null,
border = null,
prefix = PREFIX_BACKGROUND_DRAWABLE
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ internal class DefaultImageWireframeHelperTest {
resources = any(),
applicationContext = any(),
displayMetrics = any(),
drawable = any(),
originalDrawable = any(),
drawableWidth = any(),
drawableHeight = any(),
resourceResolverCallback = any()
Expand Down Expand Up @@ -500,7 +500,7 @@ internal class DefaultImageWireframeHelperTest {
resources = any(),
applicationContext = any(),
displayMetrics = any(),
drawable = any(),
originalDrawable = any(),
drawableWidth = any(),
drawableHeight = any(),
resourceResolverCallback = argumentCaptor.capture()
Expand Down Expand Up @@ -613,7 +613,7 @@ internal class DefaultImageWireframeHelperTest {
resources = any(),
applicationContext = any(),
displayMetrics = any(),
drawable = any(),
originalDrawable = any(),
drawableWidth = captor.capture(),
drawableHeight = captor.capture(),
resourceResolverCallback = any()
Expand Down Expand Up @@ -645,7 +645,7 @@ internal class DefaultImageWireframeHelperTest {
resources = any(),
applicationContext = any(),
displayMetrics = any(),
drawable = any(),
originalDrawable = any(),
drawableWidth = captor.capture(),
drawableHeight = captor.capture(),
resourceResolverCallback = any()
Expand Down Expand Up @@ -722,7 +722,7 @@ internal class DefaultImageWireframeHelperTest {
resources = any(),
applicationContext = any(),
displayMetrics = any(),
drawable = any(),
originalDrawable = any(),
drawableWidth = any(),
drawableHeight = any(),
resourceResolverCallback = any()
Expand Down
Loading

0 comments on commit f024089

Please sign in to comment.