Skip to content

Instantly share code, notes, and snippets.

@catalinghita8
Last active March 6, 2023 02:03
Show Gist options
  • Save catalinghita8/9107a8e79d2a1f70d115d79d618a2014 to your computer and use it in GitHub Desktop.
Save catalinghita8/9107a8e79d2a1f70d115d79d618a2014 to your computer and use it in GitHub Desktop.
@Composable
fun AnimatedBorderCard(
modifier: Modifier,
contents: @Composable RowScope.() -> Unit
) {
val containerSize = 200.dp
var offsetFloat by remember { mutableStateOf(0f) }
LaunchedEffect(null) {
delay(100)
offsetFloat = containerSize.value * 10f
}
val offset by animateFloatAsState(
targetValue = offsetFloat,
animationSpec = repeatable(
iterations = 4,
animation = tween(durationMillis = 6000, easing = LinearEasing),
),
)
val brush = Brush.linearGradient(
shineColors,
start = Offset(offset, offset),
end = Offset(offset + containerSize.value * 40, offset + containerSize.value * 40),
tileMode = TileMode.Repeated
)
Box(modifier = modifier.fillMaxSize()) {
Row(
modifier = Modifier
.fillMaxSize()
.clip(RoundedCornerShape(24.dp))
.border(
width = 2.5.dp, brush = brush, shape = RoundedCornerShape(24.dp)
)
.background(Color(0xFFA9A9A9))
.blur(2.dp),
) {
contents()
}
}
}
private val shineColors = listOf(
Color.White,
Color(0xFFF5C344),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment