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

Fix ViewPager being stuck in some scenarios #15376

Closed
wants to merge 1 commit into from
Closed

Conversation

satya164
Copy link
Contributor

@satya164 satya164 commented Aug 4, 2017

In some scenarios, the view pager gets stuck in and it's not possible to update the pages. I did some digging and found the following.

In native ViewPager, the onAttachedToWindow method gets called on start, which sets a variable called mFirstLayout to true. Then onLayout method gets called, which sets mFirstLayout to false, since first layout has occurred now. But then onAttachedToWindow method gets called again for some reason which resets mFirstLayout to true.

This makes the ViewPager stuck since mFirstLayout variable never updates again, and to be able to animate the pager, the native component expects it to be false.

I also discovered that @rauliyohmc arrived at the same conclusions here, which describes it in more detail -
expo/ex-navigation#415 (comment)

This PR is a hacky attempt to prevent onAttachedToWindow being called again after first layout since I am unsure about the correct fix.

Fixes #13463

cc @astreet

In some scenarios, the view pager gets stuck in and it's not possible to update the pages. I did some digging and found the following.

In native `ViewPager`, the `onAttachedToWindow` method gets called on start, which sets a variable called `mFirstLayout` to `true`. Then `onLayout` method gets called, which sets `mFirstLayout` to `false`, since first layout has occurred now. But then `onAttachedToWindow` method gets called again for some reason which resets `mFirstLayout` to `true`.

This makes the `ViewPager` stuck since `mFirstLayout` variable never updates again, and to be able to animate the pager, the native component expects it to be `false`.

I also discovered that @rauliyohmc arrived at the same conclusions here, which describes it in more detail -
 expo/ex-navigation#415 (comment)

This PR is a hacky attempt to prevent `onAttachedToWindow` being called again after first layout since I am unsure about the correct fix.

Fixes #13463

cc @astreet
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: review-needed labels Aug 4, 2017
@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Aug 8, 2017
@facebook-github-bot
Copy link
Contributor

@mmmulani has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ayc1
Copy link
Contributor

ayc1 commented Aug 16, 2017

This doesn't seem like a safe change. Why is this only a problem in React Native if it all has to do with the native android ViewPager?

@satya164
Copy link
Contributor Author

Why is this only a problem in React Native if it all has to do with the native android ViewPager

It's a problem with React Native's ViewPager wrapper. Not the native Android component.

@astreet
Copy link
Contributor

astreet commented Aug 21, 2017

I'm not working on RN anymore so I've got limited time I can give to help out, but I saw this go by internally and swallowing onAttachedToWindow isn't safe (or at least not a good idea).

This issue needs more digging to figure out why it only affects RN and not standard Android (e.g. all the explanation above only references things in ViewPager) -- there must be something weird or unexpected RN is doing that's manifesting itself this way.

@ruiaraujo
Copy link
Contributor

I also attempted fixing this in another way by having another layout pass.

#14867

It was inspired by a similar fix in the Switch component.

@facebook-github-bot
Copy link
Contributor

@satya164 I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@satya164
Copy link
Contributor Author

satya164 commented Oct 8, 2017

Closing in favor of #14867 which looks more reasonable.

@satya164 satya164 closed this Oct 8, 2017
@satya164 satya164 deleted the satya164-patch-1 branch October 8, 2017 17:13
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. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React Native v0.43 ViewPagerAndroid work not well when detached then attach
7 participants