meliorence / react-native-image-gallery

Pure JavaScript image gallery component for iOS and Android with high-performance and native feeling in mind

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android Breaks When initialPage Index > 10

geirman opened this issue · comments

Related to issue #9
Affected version: v2.1.5
Affects Android Only
Work around: downgraded to v2.1.4

Issue Summary

With v2.1.5 installed, tapping any thumbnail greater than 10 causes unexpected behavior ranging from the wrong image being displayed to loss of swipe and pinch-to-zoom functionality.

Issue Details

  1. When tapping thumbnails on a Flatlist Grid when index <= 10, everything works as expected. The correct image appears full screen in the gallery, pinch-to-zoom works, swiping works. All is good.
  2. When index === 11, the 10th image flashes but the 11th is eventually shown. Both pinch-to-zoom and swiping work as expected.
  3. When index ===12, the 10th image flashes, 11th image is shown. Both pinch-to-zoom and slider sometimes work, sometimes not. It's inconsistent. When working, the 12th image immediately appears on swipe initiation (without animation).
  4. When index >=13, the 10th image flashes, 11th image is shown. Neither pinch-to-zoom nor slider work (ever!).

Here's a video demonstrating the issue...
http://recordit.co/pSRuvmcX04

More Info which may or may not be helpful

While troubleshooting this, I verified that the offsetX calculation is correct in react-native-image-gallery#225

I have the same issue. You can try this by adding flatListProps. It works for me
#85

@pogofdev I have submitted this solution (85), but even if it works perfect on iOS I am not able to make it works perfect on Android when is landscape.

<Gallery
style={{ flex: 1, backgroundColor: 'black' }}
images={this.state.ImageList}
initialPage={this.state.index}
flatListProps={{ initialNumToRender: this.state.index, initialScrollIndex: this.state.index, getItemLayout: (data, index) => ({ length: Dimensions.get('screen').width, offset: Dimensions.get('screen').width * index, index }) }}
/>

this is working in my case

@AkshayItaliya
I prefer this prop and it works for me :
flatListProps={{ initialScrollIndex: this.state.index, getItemLayout: (data, index) => ({ length: Dimensions.get('screen').width, offset: Dimensions.get('screen').width * index, index }) }}

I think that setting initialNumToRender is a bit too violent for performance.

Thank you @AkshayItaliya and @emmguyot-adscom. Both solutions worked great for me!