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

Instead of callback, can I use a @State to control refresh action? #11

Closed
long-nguyen opened this issue Dec 21, 2021 · 4 comments
Closed

Comments

@long-nguyen
Copy link

Hi, thank you for your great implementation.
How could I achieve things like using @State var loading = false to control when the refreshing action should be finish.
Thanks

@gordan-glavas-codecons
Copy link
Collaborator

Hi,

the library is completely agnostic in terms of how you handle your refreshing, which also includes how you cancel it. In other words, something like this would work:

RefreshableScrollView(onRefresh: { done in
           isLoading = true
           DispatchQueue(label: "background").async {
             while isLoading { }
             done()
           }
          },

As far as triggering the refresh action by setting isLoading to true, I need to think about it a bit more. It's certainly a possibility.

@long-nguyen
Copy link
Author

@gordan-glavas-codecons
thank you. But the done() event, how can I call it in another functions outside the onRefresh callback like above?

@gordan-glavas-codecons
Copy link
Collaborator

It's just a block you can pass it around any way you want. You can even store it in a state var:

@State private var refreshBlock: RefreshComplete? = nil
...
RefreshableScrollView(onRefresh: { done in
           refreshBlock = done
}

// call refreshBlock?() elsewhere

@long-nguyen
Copy link
Author

@gordan-glavas-codecons
Thank you, great!

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

2 participants