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

[Android] ViewPager child view didn't get draw #11829

Closed
tlcheah2 opened this issue Jan 11, 2017 · 6 comments
Closed

[Android] ViewPager child view didn't get draw #11829

tlcheah2 opened this issue Jan 11, 2017 · 6 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@tlcheah2
Copy link

Description

I created a native UI component, which is a RelativeLayout contain a ViewPager. It instantiate two item view, which is ItemView0 and ItemView1.

However, when I performed scrolling to ItemView1 on ViewPager, the correct behaviour of the ViewPager should be draw the next item, which is ItemView2.

Instead, from the debugging I did, the instantiateItem() from PagerAdapter did called and view is inflated. However, it did not perform dispatchDraw() method for ItemView2.

Hopefully I am clear with the issue. I have also posted on StackOverflow. http://stackoverflow.com/questions/41571053/react-native-custom-native-viewpager-unable-to-addview

Thanks.

Reproduction

Here is the link for the sample project of reproduction.
https://github.com/tlcheah2/test

Solution

Firstly, I couldn't use ViewPagerAndroid as what it contain inside is quite heavy. Thus, I decided to move some of components to native. There I encountered this issue.

Secondly, I am not sure this is a bug or what. If anyone can provide some explaination, it would be really helpful and I appreciate it.

Additional Information

  • React Native version: RN 0.40
  • Platform: Android
  • Operating System: MacOS
@bruceluliang
Copy link

pls see this issue
#8348

@monumentyusuf
Copy link

monumentyusuf commented Mar 29, 2017

Im in trouble with the same issue. Im running same pager and adapter classes in an AppCompatActivity and it works but not in ReactActivity.
Did you find any solution for that @tlcheah2 ?

@tlcheah2
Copy link
Author

@monumentyusuf I found out 2 solution for this. One of it you can use viewpager.setOffScreenPageLimit() to your viewpager. As this is how ReactViewPager did it. Refer to the picture below
screen shot 2017-03-30 at 11 31 29 am

Else you can measure and relayout your View when requestLayout called.

I updated the solution to my test project and you can get it at the following commit.
tlcheah2/test@9a70c2b

Thank you.

@monumentyusuf
Copy link

Thanks a lot @tlcheah2 you saved my day :)

@Deallinker
Copy link

Thank you very much @tlcheah2 , but can you explain it why? I will appreciate you a lot.

@tlcheah2
Copy link
Author

Hi @Deallinker ,

screen shot 2017-08-12 at 4 57 12 pm

From the comment section of the code above in ReactViewPager, the problem is on the relayout. When we perform swipe on the ViewPager, ViewPager actually will relayout the view. However, it didn't behave this way and react native currently seem have limitation on re-layout the view on request..

That's why React Native are using viewpager.setOffScreenPageLimit() to render all your ViewPager child view in one time. If your viewpager child view is very heavy or you have a lot of child view, this will cause some performance issues but that is another topic.

Let me know what you think if you have different opinion and happy coding.

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants