joreilly / joreilly/MortyComposeKMM

Support for paging loading and error on SwiftUI

Open
#162 0 comments 2 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.