Skip to content

Instantly share code, notes, and snippets.

@dilrajsingh1997
Last active June 14, 2022 18:03
Show Gist options
  • Save dilrajsingh1997/8dccb8edc8dd9a0d9029eda0f49899b1 to your computer and use it in GitHub Desktop.
Save dilrajsingh1997/8dccb8edc8dd9a0d9029eda0f49899b1 to your computer and use it in GitHub Desktop.
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