-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADD/#28] CustomShadow 구현 #29
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
core/src/main/java/com/terning/core/designsystem/component/modifier/ShadowModifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifier의 확장함수면
core>extension
에 있는 Modifier.kt 파일에 넣는 게 좋을 것 같아요!!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어머어머 세상에 Modifier 이미 있는거 깜빡했네요😅 감사해용!!