I have used accompanist library with older version like 0.22 as far as I know accompanist is deprecated, I made a migration to foundation -> import androidx.compose.foundation.pager.HorizontalPager. And now my problem is: I have auto logic to get auto slider every 3 seconds also I am available to manually change the actual image on the slider. When I do it manually it starts to triggers multiple time like LaunchedEffect starts trigger that many times as it was done manually. If I do not do anything and only auto slider works it is fine. I haven't that problem with accompanist. The only change is library and fix for this version I had to make with adding coroutineScope.launch {} in LaunchedEffect

        LaunchedEffect("${state.currentPage}") {
                coroutineScope.launch {
                    delay(AUTO_SLIDER_DELAY)
                    if (state.pageCount != 0) {
                        var newPosition = state.currentPage + 1
                        if (newPosition > sliderItems.size - 1) newPosition = 0
                        state.animateScrollToPage(newPosition.mod(state.pageCount))
                    }
            }
        }
         HorizontalPager(
                        state = state
                    ) { page ->
   
                                    AsyncBlurryImage(
                                        imageUrl = imageUrl.value,
                                        contentScale = ContentScale.Crop,
                                        contentDescription = null,
                                        modifier = Modifier
                                            .aspectRatio(1.77f)
[...]
                                           

I see the problem could be that now my external coroutine logic which is created out of LaunchedEffect does not stop during the recomposition how to refix it?

0

There are 0 best solutions below