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

zt

05/20/2022, 4:31 AM
I'm having a crash caused by navigating from a screen containing a lazy column to another one, then navigating back. The stack trace doesn't point to any of my code so I'm not sure what's going on
b

Ben Trengrove [G]

05/20/2022, 4:32 AM
Which version of Compose are you running?
z

zt

05/20/2022, 4:32 AM
I'm using 1.2.0-beta01
b

Ben Trengrove [G]

05/20/2022, 4:33 AM
It's hard to say without seeing any code but I would guess thats a bug that needs to be filed
z

zt

05/20/2022, 4:38 AM
Maybe this will help
a

Andrey Kulikov

05/20/2022, 12:41 PM
it is not a know bug. if you can provide a reproducible sample we can try to fix that
z

zt

05/20/2022, 8:50 PM
I might have narrowed the issue down, the way I'm doing search is by setting the paging source to a new instance, which I doubt is the best way of doing it. Testing with it set already to an instance of a paging source seems to fix the bug. I'm not really sure how else to create a source for paging data when the search button is pressed though
It looks like this in my viewmodel
Copy code
var results by mutableStateOf<Flow<PagingData<DomainSearch.Result>>>(emptyFlow())
    private set
Copy code
fun getResults() {
    results = Pager(PagingConfig(10)) {
        object : PagingSource<String, DomainSearch.Result>() {
            override suspend fun load(params: LoadParams<String>): LoadResult<String, DomainSearch.Result> {
                return try {
                    val searchResults = repository.getSearchResults(search, params.key)

                    LoadResult.Page(
                        data = searchResults.items,
                        prevKey = null,
                        nextKey = searchResults.continuation
                    )
                } catch (e: Exception) {
                    e.printStackTrace()
                    LoadResult.Error(e)
                }
            }

            override fun getRefreshKey(state: PagingState<String, DomainSearch.Result>): String? =
                null
        }
    }.flow.cachedIn(viewModelScope)
}