Saliou seck
02/05/2024, 6:13 PMTravis Griggs
02/05/2024, 6:21 PMSaliou seck
02/05/2024, 6:23 PMTravis Griggs
02/05/2024, 6:37 PM*private fun* ScrimCover(
hole: ModalPeekhole, color: Color
) {
*val* outline = hole.*shape*.createOutline(
size = hole.*bounds*.*size*,
layoutDirection = _LocalLayoutDirection_.*current*,
density = _LocalDensity_.current
)
*val* cutout = _Path_()._apply_ *{*
_addOutline_(outline)
translate(_Offset_(hole.*bounds*.*left*, hole.*bounds*.*top*))
}
Canvas(modifier = Modifier
._fillMaxSize_()
._pointerInteropFilter_ *{* event *->*
*val* center = _Offset_(event._x_, event._y_)
*val* peephole = _Path_()._apply_ *{* addRect(_Rect_(center = center, 1f)) *}*
*val* isOutside = Path.combine(PathOperation.*Intersect*, cutout, peephole).*isEmpty*
isOutside
*}*) *{*
*val* full = _Path_()._apply_ *{* addRect(_Rect_(Offset.*Zero*, *size*)) *}*
*val* cover = Path.combine(operation = PathOperation.*Difference*, path1 = full, path2 = cutout)
drawPath(path = cover, color = color, style = Fill)
}
}
I use this to put a visual AND pointer mask that has a Shape as a cutout somewhere in it over the whole screen. So you could go with that.
On a simpler note, if you're just going the Rounded rectangle, you should be able to do a Path, add a rect for the outside, and then add a roundedRect for the peekhole. And then fill. You may need to use one of, or a combination of changing the winding rule of the Path, and having the direction of the inner rectangle be the opposite of the parent.Saliou seck
02/05/2024, 6:54 PMTravis Griggs
02/05/2024, 7:35 PMSaliou seck
02/05/2024, 7:41 PMTravis Griggs
02/05/2024, 7:50 PMSaliou seck
02/05/2024, 9:31 PM