Skip to content

Instantly share code, notes, and snippets.

View cp-hardik-p's full-sized avatar

hardik parmar cp-hardik-p

View GitHub Profile
suspend fun ScrollableState.autoScroll(
animationSpec: AnimationSpec<Float> = tween(durationMillis = 800, easing = LinearEasing)
) {
var previousValue = 0f
scroll(MutatePriority.PreventUserInput) {
animate(0f, SCROLL_DX, animationSpec = animationSpec) { currentValue, _ ->
previousValue += scrollBy(currentValue - previousValue)
}
}
}
private class AutoScrollItem<T>(
val id: String = UUID.randomUUID().toString(),
val data: T
)
LazyRow(
..
) {
itemsIndexed(
items, key = { _, item -> item.id }
LazyRow(
state = lazyListState,
modifier = modifier,
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
itemsIndexed(
items, key = { _, item -> item.id }
) { index, item ->
itemContent(item = item.data)
private fun <T : Any> List<T>.mapAutoScrollItem(): List<AutoScrollItem<T>> {
val newList = this.map { AutoScrollItem(data = it) }.toMutableList()
var index = 0
if (this.size < REQUIRED_CARD_COUNT) {
while (newList.size != REQUIRED_CARD_COUNT) {
if (index > this.size - 1) {
index = 0
}
newList.add(AutoScrollItem(data = this[index]))
@Composable
fun ChasingCircleAnimation(infiniteTransition: InfiniteTransition) {
val arcAngle1 by infiniteTransition.animateFloat(
initialValue = 0F,
targetValue = 180F,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
val arcAngle1 by infiniteTransition.animateFloat(
initialValue = 0F,
targetValue = 180F,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
val arcAngle2 by infiniteTransition.animateFloat(
val flashAnimation by infiniteTransition.animateFloat(
initialValue = 1f,
targetValue = 0f,
animationSpec = infiniteRepeatable(
tween(1000, easing = FastOutSlowInEasing),
repeatMode = RepeatMode.Reverse
)
)
Box(
val angleOffset = 30f
val wiggleAnimation by infiniteTransition.animateFloat(
initialValue = -angleOffset,
targetValue = angleOffset,
animationSpec = infiniteRepeatable(
animation = tween(500, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
)
)
val heartbeatAnimation by infiniteTransition.animateFloat(
initialValue = 1f,
targetValue = 1.4f,
animationSpec = infiniteRepeatable(
animation = tween(1000),
repeatMode = RepeatMode.Reverse
)
)
Image(
@Composable
fun SadEmoji() {
val size = 100
Canvas(
modifier = Modifier
.padding(top = 40.dp)
.size(size.dp)
) {
drawArc(