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

initialPage not working in Android (production only) #851

Open
gtwilliams03 opened this issue Aug 8, 2024 · 3 comments
Open

initialPage not working in Android (production only) #851

gtwilliams03 opened this issue Aug 8, 2024 · 3 comments

Comments

@gtwilliams03
Copy link

gtwilliams03 commented Aug 8, 2024

Environment

react-native 0.74.5 (new architecture)
expo 51.0.25 (managed)
react-native-pager-view 6.3.0 (expo will not run if I use a higher version because I get the Invariant Violation: requireNativeComponent: "LEGACY_RNCViewPager" was not found in the UIManager error).

Description

I am experiencing an odd issue. I am using this package as a photo gallery viewer. I show a number of thumbnail images. When you press on one of the thumbnails, I set the currentIndex variable (which is passed into the initialPage prop of the AnimatedPagerView component). This works fine in the iOS simulator, iOS devices in production, Android simulator in Android Studio, but in Android production devices, no matter what thumbnail I press, the currentIndex variable stays at 0 and loads the first image.

Reproducible Demo

<AnimatedPagerView style={s.photoContainer}
    initialPage={currentIndex}
    pageMargin={0}
    offscreenPageLimit={2}
    onPageSelected={e => handleViewPagerChange(e.nativeEvent.position)}>
    {lightboxImages && lightboxImages.map(i =>
    <Image key={i.key}
        source={{ uri: i.fullImageUrl }} 
        containerStyle={{ width: '100%', height: '100%' }}
        PlaceholderContent={<ActivityIndicator size='large' />}
        resizeMethod='scale' resizeMode='contain' />
    )}
</AnimatedPagerView>
@gtwilliams03
Copy link
Author

I tried to update the photo gallery component to include a useEffect to call setPage when the gallery is open (isOpen === true) and the currentIndex changes. I also used a setTimeout to try and delay the setPage until the Modal opens with the PagerView in it:

  useEffect(() => {
      if (isOpen && _pagerRef?.current) {            
          setTimeout(() => _pagerRef.current.setPage(currentImage), 450)
      }
  }, [isOpen, currentImage])

In both cases, Android in production originally scrolls to the new index, but then reverts to index 0. I can't figure it out:

IMG_6716-480p.mov

@MrRefactor
Copy link
Collaborator

@gtwilliams03
Copy link
Author

@MrRefactor Thank you for your note - like I mentioned above, expo will not run if I use a higher version because I get the Invariant Violation: requireNativeComponent: "LEGACY_RNCViewPager" was not found in the UIManager error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants