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

Use Promises for ListView onRefresh #232

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Use Promises for ListView onRefresh #232

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 17, 2017

I faced with an issue that in ListView RefreshControl spins forever...
Someone recommend to use ListView loading prop to Dismiss refreshControl, but it seems in ListView Statuses are strings like Status.IDLE, Status.REFRESHING and so on, but the loading prop is a boolean value and it cause issues.

Currently refresh Control automatically set ListView Component status: Status.REFRESHING and then call this.props.onRefresh that I was passed from MyComponent.
In MyComponent I have an state like this.state.loading : false and when I want to set loading prop, I should set it to this.setState({loading: true}) on MyComponent onRefresh prop, so as soon as ListView componentWillReceiveProps triggered, refreshControl will disappear ( in Less than one second ), because my status state is not equals to ListView component status state. So there is no possibility to keep spins without hacks.

so Its nice to use Promise to handle this issue.

<ListView
    data={this.state.items}
    loading={this.state.loading}
    onRefresh={() => {
       return new Promise((resolve, reject) => {
           setTimeout(() => {
               resolve(true);
           }, 4000);
       });
    }}
    renderRow={() => {}}
/>

@ghost ghost changed the title Use Promises for RefreshControl Use Promises for ListView onRefresh Apr 17, 2017
@ghost
Copy link
Author

ghost commented Apr 17, 2017

#150

@SoHotSoup SoHotSoup self-requested a review April 18, 2017 07:39
this.props.onRefresh();
const callback = this.props.onRefresh();
const setIdle = () => {
if(this._isMounted) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this? Is it even possible that onRefresh is called before component is mounted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It because there is no way to unsubscribe from promises, so this._isMounted check make sure that setState will not execute when component is UnMounted.

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

Successfully merging this pull request may close these issues.

1 participant