leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.37k stars 2.35k forks source link

Not refresh current page at update #1120

Open psycura opened 4 years ago

psycura commented 4 years ago

Which OS ?

Android

Version

Which versions are you using:

Expected behaviour

If index prop is changed, current swipe-page should be scrolled to the updated page

Actual behaviour

On initial load Swiper is behave ok, display page that should be displayed by index. When index updated Swiper doesn't scroll to the new position, despite of fact, that he is receive new offset in the Swiper components

How to reproduce it>

To help us, please fork this component, modify one example in examples folder to reproduce your issue and include link here.

import React, { useMemo, useRef, useState } from 'react';
import Swiper from 'react-native-swiper'
import { View, Text, Button } from 'react-native';

const ChannelScreen = () => {
  const ref = useRef ( null )
  const [ index, setIndex ] = useState ( 0 )

  const channelsList = useMemo ( () => [ '1', '2', '3', '4' ], [] )

  return (
    <View style={styles.wrapper}>
      <Button
        title="Press me"
        onPress={() => setIndex ( index + 1 )}
      />
      <Swiper loop={false}
              ref={ref}
              showsButtons={false}
              showsPagination={false}
              index={index}
      >
        {
          channelsList.map ( ( ch ) => {
            return (
              <View style={styles.slide1}>
                <Text style={styles.text}>{ch}</Text>
              </View>
            )
          } )
        }
      </Swiper>
    </View>
  );

};

export default ChannelScreen

const styles = {
  wrapper: {
    flex: 1,
  },
  slide1: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#9DD6EB'
  },
  slide2: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#97CAE5'
  },
  slide3: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#92BBD9'
  },
  text: {
    color: '#fff',
    fontSize: 30,
    fontWeight: 'bold'
  }
}

-

Steps to reproduce

Here is very basic example. I have array of channels. On screen load, i define index based on some parameters, that receive from outside. On Initial mount, Swiper works ok and display right page based on index. If i press button, to change index (emulation of index update), i want that Swiper will display new Page based on index. But this isn`t happen

Druidsnake commented 4 years ago

i got same behavior, using scrollby() method change the index props but dont change the actual swiper view.

vksgautam1 commented 4 years ago

Which versions are you using:

react-native-swiper v1.6.0-nightly.5 react-native v0.61.5

issue coming for ios only to me

hansol775 commented 4 years ago

same issue. has not it been resolved yet? only android issue.

thanhluantl2304 commented 3 years ago

any update on this???