Closed Kerubel-Abera closed 2 months ago
Hey @Kerubel-Abera, you can achieve this easily with the AnimatedContent
with proper duration like the code below:
@Composable
fun CrossfadeImages(
modifier: Modifier = Modifier,
imageUrls: List<Poster>,
durationFadeMillis: Int = 500,
durationImageMillis: Int = 1000,
) {
var currentImageIndex by remember { mutableStateOf(0) }
LaunchedEffect(Unit) {
while (true) {
delay(durationImageMillis.toLong())
currentImageIndex = (currentImageIndex + 1) % imageUrls.size
}
}
AnimatedContent(
targetState = imageUrls[currentImageIndex].image,
modifier = modifier,
transitionSpec = {
(fadeIn(animationSpec = tween(durationFadeMillis, delayMillis = 0)))
.togetherWith(fadeOut(animationSpec = tween(durationFadeMillis, delayMillis = 0)))
}
) { state ->
CoilImage(
modifier = Modifier.fillMaxSize(),
imageModel = { state },
imageOptions = ImageOptions(contentScale = ContentScale.Crop),
)
}
}
The result:
How can I make my image crossfade between a list of images without it disappearing for a second? the animation is working but the it fades from image -> background -> image instead of image -> image
heres my code: