

Compose has few ways to add shadows.
This library provides box shadows and drop shadows to enrich shadow expression of Compose.
Install
repositories {
google()
mavenCentral()
maven {
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
mavenContent {
snapshotsOnly()
includeGroup("io.github.kubode.compose.shadow")
}
}
}
dependencies {
implementation("io.github.kubode.compose.shadow:compose-boxshadow:$latestVersion")
implementation("io.github.kubode.compose.shadow:compose-dropshadow:$latestVersion")
}
Usage
Samples are available in sample.
DropShadow
Simple usage:
DropShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
) {
Image(
painter = painterResource(id = R.drawable.ic_android_black_24dp),
contentDescription = null,
modifier = Modifier.size(48.dp),
colorFilter = ColorFilter.tint(Color(0xFF3DDC84)),
)
}
With animation:
val infiniteTransition = rememberInfiniteTransition(label = "infinite")
val degrees by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1000, easing = LinearEasing)
),
label = "degrees",
)
DropShadow(
color = Color.Black.copy(alpha = ),
offset = DpOffset(dp, dp),
radius = dp,
drawInvalidationTrigger = { degrees },
) {
Image(
painter = painterResource(id = R.drawable.ic_android_black_24dp),
contentDescription = ,
modifier = Modifier
.size(dp)
.rotate(degrees),
colorFilter = ColorFilter.tint(Color()),
)
}
BoxShadow
Box(
modifier = Modifier
.size(48.dp)
.boxShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
)
.background(Color.Red)
)
Compatibility
compose-dropshadow uses DrawScope.draw API newly introduced in Compose 1.6.0-alpha01.
Therefore, it requires Compose 1.6 or higher to work.
License
Copyright 2023 Masatoshi Kubode
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.