https://kotlinlang.org logo
#compose
Title
# compose
s

Shakil Karim

01/11/2021, 7:23 AM
I using paging with Compose but it crashes the app on orientation change, but with the normal list, it's work fine.
Copy code
--------------------- in ViewModel ---------------------------- 
val newsSelection : MutableStateFlow<HeadlinesPagingKey> = MutableStateFlow(
            HeadlinesPagingKey())

@ExperimentalCoroutinesApi
     val topHeadlines: Flow<PagingData<Article>> =
             newsSelection.flatMapLatest {
                 newsRepository.topNewsHeadlines(it)
             }.shareIn(viewModelScope, SharingStarted.Lazily,1)

---------------------and in Composable---------------------------- 

val lazyPagingItems: LazyPagingItems<Article> =
        headlinesViewModel.topHeadlines.collectAsLazyPagingItems()
a

Andrey Kulikov

01/11/2021, 12:41 PM
could you share a crash?
s

Shakil Karim

01/11/2021, 4:05 PM
I am getting this exception when using shareIn operator java.lang.IllegalStateException: Attempt to collect twice from pageEventFlow, which is an illegal operation. Did you forget to call Flow<PagingData<*>>.cachedIn(coroutineScope)?
15 Views