Last active
June 14, 2022 18:03
-
-
Save dilrajsingh1997/8dccb8edc8dd9a0d9029eda0f49899b1 to your computer and use it in GitHub Desktop.
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
val producerChannel = remember { | |
Channel<List<ItemState>>(Channel.UNLIMITED) | |
} | |
LaunchedEffect(true) { | |
for (incomingList in producerChannel) { | |
launch(Dispatchers.IO) { | |
itemsChannel.trySend(itemsToAnimate.value.toMutableList().apply { | |
addAll(incomingList) | |
}) | |
} | |
} | |
} | |
Button( | |
onClick = { | |
val randomX = Random.nextInt(0, (width).toInt()).toFloat() | |
producerChannel.trySend( | |
listOf( | |
ItemState( | |
x = randomX, | |
y = height, | |
xAnimation = TargetBasedAnimation( | |
animationSpec = tween(durationMillis = 5500, easing = FastOutSlowInEasing), | |
typeConverter = Float.VectorConverter, | |
initialValue = randomX, | |
targetValue = randomX | |
), | |
yAnimation = TargetBasedAnimation( | |
animationSpec = tween(durationMillis = 5500, easing = FastOutSlowInEasing), | |
typeConverter = Float.VectorConverter, | |
initialValue = height, | |
targetValue = height / 2 | |
), | |
) | |
) | |
) | |
}, | |
modifier = Modifier | |
.align(Alignment.BottomCenter) | |
.padding(24.dp) | |
.wrapContentHeight() | |
.wrapContentWidth() | |
) { | |
Text( | |
text = "Like", | |
color = Color.White | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment