joreilly / joreilly/MortyComposeKMM
Support for paging loading and error on SwiftUI
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 406
- Forks
- 27
- Avg merge
- 6d 11h
- Merged PRs (30d)
- 7
Description
Hi, thank you very much for this sample of KMP paging on SwiftUI.
Your SwiftUI implementation is missing some features found in the Compose version, such as handling loading states (for both the initial list and subsequent pages) and errors.
By looking at how collectAsLazyPagingItems() works in Compose, we discovered that we can expose the PagingDataPresenter's loadStateFlow from the KMP ViewModel. This flow can then be used in SwiftUI to observe loadState.append and loadState.refresh.
We have implemented this in our project, but I'm unable to create a PR because we are using SKIE, and I'm not sure how it should be implemented on the SwiftUI side with KMP-ObservableViewModel.
In any case, here is the line of code that can be added to the CharactersViewModel to be used from SwiftUI:
val charactersLoadState: Flow<CombinedLoadStates> = charactersPagingDataPresenter.loadStateFlow.filterNotNull()
I hope this is useful to someone else.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading CharactersViewModel and the existing SwiftUI paging implementation, then compare it with Compose's collectAsLazyPagingItems() behavior. Trace charactersPagingDataPresenter.loadStateFlow and determine how refresh and append states should be observed. Done means SwiftUI presents initial and subsequent-page loading states and errors consistently with the Compose version.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, swift
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100