Skip to content

Commit

Permalink
Pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmos committed Nov 30, 2023
1 parent b3ff8d9 commit 039b17e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@

package com.datadog.reactnative.sessionreplay

import androidx.annotation.VisibleForTesting

private const val HEX_COLOR_INCLUDING_ALPHA_LENGTH: Int = 8

internal fun resolveBackgroundColorAsHex(backgroundColor: Int): String {
internal fun formatAsRgba(backgroundColor: Int): String {
val colorHexString = Integer.toHexString(backgroundColor)

// reorder the hex string from argb to rgba
return "#${reorderARGBtoRGBA(colorHexString)}"
return "#${convertArgbToRgba(colorHexString)}"
}

@VisibleForTesting
internal fun reorderARGBtoRGBA(hexString: String): String {
private fun convertArgbToRgba(hexString: String): String {
return if (hexString.length == HEX_COLOR_INCLUDING_ALPHA_LENGTH) {
hexString.substring(2, 8) + hexString.substring(0, 2)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class ReactViewGroupMapper :
} else {
backgroundDrawable?.resolveShapeStyleAndBorder(opacity) ?: (null to null)
}

return listOf(
MobileSegment.Wireframe.ShapeWireframe(
resolveViewId(view),
Expand All @@ -68,13 +68,12 @@ internal class ReactViewGroupMapper :
backgroundDrawable: ReactViewBackgroundDrawable,
opacity: Float,
pixelDensity: Float
): Pair<MobileSegment.ShapeStyle?, MobileSegment.ShapeBorder?> {
): Pair<MobileSegment.ShapeStyle, MobileSegment.ShapeBorder> {
val backgroundColor = view.backgroundColor
val colorHexString = resolveBackgroundColorAsHex(backgroundColor)

val colorHexString = formatAsRgba(backgroundColor)
val cornerRadius = backgroundDrawable.fullBorderRadius.toLong().convertToDensityNormalized(pixelDensity)
val borderWidth = backgroundDrawable.fullBorderWidth.toLong().convertToDensityNormalized(pixelDensity)
val borderColor = resolveBackgroundColorAsHex(backgroundDrawable.getBorderColor(Spacing.ALL))
val borderColor = formatAsRgba(backgroundDrawable.getBorderColor(Spacing.ALL))

return MobileSegment.ShapeStyle(
backgroundColor = colorHexString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,20 @@ import org.mockito.quality.Strictness
internal class ColorUtilsTest {

@Test
fun `M return without alpha W resolveBackgroundColorAsHex { color without alpha }`() {
fun `M return without alpha W formatAsRgba { color without alpha }`() {
// When
val hexColor = resolveBackgroundColorAsHex(16711680)
val hexColor = formatAsRgba(16711680)

// Then
assertThat(hexColor).isEqualTo("#ff0000")
}

@Test
fun `M resolve with alpha W resolveBackgroundColorAsHex { color with alpha }`() {
fun `M resolve with alpha W formatAsRgba { color with alpha }`() {
// When
val hexColor = resolveBackgroundColorAsHex(1717960806)
val hexColor = formatAsRgba(1717960806)

// Then
assertThat(hexColor).isEqualTo("#66006666")
}

@Test
fun `M reverse alpha to end W reorderARGBtoRGBA { hex color with alpha }`() {
// When
val result = reorderARGBtoRGBA("FF006666")

// Then
assertThat(result).isEqualTo("006666FF")
}

@Test
fun `M return original string W reorderARGBtoRGBA { hex color without alpha }`() {
// When
val result = reorderARGBtoRGBA("006666")

// Then
assertThat(result).isEqualTo("006666")
}
}

0 comments on commit 039b17e

Please sign in to comment.