-
Notifications
You must be signed in to change notification settings - Fork 54
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
initialPage not working #4
Comments
Here is a simple workaround:
I still think that it would be better to do the datasource cloning in componentWillReceiveProps instead of doing it in render(). I tried to move it and it worked if I also removed the creation of a new dataSource in onLayout(). Why do you need a new datasource if layout changes? |
@MichaelSWE this is the exactly the problem I came across. This is the PR to resolve it |
Great, thank you @ksti. |
I still get this issue, to solve it ... i have done the following: I added the initialListSize property to the ListView in the render method
In the same render method i adjusted the render as following:
This will make sure the size of list view is is always similar to the number of pages. and avoid render errors. |
I don't know if this is related to this issue, but on react-native-gallery when I set initialPage=13, it seems it actually displatys the 11th image. Up to the 11th image initialPage works fine, then it seems any page higher than 11 displays the 11th image(/page). |
@slorber how did you solve the problem?I'm confused with this for serveral days! Any ideals? |
@budiga unfortunatly I did not solve it yet but will certainly have to look for a solution soon. Please share if you find a solution (or alternative lib to use) |
@slorber thank you for your reply.I'm new for the react native.I hope you can share your solution if you find it.Thanks again. |
@slorber @budiga you can try it? Maybe we need to export a prop listViewProps. also you can move to @mjebrini 's answer #4 (comment) |
@ksti ok, I will give it a try later.I find when I swipper over 12 images,the error will appears. |
Any updated? |
I'm going to test that workaroud asap when i get back to my app. Will have to check if it's possible because i'm using image gallery, not this project directly |
I am also using the Gallery. And, I have tried if you set the initialListSize to the length of your assets, app will run out of memory when you are trying to display hundreds or thousands of images. |
I think the best solution is to replace the ListView with FlatList, and use the ScrollToIndex api to navigate to the exact item. However, it might be a huge code refactoring. |
For my usecase it's max 30 images so it may work fine @gameboyVito I tested this and it does not work for me, is it what you suggested? I don't think initialListSize is forwarded to the ListView
|
If you take a look at the source code of Gallery, you will find out the
Like @budiga said. |
Should permit to solve temporarily this issue: ldn0x7dc#4 (comment)
Thanks it seems to work when modifying the sources. I've made a PR #9 |
If we move to FlatList, there is something similar wrong in setting initial pasition/page/item as well. Check at: If we scroll to some item without animation that is outside initial windowSize it's not rendered. |
I think that the datasource cloning needs to move into componentWillReceiveProps so this.pageCount will be updated before the first scrollToPage-call.
But it seems that height and width are needed before cloning (why?). Width and height are achieved at onLayout() which I believe happens after receiveProps.
Here is the problem:
https://github.com/ldn0x7dc/react-native-view-pager/blob/master/library/ViewPager.js#L248
validPage() resets page to 0 because pageCount is 0 at this stage.
This problem affects Gallery as well:
ldn0x7dc/react-native-gallery#18
The text was updated successfully, but these errors were encountered: