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

fix initState calc the offset #1301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

huhuang03
Copy link

I think you forget the the loop=true in initState calc the offset

The example:

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

export interface TestSwiperViewProps {}

var styles = {
  wrapper: {},
  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',
  },
};

const TestSwiperView: React.FC<TestSwiperViewProps> = props => {
  const [imgs, setImgs] = useState(['1', '2', '3']);

  return (
    <View
      style={{
        height: '100%',
      }}>
      <Button
        title={'setState'}
        onPress={() => {
          setImgs([...imgs]);
        }}
      />
      <Swiper style={styles.wrapper} showsButtons={false} loop={false}>
        {imgs.map(img => {
          return (
            <View testID="Hello" style={styles.slide1}>
              <Text style={styles.text}>{img}</Text>
            </View>
          );
        })}
      </Swiper>
    </View>
  );
};

export default TestSwiperView;

Reproduce step:

  1. scroll to page 2.
  2. click the top button.

@swzift
Copy link

swzift commented Jul 13, 2023

@huhuang03 bro,you saved my life

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

Successfully merging this pull request may close these issues.

None yet

2 participants