React-native-swiper: Not refresh current page at update

Created on 10 Dec 2019  路  4Comments  路  Source: leecade/react-native-swiper

Which OS ?

Android

Version

Which versions are you using:

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

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

Most helpful comment

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

All 4 comments

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

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

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

any update on this???

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agzuniverse picture agzuniverse  路  3Comments

ruben-kasaz picture ruben-kasaz  路  3Comments

Liqiankun picture Liqiankun  路  3Comments

kliuj picture kliuj  路  3Comments

JonasOmdal picture JonasOmdal  路  3Comments