Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use this library with Swift UI? #107

Open
maulikhirani opened this issue May 17, 2023 · 5 comments
Open

Can we use this library with Swift UI? #107

maulikhirani opened this issue May 17, 2023 · 5 comments

Comments

@maulikhirani
Copy link

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!

@veyndan
Copy link
Collaborator

veyndan commented May 17, 2023

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!

@Tlaster
Copy link

Tlaster commented Sep 28, 2023

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)
        }
    }
}

@AshuTyagi16
Copy link

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.

@veyndan
Copy link
Collaborator

veyndan commented Jan 18, 2024

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 SwiftUiPagingHelperclass), we can do that in a separate pull request. I'd prefer to hold off on that though until we have a working sample.

@BreakZero
Copy link

BreakZero commented Mar 25, 2024

refer to @AshuTyagi16 's sample, I did it like
View
ViewModel
looks more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants