Skip to content

Commit

Permalink
Clip to radii bounds in OutsetBoxShadowDrawable
Browse files Browse the repository at this point in the history
Summary:
This adjusts logic to be similar to InsetBoxShadowDrawable to keep the full ink within RenderNode bounds. This avoids a tiny bit of overdraw, but also means we get correct rendering if RenderNode is promoted to a compositing layer.

Changelog: [Internal]

Differential Revision: D60972085
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Aug 12, 2024
1 parent 184646e commit 42de92e
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.facebook.react.uimanager.FilterHelper
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.uimanager.style.BorderRadiusStyle
import com.facebook.react.uimanager.style.ComputedBorderRadius
import kotlin.math.ceil
import kotlin.math.roundToInt

private const val TAG = "OutsetBoxShadowDrawable"
Expand Down Expand Up @@ -54,7 +55,7 @@ internal class OutsetBoxShadowDrawable(

private val renderNode =
RenderNode(TAG).apply {
clipToBounds = false
clipToBounds = true
setRenderEffect(FilterHelper.createBlurEffect(blurRadius * BLUR_RADIUS_SIGMA_SCALE))
}

Expand All @@ -81,6 +82,7 @@ internal class OutsetBoxShadowDrawable(
}

val spreadExtent = PixelUtil.toPixelFromDIP(spread).roundToInt().coerceAtLeast(0)
val shadowOutset = ceil(PixelUtil.toPixelFromDIP(blurRadius))
val shadowShapeFrame = Rect(bounds).apply { inset(-spreadExtent, -spreadExtent) }
val shadowShapeBounds = Rect(0, 0, shadowShapeFrame.width(), shadowShapeFrame.height())

Expand Down Expand Up @@ -149,9 +151,11 @@ internal class OutsetBoxShadowDrawable(
offset(
PixelUtil.toPixelFromDIP(offsetX).roundToInt() - shadowShapeFrame.left,
PixelUtil.toPixelFromDIP(offsetY).roundToInt() - shadowShapeFrame.top)
inset(-shadowOutset.roundToInt(), -shadowOutset.roundToInt())
})

beginRecording().let { renderNodeCanvas ->
renderNodeCanvas.translate(shadowOutset, shadowOutset)
if (shadowBorderRadii?.hasRoundedBorders() == true) {
renderNodeCanvas.drawPath(shadowOuterPath, shadowPaint)
} else {
Expand Down

0 comments on commit 42de92e

Please sign in to comment.