From 25dcbc6d8c753ec745e9bd45520cb66e706b77be Mon Sep 17 00:00:00 2001 From: raine-lemon Date: Mon, 2 Sep 2024 09:43:14 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20Move=20packages=20-=20=EC=86=8C?= =?UTF-8?q?=EC=8A=A4=20=ED=8C=8C=EC=9D=BC=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/lemon/core/{ => android}/component/intent/Intent.kt | 0 .../io/lemon/core/{ => android}/component/intent/IntentBuilder.kt | 0 .../io/lemon/core/{ => android}/component/intent/PendingIntent.kt | 0 .../core/{ => android}/component/launcher/ActivityLauncher.kt | 0 .../core/{ => android}/component/launcher/ReceiverLauncher.kt | 0 .../core/{ => android}/component/launcher/ServiceLauncher.kt | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename android-component/src/main/java/io/lemon/core/{ => android}/component/intent/Intent.kt (100%) rename android-component/src/main/java/io/lemon/core/{ => android}/component/intent/IntentBuilder.kt (100%) rename android-component/src/main/java/io/lemon/core/{ => android}/component/intent/PendingIntent.kt (100%) rename android-component/src/main/java/io/lemon/core/{ => android}/component/launcher/ActivityLauncher.kt (100%) rename android-component/src/main/java/io/lemon/core/{ => android}/component/launcher/ReceiverLauncher.kt (100%) rename android-component/src/main/java/io/lemon/core/{ => android}/component/launcher/ServiceLauncher.kt (100%) diff --git a/android-component/src/main/java/io/lemon/core/component/intent/Intent.kt b/android-component/src/main/java/io/lemon/core/android/component/intent/Intent.kt similarity index 100% rename from android-component/src/main/java/io/lemon/core/component/intent/Intent.kt rename to android-component/src/main/java/io/lemon/core/android/component/intent/Intent.kt diff --git a/android-component/src/main/java/io/lemon/core/component/intent/IntentBuilder.kt b/android-component/src/main/java/io/lemon/core/android/component/intent/IntentBuilder.kt similarity index 100% rename from android-component/src/main/java/io/lemon/core/component/intent/IntentBuilder.kt rename to android-component/src/main/java/io/lemon/core/android/component/intent/IntentBuilder.kt diff --git a/android-component/src/main/java/io/lemon/core/component/intent/PendingIntent.kt b/android-component/src/main/java/io/lemon/core/android/component/intent/PendingIntent.kt similarity index 100% rename from android-component/src/main/java/io/lemon/core/component/intent/PendingIntent.kt rename to android-component/src/main/java/io/lemon/core/android/component/intent/PendingIntent.kt diff --git a/android-component/src/main/java/io/lemon/core/component/launcher/ActivityLauncher.kt b/android-component/src/main/java/io/lemon/core/android/component/launcher/ActivityLauncher.kt similarity index 100% rename from android-component/src/main/java/io/lemon/core/component/launcher/ActivityLauncher.kt rename to android-component/src/main/java/io/lemon/core/android/component/launcher/ActivityLauncher.kt diff --git a/android-component/src/main/java/io/lemon/core/component/launcher/ReceiverLauncher.kt b/android-component/src/main/java/io/lemon/core/android/component/launcher/ReceiverLauncher.kt similarity index 100% rename from android-component/src/main/java/io/lemon/core/component/launcher/ReceiverLauncher.kt rename to android-component/src/main/java/io/lemon/core/android/component/launcher/ReceiverLauncher.kt diff --git a/android-component/src/main/java/io/lemon/core/component/launcher/ServiceLauncher.kt b/android-component/src/main/java/io/lemon/core/android/component/launcher/ServiceLauncher.kt similarity index 100% rename from android-component/src/main/java/io/lemon/core/component/launcher/ServiceLauncher.kt rename to android-component/src/main/java/io/lemon/core/android/component/launcher/ServiceLauncher.kt From 00d0931d0f43e3ef85dc681537792143094cb0f8 Mon Sep 17 00:00:00 2001 From: raine-lemon Date: Mon, 2 Sep 2024 09:45:32 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20Rename=20file=20-=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95=20-=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/compose/util/{Modifier.kt => modifier/Clickable.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename compose-util/src/main/java/io/lemon/core/compose/util/{Modifier.kt => modifier/Clickable.kt} (98%) diff --git a/compose-util/src/main/java/io/lemon/core/compose/util/Modifier.kt b/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Clickable.kt similarity index 98% rename from compose-util/src/main/java/io/lemon/core/compose/util/Modifier.kt rename to compose-util/src/main/java/io/lemon/core/compose/util/modifier/Clickable.kt index fb82c78..a6b09d0 100644 --- a/compose-util/src/main/java/io/lemon/core/compose/util/Modifier.kt +++ b/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Clickable.kt @@ -1,4 +1,4 @@ -package io.lemon.core.compose.util +package io.lemon.core.compose.util.modifier import androidx.compose.foundation.Indication import androidx.compose.foundation.clickable From 5b896c2d5161aefbda815b0c1beee0e671f2e4a5 Mon Sep 17 00:00:00 2001 From: raine-lemon Date: Mon, 2 Sep 2024 09:54:30 +0900 Subject: [PATCH 3/4] feat: Add toggleable modifier extensions --- .../core/compose/util/modifier/Toggleable.kt | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 compose-util/src/main/java/io/lemon/core/compose/util/modifier/Toggleable.kt diff --git a/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Toggleable.kt b/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Toggleable.kt new file mode 100644 index 0000000..5e70c73 --- /dev/null +++ b/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Toggleable.kt @@ -0,0 +1,103 @@ +package io.lemon.core.compose.util.modifier + +import androidx.compose.foundation.Indication +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.selection.toggleable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableLongStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.composed +import androidx.compose.ui.semantics.Role +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +/** + * Toggle interaction 이 연속적으로 발생하는 것을 방지하는 확장자 + */ +fun Modifier.throttleToggleable( + value: Boolean, + onValueChange: (Boolean) -> Unit, + enabled: Boolean = true, + role: Role? = null, + coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main, + throttleTime: Long = 250L, +) = composed { + val coroutineScope = rememberCoroutineScope { coroutineDispatcher } + var lastEmissionTime: Long by remember { mutableLongStateOf(0L) } + + toggleable( + value = value, + onValueChange = { + val currentTime = System.currentTimeMillis() + if (currentTime - lastEmissionTime >= throttleTime) { + coroutineScope.launch { + lastEmissionTime = currentTime + onValueChange(it) + } + } + lastEmissionTime = currentTime + }, + enabled = enabled, + role = role, + ) +} + +/** + * Toggle interaction 이 연속적으로 발생하는 것을 방지하는 확장자 + */ +fun Modifier.throttleToggleable( + value: Boolean, + onValueChange: (Boolean) -> Unit, + interactionSource: MutableInteractionSource = MutableInteractionSource(), + indication: Indication? = null, + enabled: Boolean = true, + role: Role? = null, + coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main, + throttleTime: Long = 250L, +) = composed { + val coroutineScope = rememberCoroutineScope { coroutineDispatcher } + var lastEmissionTime: Long by remember { mutableLongStateOf(0L) } + + noRippleToggleable( + value = value, + onValueChange = { + val currentTime = System.currentTimeMillis() + if (currentTime - lastEmissionTime >= throttleTime) { + coroutineScope.launch { + lastEmissionTime = currentTime + onValueChange(it) + } + } + lastEmissionTime = currentTime + }, + interactionSource = remember { interactionSource }, + indication = indication, + enabled = enabled, + role = role + ) +} + +/** + * Toggle interaction 중 발생하는 시각 이펙트를 제거하는 확장자 + */ +fun Modifier.noRippleToggleable( + value: Boolean, + onValueChange: (Boolean) -> Unit, + interactionSource: MutableInteractionSource = MutableInteractionSource(), + indication: Indication? = null, + enabled: Boolean = true, + role: Role? = null, +) = composed { + toggleable( + value = value, + interactionSource = remember { interactionSource }, + indication = indication, + enabled = enabled, + onValueChange = onValueChange, + role = role + ) +} From 39debf52d3bf9277787ffa9f8e5f4e6f26d254ab Mon Sep 17 00:00:00 2001 From: raine-lemon Date: Mon, 2 Sep 2024 14:14:28 +0900 Subject: [PATCH 4/4] feat: Add drop shadow modifier extensions --- .../core/compose/util/modifier/Shadow.kt | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 compose-util/src/main/java/io/lemon/core/compose/util/modifier/Shadow.kt diff --git a/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Shadow.kt b/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Shadow.kt new file mode 100644 index 0000000..1b8ed42 --- /dev/null +++ b/compose-util/src/main/java/io/lemon/core/compose/util/modifier/Shadow.kt @@ -0,0 +1,104 @@ +package io.lemon.core.compose.util.modifier + +import android.graphics.BlurMaskFilter +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Paint +import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.graphics.drawOutline +import androidx.compose.ui.graphics.drawscope.drawIntoCanvas +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.dp + +/** + * @param shape 그림자에 적용할 모양 + * @param color 그림자 색상 + * @param offset 그림자의 위치 + * @param blur 그림자 흐림 효과 (번짐의 정도) + * @param spread 그림자의 확산효과이며, 그림자의 크기; + * 음수로 할 경우 그림자의 크기가 기존 도형보다 줄어듭니다. + */ +fun Modifier.dropShadow( + shape: Shape, + color: Color, + offset: DpOffset, + blur: Dp = 1.dp, + spread: Dp = 0.dp +) = drawBehind { + + drawIntoCanvas { canvas -> + canvas.save() + canvas.translate(dx = offset.x.toPx(), dy = offset.y.toPx()) // 캔버스 위치 이동 + canvas.drawOutline( + outline = shape.createOutline( + size = Size( + width = size.width + spread.toPx(), + height = size.height + spread.toPx() + ), + layoutDirection = layoutDirection, + density = this + ), // 그림자 사이즈 구성 + paint = Paint().apply { + this.color = color + blur.toPx().takeIf { it > 0f }?.let { radius -> + asFrameworkPaint().apply { + maskFilter = BlurMaskFilter( + /* radius = */ radius, + /* style = */ BlurMaskFilter.Blur.NORMAL + ) + } + } + } // 그림자 스타일 구성 + ) // 그림자 생성 + canvas.restore() + } +} + +/** + * @param shape 그림자에 적용할 모양 + * @param color 그림자 색상 + * @param yOffset 그림자의 y 오프셋 + * @param xOffset 그림자의 x 오프셋 + * @param blur 그림자 흐림 효과 (번짐의 정도) + * @param spread 그림자의 확산효과이며, 그림자의 크기; + * 음수로 할 경우 그림자의 크기가 기존 도형보다 줄어듭니다. + */ +fun Modifier.dropShadow( + shape: Shape, + color: Color, + yOffset: Dp = 0.dp, + xOffset: Dp = 0.dp, + blur: Dp = 1.dp, + spread: Dp = 0.dp +) = drawBehind { + + drawIntoCanvas { canvas -> + canvas.save() + canvas.translate(dx = xOffset.toPx(), dy = yOffset.toPx()) // 캔버스 위치 이동 + canvas.drawOutline( + outline = shape.createOutline( + size = Size( + width = size.width + spread.toPx(), + height = size.height + spread.toPx() + ), + layoutDirection = layoutDirection, + density = this + ), // 그림자 사이즈 구성 + paint = Paint().apply { + this.color = color + blur.toPx().takeIf { it > 0f }?.let { radius -> + asFrameworkPaint().apply { + maskFilter = BlurMaskFilter( + /* radius = */ radius, + /* style = */ BlurMaskFilter.Blur.NORMAL + ) + } + } + } // 그림자 스타일 구성 + ) // 그림자 생성 + canvas.restore() + } +}