Open maulikhirani opened 1 year ago
There aren't any current plans to support Swift UI from my side, but I'm happy to take a PR! My knowledge of iOS development is close to zero, so I don't know enough about Swift UI to give any pointers. If you have any specific questions about integrating Multiplatform Paging into Swift UI, I'd be happy to help on the Multiplatform Paging side of things!
I've found a way to use this library in SwiftUI My presenter is also using molecule on iOS, it should work well even you're not using it
class KotlinViewPresenter {
@Composable
fun body(): State {
//...
val listState: LazyPagingItems<Item> = ///
return State(
listState = listState,
)
}
}
in SwiftUI:
List {
ForEach(1...state.listState.itemCount) { index in
// using peek instead of get to avoid load the next page too early
let item = state.listState.peek(index - 1)
Text(item).onAppear {
// for loading more items
_ = state.listState.get(index - 1)
}
}
}
I've integrated it with SwiftUI.
You can add this class to your iosMain folder in common code & use it like this.
This sample has examples of how to add loading footer, error footer with retry page load functionality.
@veyndan Can you please look at it once? If it looks fine then I can raise a PR with the code & sample demo.
Thanks @Tlaster and @AshuTyagi16 for showing some code samples!
If it looks fine then I can raise a PR with the code & sample demo.
A PR would be lovely and very much appreciated!
If possible, a new sample under https://github.com/cashapp/multiplatform-paging/tree/main-3.3.0-alpha02/samples/repo-search named ios-swiftui
would be wonderful. Ideally the functionality should mimic that of the other samples their (i.e., a basic GitHub repository search).
Once that's done, I'll point to that sample as an example usage of Multiplatform Paging with Swift UI.
If it then makes sense to create a separate module containing helper classes (like your SwiftUiPagingHelper
class), we can do that in a separate pull request. I'd prefer to hold off on that though until we have a working sample.
As per the examples, it looks like this library only supports traditional UI for iOS (and Compose for iOS), not Swift UI. Is it planned to be supported? Any workarounds or pointers to make this work on Swift UI would be appreciated. Thanks!