This file contains hidden or 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
| 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) | |
| } | |
| } | |
| } |
This file contains hidden or 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
| private class AutoScrollItem<T>( | |
| val id: String = UUID.randomUUID().toString(), | |
| val data: T | |
| ) | |
| LazyRow( | |
| .. | |
| ) { | |
| itemsIndexed( | |
| items, key = { _, item -> item.id } |
This file contains hidden or 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
| LazyRow( | |
| state = lazyListState, | |
| modifier = modifier, | |
| horizontalArrangement = Arrangement.Center, | |
| verticalAlignment = Alignment.CenterVertically | |
| ) { | |
| itemsIndexed( | |
| items, key = { _, item -> item.id } | |
| ) { index, item -> | |
| itemContent(item = item.data) |
This file contains hidden or 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
| 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])) |
This file contains hidden or 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
| @Composable | |
| fun ChasingCircleAnimation(infiniteTransition: InfiniteTransition) { | |
| val arcAngle1 by infiniteTransition.animateFloat( | |
| initialValue = 0F, | |
| targetValue = 180F, | |
| animationSpec = infiniteRepeatable( | |
| animation = tween(1000, easing = LinearEasing), | |
| repeatMode = RepeatMode.Restart | |
| ) | |
| ) |
This file contains hidden or 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
| val arcAngle1 by infiniteTransition.animateFloat( | |
| initialValue = 0F, | |
| targetValue = 180F, | |
| animationSpec = infiniteRepeatable( | |
| animation = tween(1000, easing = LinearEasing), | |
| repeatMode = RepeatMode.Restart | |
| ) | |
| ) | |
| val arcAngle2 by infiniteTransition.animateFloat( |
This file contains hidden or 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
| val flashAnimation by infiniteTransition.animateFloat( | |
| initialValue = 1f, | |
| targetValue = 0f, | |
| animationSpec = infiniteRepeatable( | |
| tween(1000, easing = FastOutSlowInEasing), | |
| repeatMode = RepeatMode.Reverse | |
| ) | |
| ) | |
| Box( |
This file contains hidden or 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
| val angleOffset = 30f | |
| val wiggleAnimation by infiniteTransition.animateFloat( | |
| initialValue = -angleOffset, | |
| targetValue = angleOffset, | |
| animationSpec = infiniteRepeatable( | |
| animation = tween(500, easing = LinearEasing), | |
| repeatMode = RepeatMode.Reverse | |
| ) | |
| ) |
This file contains hidden or 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
| val heartbeatAnimation by infiniteTransition.animateFloat( | |
| initialValue = 1f, | |
| targetValue = 1.4f, | |
| animationSpec = infiniteRepeatable( | |
| animation = tween(1000), | |
| repeatMode = RepeatMode.Reverse | |
| ) | |
| ) | |
| Image( |
This file contains hidden or 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
| @Composable | |
| fun SadEmoji() { | |
| val size = 100 | |
| Canvas( | |
| modifier = Modifier | |
| .padding(top = 40.dp) | |
| .size(size.dp) | |
| ) { | |
| drawArc( |