Last active
January 5, 2024 12:24
-
-
Save muhammedesadcomert/4a457010f0c6418db0ae45824b58920b to your computer and use it in GitHub Desktop.
Infinite Transition with Pager
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 pagerState = rememberPagerState { Int.MAX_VALUE } | |
LaunchedEffect(Unit) { | |
while (true) { | |
delay(1500) // The duration of the image on the screen | |
if (pagerState.currentPage >= YourEnumClass.entries.lastIndex - 1) { | |
pagerState.animateScrollToPage(0) // If it reaches the end of the list, it returns to the beginning | |
} else { | |
pagerState.animateScrollToPage(pagerState.currentPage + 1) | |
} | |
} | |
} | |
HorizontalPager( | |
modifier = Modifier.fillMaxWidth(), | |
state = pagerState, | |
userScrollEnabled = false, | |
verticalAlignment = Alignment.CenterVertically, | |
) { page -> | |
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { | |
Image( | |
modifier = Modifier.size(72.dp), | |
// I'm using an Enum Class for images. But you can use a regular list here, it's not mandatory | |
painter = painterResource(id = YourEnumClass.entries[page].imageRes), | |
contentDescription = null | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment