leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.42k stars 2.34k forks source link

ViewPagerAndroid and dynamic swiper content #675

Open vvusts opened 6 years ago

vvusts commented 6 years ago

I use swiper datasource that can be dynamic.

When I load swiper with 5 items and reduce it to 2 items and then increase to 3 items only two items are rendered 3rd it blank screen.

This scenario works perfect on ios. This happens only on android.

I dig a bit and found that ViewPagerAndroid component is actually problem here. I discovered that if I put key={Math.random()} fix the issue but then I loose animation between items. I tried to put key={this.children.length}and this doesn't work.

Do you have some suggestion on how to fix this on android to work and to have animations? I am in trouble as main part of the app is based on this component.

One more thing. Swiper is part of modal component. When issue occurs and I dismiss modal view and bring it back again it load 3 items correctly. I don't know what happen there but seems like some restart of swiper. Maybe I can restart swiper somehow but don't know how to do it.

Thanks

vvusts commented 6 years ago

Actually I am in hell of dead line so I made one change that actually fix this. But I need some of authors to confirm me that this will not cause some other issues.

What do you think is this valid solution?

appielife commented 6 years ago

Only one constant image is getting loaded . Any idea on how to change that

SSTPIERRE2 commented 6 years ago

Rule of thumb for rendering dynamic content:

Long form answer: My team and I at work are using this package for something similar, rendering a dynamic number of views form some survey question data. This first issue we ran into was giving each view a unique key as we mapped through the data (simple array map function call in render method of the swiper component), so make sure you don't just use the index here (we used the unique question names).

Note on ViewPagerAndroid and swiper "restarting"

What I did to fix that last bullet point