leecade / react-native-swiper

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

Push new view and come back to the swiper make troubles (wix/react-native-navigation) #757

Open zagoa opened 6 years ago

zagoa commented 6 years ago

Which OS ?

Android

Version

Problem

I use my swiper to do something like Snapchat. I also use wix/React-native-navigation. But in on of my children of the swiper I have a button. This button can push a new view, this is all right ( I have a new view with some kind of things ). But when I press the back button of my android phone I go back to the swiper view BUT the swipe is broken, I need to do multiple swipes to scroll to another screen of the swiper.

Steps to reproduce

  1. Create a swiper with 2 screen
  2. In one of those screen add a button to push a new view (wix/react-native-navigation).
  3. Then do a pop() or press the back button of an android phone
ozberkctn commented 6 years ago

i have same problem. any solution ?

viotti commented 6 years ago

Are you using React Native Navigation v2? If so, I've traced the problem to v2.0.2247.

React Native Swiper works with React Native Navigation v2.0.2246, on Android, but not with v2.0.2247.

This commit, https://github.com/wix/react-native-navigation/pull/3094, seems to break with React Native Swiper.

viotti commented 6 years ago

This issue does not happen with React Native Navigation version 2.0.2274.

zagoa commented 6 years ago

So the problem come from react native navigation version 1. I use it because v2 is not released.

viotti commented 6 years ago

I did not try React Native Swiper with RNN version 1. But I had the same problem you described with version 2.0.2247. Today I updated RNN to 2.0.2274 and the swiper is behaving properly again.

Tritty commented 6 years ago

I have the same problem with v0.44.3RN and v1.1.245 RNN. And I CAN NOT update the RNN. Is there any way to resolve it? Thanks a lot.

Tritty commented 6 years ago

Hi,all!I've found the resolusion. Please check at Toggling tabs not working after poping back in Android. This work for me!

Here's my code.

constructor(props: Props) {
    super(props);
    this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
  }

public render(): JSX.Element {
    const { showTouch, flex } = this.state;
    return (
      <View>
            <Swiper
              style={{padding: 0, flex}}
              //other props
            >
              // your component
            </Swiper>
      </View>
    );

private onNavigatorEvent(event) {
    switch (event.id) {
      case "willAppear":
        this.setState({ flex: 1 });
        break;
      case "willDisappear":
        this.setState({ flex: 0 });
        break;
    }
  }
}

I hope it works for u too!

Tritty commented 6 years ago

You can alse user RNN's resetTo() to go back you original page. It works too.

zagoa commented 5 years ago

Great solution ! Thank you so much.