Hey folks, I've been integrating KMM into our nati...
# multiplatform
Hey folks, I've been integrating KMM into our native apps, and now building out a feature that requires pagination. Android side is straightforward, but we're using SwiftUI in our iOS app. Wondering if anyone can recommend a sample project that integrates Cashapp's multiplatform paging into an iOS app that uses SwiftUI. TIA!
Not a direct answer but using https://github.com/kuuuurt/multiplatform-paging in https://github.com/joreilly/MortyComposeKMM (which uses Compose and SwiftUI)
Thanks! I did run into that example, and that library solves the question I have. Essentially, how does iOS tell the pager to fetch more data. In the example you shared, a
function is exposed, which is great. But, I was trying to determine how to mimic that using Cashapp's library. Perhaps I need to call load in the paging source directly?
Not really an answer to your initial question, but there's an open issue about adding Swift UI support here. If you do find an implementation, I'd be very happy to link to it from the README!
Thanks @veyndan. Yeah, haven't found a great example yet, but maybe I can write up the first. My main question is what I mentioned above. From the SwiftUI side, how can I programmatically trigger another page load?
So you'll probably want to use a
in iOS and hook up the necessary things (sorry it's a bit handwavy as idk Swift UI). Then, whenever you call
(which retrieves an item at an index), that function will internally check if it should load the next page of data or not. So essentially you shouldn't need to programatically trigger another page load. By incrementally loading data as you scroll, additional pages will be loaded as needed. Quick example — assume you have page sizes of 30, your view port can show 10 items at a time, and you have configured to load the next page when you're 5 items before the end of the page. When you call
on the first 10 items on screen, no additional page loads are required. When you scroll a bit and show the item range 16 to 26 on screen, you're now 5 away, and paging will internally trigger an additional page load.
FWIW the
approach is what
does under the hood. Here's the implementation, which may or may not be useful.