leecade / react-native-swiper

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

Couldn't work well with newest react-navigation's TabNavigator #735

Open fondoger opened 6 years ago

fondoger commented 6 years ago

Which OS ?

Android

Version

Which versions are you using:

I found that react-native-swiper couldn't work well with newest react-navigation(v1.1.2). We can't see the contents of swiper if we put the swiper in the first tab of react-navigation's TabNavigator, but everything is ok if we put the swiper in any other tabs except the first tab.

Code(make sure your react-navigation's version is above 1.0.0):

import React, { Component } from 'react';
import { Text } from 'react-native';
import { TabNavigator } from 'react-navigation'; // 1.1.2
import Swiper from 'react-native-swiper'; // 1.5.13
class Tab extends Component {
  render() {
    return (
      <Swiper>
        <Text>Hello, React</Text>
        <Text>Hello, Native</Text>
        <Text>Hello, Swiper</Text>
      </Swiper>
    )
  }
}
const App = TabNavigator({
  First: {
    screen: Tab,
    navigationOptions: {
      tabBarLabel: 'TabA',
    },
  },
  Second: {
    screen: Tab, 
    navigationOptions: {
      tabBarLabel: 'TabB',
    },
  },
  Thrid: {
    screen: Tab, 
    navigationOptions: {
      tabBarLabel: 'TabC',
    },
  },
})
export default App;

Screenshots:

wechat image_20180225174507 Can't see contents of swiper in the first tab

wechat image_20180225174513

Update

A solution is to delay the rendering of swiper. Below is the code. But I believe this is a bug, hope to fix it.

import React, { Component } from 'react';
import { Text } from 'react-native';
import { TabNavigator } from 'react-navigation'; // 1.1.2
import Swiper from 'react-native-swiper'; // 1.5.13
class Tab extends Component {
  constructor(props) {
    super(props);
    this.state = {
      showSwiper: false,
    }
  }
  componentDidMount() {
    // Delay ten  millisecond will solve this.
    setTimeout(()=>{
      showSwiper: true,
    }, 10);
  }
  render() {
    return (
      <Swiper>
        <Text>Hello, React</Text>
        <Text>Hello, Native</Text>
        <Text>Hello, Swiper</Text>
      </Swiper>
    )
  }
}
const App = TabNavigator({
  First: {
    screen: Tab,
    navigationOptions: {
      tabBarLabel: 'TabA',
    },
  },
  Second: {
    screen: Tab, 
    navigationOptions: {
      tabBarLabel: 'TabB',
    },
  },
  Thrid: {
    screen: Tab, 
    navigationOptions: {
      tabBarLabel: 'TabC',
    },
  },
})
export default App;

Temporarily Solution

Temporarily delaying the rendering of swiper by setTimeout() will solve this.

fondoger commented 6 years ago

This is so wired.

MariusMeiners commented 6 years ago

seems like more of a problem in react-navigation to me ?

AllenCai1991 commented 6 years ago

me too

idlework commented 6 years ago

Maybe this help for your information and debugging; the same occurs when you put the Swiper component in a react-native Modal