leecade / leecade/react-native-swiper

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

Open
#735 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.5.13
  • react-native v0.53.0
  • react-navigation v1.1.2

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.

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 by reproducing the provided TabNavigator example with react-native-swiper 1.5.13, react-native 0.53.0, and react-navigation 1.1.2 on Android. Compare rendering in the first tab with later tabs and inspect the interaction between the Swiper component and TabNavigator. Done means the Swiper contents render in the first tab without relying on delayed rendering.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.