Skip to content

Commit 729fbd1

Browse files
resolve to pixel
1 parent fba24c9 commit 729fbd1

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/LengthPercentage.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,12 @@ public data class LengthPercentage(
7878
return value
7979
}
8080

81+
public fun resolveToPixel(referenceLength: Float): Float {
82+
if (type == LengthPercentageType.PERCENT) {
83+
return (value / 100) * referenceLength
84+
}
85+
return PixelUtil.toPixelFromDIP(value)
86+
}
87+
8188
public constructor() : this(0f, LengthPercentageType.POINT)
8289
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/RadialGradient.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ internal class RadialGradient(
164164
}
165165

166166
fun getShader(width: Float, height: Float): Shader {
167-
val centerX = position.first.resolve(width)
168-
val centerY = position.second.resolve(height)
167+
val centerX = position.first.resolveToPixel(width)
168+
val centerY = position.second.resolveToPixel(height)
169169

170170
val (radiusX, radiusY) = calculateRadius(centerX, centerY, width, height)
171171

@@ -326,8 +326,8 @@ internal class RadialGradient(
326326
}
327327
} else {
328328
val dimensions = size.value as GradientSize.Dimensions
329-
val radiusX = dimensions.x.resolve(width)
330-
val radiusY = dimensions.y.resolve(height)
329+
val radiusX = dimensions.x.resolveToPixel(width)
330+
val radiusY = dimensions.y.resolveToPixel(height)
331331

332332
return if (isCircle) {
333333
val radius = max(radiusX, radiusY)

0 commit comments

Comments
 (0)