From 39cbd47e173084f93c914e91e6998cc92019b259 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Wed, 10 Jul 2024 02:44:51 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[CHORE/#28]=20Preview=20dependency=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index c53a6a378..6c7528d49 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -59,6 +59,7 @@ dependencies { // Compose Preview debugImplementation(libs.compose.ui.tooling) + implementation(libs.androidx.ui.tooling.preview) // Test Dependency testImplementation(libs.junit) From 3f45ad55e1877611357e01facf777d291f187bcb Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Wed, 10 Jul 2024 04:27:18 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[FEAT/#28]=20customShadow=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/modifier/ShadowModifier.kt | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt diff --git a/core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt b/core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt new file mode 100644 index 000000000..ad17c3c77 --- /dev/null +++ b/core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt @@ -0,0 +1,68 @@ +package com.terning.core.designsystem.component.modifier + +import android.graphics.BlurMaskFilter +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.composed +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Paint +import androidx.compose.ui.graphics.drawscope.drawIntoCanvas +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.terning.core.designsystem.theme.Grey200 + +@Composable +fun Modifier.customShadow( + color: Color = Grey200, + shadowRadius: Dp = 0.dp, + shadowWidth: Dp = 2.dp, + offsetX: Dp = 0.dp, + offsetY: Dp = 0.dp, +) = composed { + val paint: Paint = remember { Paint() } + val density = LocalDensity.current + val radius = shadowRadius + shadowWidth + val blurRadiusPx = with(density) { radius.toPx() } + val maskFilter = remember { + BlurMaskFilter(blurRadiusPx, BlurMaskFilter.Blur.NORMAL) + } + drawBehind { + drawIntoCanvas { canvas -> + val frameworkPaint = paint.asFrameworkPaint() + if (radius != 0.dp) { + frameworkPaint.maskFilter = maskFilter + } + frameworkPaint.color = color.toArgb() + + val leftPixel = offsetX.toPx() + val topPixel = offsetY.toPx() + val rightPixel = size.width + leftPixel + val bottomPixel = size.height + topPixel + + if (radius > 0.dp) { + val radiusPx = radius.toPx() + canvas.drawRoundRect( + left = leftPixel, + top = topPixel, + right = rightPixel, + bottom = bottomPixel, + radiusX = radiusPx, + radiusY = radiusPx, + paint = paint, + ) + } else { + canvas.drawRect( + left = leftPixel, + top = topPixel, + right = rightPixel, + bottom = bottomPixel, + paint = paint, + ) + } + } + } +} From ecfa173df16a79545fb6cef696cc6a85db1a419b Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Wed, 10 Jul 2024 15:52:40 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[CHORE/#28]=20Modifier.kt=EB=A1=9C=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/modifier/ShadowModifier.kt | 68 ------------------- .../com/terning/core/extension/Modifier.kt | 63 +++++++++++++++++ 2 files changed, 63 insertions(+), 68 deletions(-) delete mode 100644 core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt diff --git a/core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt b/core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt deleted file mode 100644 index ad17c3c77..000000000 --- a/core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.terning.core.designsystem.component.modifier - -import android.graphics.BlurMaskFilter -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import androidx.compose.ui.composed -import androidx.compose.ui.draw.drawBehind -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.Paint -import androidx.compose.ui.graphics.drawscope.drawIntoCanvas -import androidx.compose.ui.graphics.toArgb -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp -import com.terning.core.designsystem.theme.Grey200 - -@Composable -fun Modifier.customShadow( - color: Color = Grey200, - shadowRadius: Dp = 0.dp, - shadowWidth: Dp = 2.dp, - offsetX: Dp = 0.dp, - offsetY: Dp = 0.dp, -) = composed { - val paint: Paint = remember { Paint() } - val density = LocalDensity.current - val radius = shadowRadius + shadowWidth - val blurRadiusPx = with(density) { radius.toPx() } - val maskFilter = remember { - BlurMaskFilter(blurRadiusPx, BlurMaskFilter.Blur.NORMAL) - } - drawBehind { - drawIntoCanvas { canvas -> - val frameworkPaint = paint.asFrameworkPaint() - if (radius != 0.dp) { - frameworkPaint.maskFilter = maskFilter - } - frameworkPaint.color = color.toArgb() - - val leftPixel = offsetX.toPx() - val topPixel = offsetY.toPx() - val rightPixel = size.width + leftPixel - val bottomPixel = size.height + topPixel - - if (radius > 0.dp) { - val radiusPx = radius.toPx() - canvas.drawRoundRect( - left = leftPixel, - top = topPixel, - right = rightPixel, - bottom = bottomPixel, - radiusX = radiusPx, - radiusY = radiusPx, - paint = paint, - ) - } else { - canvas.drawRect( - left = leftPixel, - top = topPixel, - right = rightPixel, - bottom = bottomPixel, - paint = paint, - ) - } - } - } -} diff --git a/core/src/main/java/com/terning/core/extension/Modifier.kt b/core/src/main/java/com/terning/core/extension/Modifier.kt index 57cca1101..789d198b5 100644 --- a/core/src/main/java/com/terning/core/extension/Modifier.kt +++ b/core/src/main/java/com/terning/core/extension/Modifier.kt @@ -1,14 +1,25 @@ package com.terning.core.extension import android.annotation.SuppressLint +import android.graphics.BlurMaskFilter import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.composed +import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.focus.FocusManager +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Paint +import androidx.compose.ui.graphics.drawscope.drawIntoCanvas +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.terning.core.designsystem.theme.Grey200 @SuppressLint("ModifierFactoryUnreferencedReceiver") inline fun Modifier.noRippleClickable(crossinline onClick: () -> Unit): Modifier = composed { @@ -25,3 +36,55 @@ fun Modifier.addFocusCleaner(focusManager: FocusManager): Modifier { }) } } + +@Composable +fun Modifier.customShadow( + color: Color = Grey200, + shadowRadius: Dp = 0.dp, + shadowWidth: Dp = 2.dp, + offsetX: Dp = 0.dp, + offsetY: Dp = 0.dp, +) = composed { + val paint: Paint = remember { Paint() } + val density = LocalDensity.current + val radius = shadowRadius + shadowWidth + val blurRadiusPx = with(density) { radius.toPx() } + val maskFilter = remember { + BlurMaskFilter(blurRadiusPx, BlurMaskFilter.Blur.NORMAL) + } + drawBehind { + drawIntoCanvas { canvas -> + val frameworkPaint = paint.asFrameworkPaint() + if (radius != 0.dp) { + frameworkPaint.maskFilter = maskFilter + } + frameworkPaint.color = color.toArgb() + + val leftPixel = offsetX.toPx() + val topPixel = offsetY.toPx() + val rightPixel = size.width + leftPixel + val bottomPixel = size.height + topPixel + + if (radius > 0.dp) { + val radiusPx = radius.toPx() + canvas.drawRoundRect( + left = leftPixel, + top = topPixel, + right = rightPixel, + bottom = bottomPixel, + radiusX = radiusPx, + radiusY = radiusPx, + paint = paint, + ) + } else { + canvas.drawRect( + left = leftPixel, + top = topPixel, + right = rightPixel, + bottom = bottomPixel, + paint = paint, + ) + } + } + } +}