taiki-t's diary

React Native, Rails そして雑多な記録: The world is waiting for you to give it a meaning.

React Native Tab View with default index to 1

When Using React Native Tav View with defalut index to 1, I happened to face a strange behaviour; automatically swipes to index 0 sometimes when opening the scene. So what I did was to set initialLayout and it fixed it.

Like this:

const initialLayout = {
  height: 0,
  width: Dimensions.get('window').width,
};

render () {
   <TabViewAnimated
       // other props
       initialLayout={initialLayout}
   />
}

github.com


React Native Tab Viewの初期indexを1に指定して使ったところ、画面を開いたとき時々勝手にindex 0の画面にスクロールされることがあった。 initialLayoutを設定したら解決した。