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

Allows RefreshControl to be mounted with refreshing = true #5745

Closed

Conversation

janicduplessis
Copy link
Contributor

RefreshControl did not start refreshing when refreshing was set to true initially. It also did not start refreshing on iOS when setting the prop from false to true without doing a pull to refresh gesture.

This was a pain in the ass to make work on iOS because UIRefreshControl seems super sensitive to when beginRefreshing can be called, for the initial render I need to call it in layoutSubviews. I also have to manually adjust the scrollview content offset when calling beginRefreshing. The code is a bit hacky but it was the only solution I found that was actually working.

Fixes #5716

RefreshControl did not start refreshing when refreshing was set to true initially. It also did not start refreshing on iOS when setting the prop from false to true without doing a pull to refresh gesture.

This was a pain in the ass to make work on iOS because UIRefreshControl seems super sensitive to when beginRefreshing can be called, for the initial render I need to call it in layoutSubviews. I also have to manually adjust the scrollview content offset when calling beginRefreshing. The code is pretty hacky but it was the only solution I found that was actually working.
@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @janicduplessis, @bestander and @lexs to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 4, 2016
@bestander
Copy link
Contributor

@TheBerg @nicklockwood ping

[scrollView setContentOffset:offset animated:NO];
[super beginRefreshing];
} else {
[UIView animateWithDuration:0.25
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use animateWithDuration here instead of setContentOffset:animated:YES ?

Copy link
Contributor

Choose a reason for hiding this comment

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

(I daresay there's a good reason, but please add a comment explaining why if there is)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason is that [super beginRefreshing] must be called after the animation is over otherwise it didn't work properly. I'll add a comment to explain this.

@facebook-github-bot
Copy link
Contributor

@janicduplessis updated the pull request.

@janicduplessis
Copy link
Contributor Author

Ok, I made the changes you suggested, now there is pretty much 1 comment per line of code, speaks to how weird the changes had to be to work :) Let me know if anything isn't clear.

@TheBerg
Copy link
Contributor

TheBerg commented Feb 7, 2016

This looks amazing! 👍

@nicklockwood
Copy link
Contributor

👍

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/567468353403947/int_phab to review.

@facebook-github-bot
Copy link
Contributor

@janicduplessis updated the pull request.

@janicduplessis
Copy link
Contributor Author

I made one last change to use scrollView.contentOffset if you want to include it before merging this.

@ghost ghost closed this in 3e1f1ea Feb 7, 2016
@nicklockwood
Copy link
Contributor

@janicduplessis too late, but thanks :-)

pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:
RefreshControl did not start refreshing when refreshing was set to true initially. It also did not start refreshing on iOS when setting the prop from false to true without doing a pull to refresh gesture.

This was a pain in the ass to make work on iOS because UIRefreshControl seems super sensitive to when beginRefreshing can be called, for the initial render I need to call it in layoutSubviews. I also have to manually adjust the scrollview content offset when calling beginRefreshing. The code is a bit hacky but it was the only solution I found that was actually working.

Fixes facebook#5716
Closes facebook#5745

Reviewed By: svcscm

Differential Revision: D2910716

Pulled By: nicklockwood

fb-gh-sync-id: d60e73bcfe8d86bb01249ba5f17e6a23c5a5aff6
@askday
Copy link

askday commented Mar 31, 2016

still have a problem,if you first setRefreshing true and then setRefreshing false,sometimes layoutSubviews function not be called, so the refreshcontrol would refresh for all

@sshymko
Copy link

sshymko commented Nov 1, 2016

Reproduced the original test case #5716 on versions from 0.34.1 to 0.37.0-rc.0 including.
Empty space is being rendered in place of RefreshControl's spinner icon.
@janicduplessis Was the fix not included into the aforementioned releases?

@jenskuhrjorgensen
Copy link

@janicduplessis @nicklockwood I just tested this in the official React-Native docs using the in-browser previews, and setting the initial refreshing value to true by changing
const [refreshing, setRefreshing] = React.useState(false);
to
const [refreshing, setRefreshing] = React.useState(true);
only seems to animate the refresh control on Android but not on iOS.

Did something break again, or was it never fixed?

@Gjeka
Copy link

Gjeka commented Jun 29, 2022

Any update on this issue? This is still occurring on iOS

@janicduplessis janicduplessis deleted the refresh-control-init branch June 29, 2022 21:03
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RefreshControl with refreshing=true does not show refreshing indicator on first render
9 participants