React-native-pager-view: initial page render question

Created on 22 Jul 2021  路  12Comments  路  Source: callstack/react-native-pager-view

Ask your Question

when PagerView rendered,
even though the initialPage={1} is selected, Page 0 is displayed first then Page 1 is displayed.
i use Android simulator. help!

bug android

Most helpful comment

still not working for me

All 12 comments

Hello 馃憢
Thank you for reporting an issue. How about the ios ?

Hello 馃憢
Thank you for reporting an issue. How about the ios ?

I haven't tried ios.

I am not able to reproduce it, hence I am closing this issue

i think same problems in android ..

https://www.gitmemory.com/issue/react-native-community/react-native-viewpager/101/553832372
https://github.com/callstack/react-native-pager-view/issues/190
https://github.com/callstack/react-native-pager-view/issues/101

Even if i use 'ViewPagerRef.current.setPageWithoutAnimation(idx)',
always initialPage0 first appear.

<ViewPager
        ref={ViewPagerRef}
        initialPage={1}
        onPageSelected={e => {
          console.log(e.nativeEvent.position);
        }}>
        <View key="1">
          <aPager />
        </View>
        <View key="2">
          <bPager />
        </View>
</ViewPager>

log says 0 then 1

Will this fix be on a new release version soon?

still not working for me

still not working for me

same to you

Maybe it's about using state to store the initialIndex? I found that if I use state to store the index, pager will select page 0 first then select page 3

// BasicPagerViewExample.js
export function BasicPagerViewExample() {
  const { ref, ...navigationPanel } = useNavigationPanel();
  const [index, setIndex] = useState(0);
  useEffect(() => {
    setIndex(3)
  }, []);

  return (
    <SafeAreaView style={styles.container}>
      <AnimatedPagerView
        //@ts-ignore
        testID="pager-view"
        ref={ref}
        style={styles.PagerView}
        initialPage={index}
       .......

but if I set initialPage like this: initialPage={3} or using useLayoutEffect to set the index, pager will set to third page on first rendering

https://user-images.githubusercontent.com/8035517/128470055-7ff54522-963f-4dd0-ac58-d3bb9a1ad5b8.mp4

Why do you store the initial index in state ? It is incorrect usage. Please take a look on the example https://github.com/callstack/react-native-pager-view/blob/master/example/src/BasicPagerViewExample.tsx

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thecodecafe picture thecodecafe  路  4Comments

Andarius picture Andarius  路  5Comments

nnajiabraham picture nnajiabraham  路  6Comments

hengkx picture hengkx  路  8Comments

troZee picture troZee  路  3Comments