@@ -2,99 +2,43 @@ package com.neki.android.feature.photo_upload.impl.qrscan.component
22
33import androidx.compose.foundation.Canvas
44import androidx.compose.foundation.layout.Box
5- import androidx.compose.foundation.layout.BoxScope
65import androidx.compose.foundation.layout.fillMaxSize
7- import androidx.compose.foundation.layout.padding
86import androidx.compose.runtime.Composable
9- import androidx.compose.runtime.Immutable
10- import androidx.compose.runtime.getValue
11- import androidx.compose.runtime.mutableStateOf
12- import androidx.compose.runtime.remember
13- import androidx.compose.runtime.setValue
147import androidx.compose.ui.Modifier
15- import androidx.compose.ui.geometry.CornerRadius
168import androidx.compose.ui.geometry.Offset
179import androidx.compose.ui.geometry.Size
1810import androidx.compose.ui.graphics.BlendMode
1911import androidx.compose.ui.graphics.Color
2012import androidx.compose.ui.graphics.CompositingStrategy
2113import androidx.compose.ui.graphics.graphicsLayer
22- import androidx.compose.ui.layout.onGloballyPositioned
23- import androidx.compose.ui.layout.positionInParent
24- import androidx.compose.ui.platform.LocalDensity
25- import androidx.compose.ui.unit.Dp
26- import androidx.compose.ui.unit.dp
27- import com.neki.android.feature.photo_upload.impl.qrscan.const.QRLayoutConst.CUTOUT_RADIUS
14+ import androidx.compose.ui.unit.IntSize
2815import com.neki.android.feature.photo_upload.impl.qrscan.const.QRLayoutConst.DIM_COLOR
2916
30- @Immutable
31- private data class CutoutRectPx (
32- val left : Float ,
33- val top : Float ,
34- val width : Float ,
35- val height : Float ,
36- )
37-
3817@Composable
3918internal fun DimExceptContent (
19+ offSet : Offset ? ,
20+ size : IntSize ? ,
4021 modifier : Modifier = Modifier ,
4122 dimColor : Color = Color (DIM_COLOR ),
42- cutoutRadius : Dp = CUTOUT_RADIUS .dp,
43- cutoutPadding : Dp = 0.dp,
44- cutout : @Composable BoxScope .(Modifier ) -> Unit ,
4523) {
46- val density = LocalDensity .current
47- var cutoutRect by remember { mutableStateOf<CutoutRectPx ?>(null ) }
48-
49- val paddingPx = with (density) { cutoutPadding.toPx() }
50- val radiusPx = with (density) { cutoutRadius.toPx() }
51-
52- Box (modifier = modifier) {
53- cutout(
54- Modifier
55- .padding(bottom = 20 .dp)
56- .onGloballyPositioned { coords ->
57- val pos = coords.positionInParent()
58- val size = coords.size
59- cutoutRect = CutoutRectPx (
60- left = pos.x,
61- top = pos.y,
62- width = size.width.toFloat(),
63- height = size.height.toFloat(),
64- )
65- },
66- )
67-
24+ Box (
25+ modifier = modifier,
26+ ) {
6827 Canvas (
6928 modifier = Modifier
7029 .fillMaxSize()
7130 .graphicsLayer { compositingStrategy = CompositingStrategy .Offscreen },
7231 ) {
7332 drawRect(dimColor)
7433
75- val c = cutoutRect ? : return @Canvas
76-
77- val left = c.left - paddingPx
78- val top = c.top - paddingPx
79- val w = c.width + paddingPx * 2f
80- val h = c.height + paddingPx * 2f
34+ if (offSet == null || size == null ) return @Canvas
8135
82- if (radiusPx > 0f ) {
83- drawRoundRect(
84- color = Color .Transparent ,
85- topLeft = Offset (left, top),
86- size = Size (w, h),
87- cornerRadius = CornerRadius (radiusPx, radiusPx),
88- blendMode = BlendMode .Clear ,
89- )
90- } else {
91- drawRect(
92- color = Color .Transparent ,
93- topLeft = Offset (left, top),
94- size = Size (w, h),
95- blendMode = BlendMode .Clear ,
96- )
97- }
36+ drawRoundRect(
37+ color = Color .Transparent ,
38+ topLeft = offSet,
39+ size = Size (size.width.toFloat(), size.height.toFloat()),
40+ blendMode = BlendMode .Clear ,
41+ )
9842 }
9943 }
10044}
0 commit comments