LoginSignup
1
1

More than 5 years have passed since last update.

【React Native】react-navigationでbottomTabメニューのdefaultタブを設定する

Last updated at Posted at 2018-06-29

ライブラリ

やりたいこと

以下の画面構成のとき、MAIN画面にナビゲートされたらTAB 2がinitialで表示されるように

  • LOGIN
  • MAIN
    • TAB 1
    • TAB 2
    • TAB 3

どうやるか

initialRouteNamecreateStackNavigator()の第二引数のオブジェクトに設定する

Navigator.js
import Main from './Main';

const Navigator = createStackNavigator(
  {
    'LOGIN': {
      screen: Login,
    },
    'MAIN': {
      screen: Main,
    },
  },
);
export default Navigator;
Main.js

const Main = createBottomTabNavigator({
  'TAB 1': {
    screen: tab1screen,
    navigationOptions: {
      tabBarLabel: 'TAB 1',
    },
  },
  'TAB 2': {
    screen: tab2screen,
    navigationOptions: {
      tabBarLabel: 'TAB 2',
    },
  },
  'TAB 3': {
    screen: tab3screen,
    navigationOptions: {
      tabBarLabel: 'TAB 3',
    },
  },
},{
  // このoptionはBottomTab共通で適用される
  tabBarPosition: 'bottom',
  initialRouteName: 'TAB 2',// ← ココ
  tabBarOptions: {
    activeTintColor: 'red',
    labelStyle: {
      fontSize: 9,
    },
    style: {
      backgroundColor: COLORS.WHITE,
    },
  }
}
export default Main;

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1