leecade / leecade/react-native-swiper

Not refresh current page at update

Open
#1,120 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.5k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Swiper component and the example in the examples folder, using the supplied Android reproduction to compare initial index handling with later index updates. Confirm that changing the index scrolls to the corresponding page while preserving the initial-load behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.