0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ReactNativeでTabにStackを入れ子にする

Last updated at Posted at 2018-10-24

react-navigationでTabにStackを入れ子にしたい。

準備

npm install --save react-navigation
npm install

イメージ

動画にしたかったけどうまく録画できず・・・。

スクリーンショット 2018-10-25 7.08.46.png

実装

レイアウト?自体はそんなに難しくはない。Stackを作って、Tabでページとして指定するだけ。

App.js
import React from 'react';
import { Text, View, Button } from 'react-native';
import { createBottomTabNavigator, createStackNavigator } from 'react-navigation';
import { Entypo, Ionicons, Feather, FontAwesome } from '@expo/vector-icons';

//Home
class HomeScreen extends React.Component{
  render(){
    return (
      <View style={{flex:1, alignItems: 'center', justifyContent: 'center'}}>
        <Text>Home</Text>
        <Button
          title='Link to About'
          onPress={() => this.props.navigation.navigate('About')}
        />
      </View>
    );
  }
}

//About
class AboutScreen extends React.Component{
  render() {
    return (
      <View style={{flex:1, alignItems: 'center', justifyContent: 'center'}}>
        <Text>About</Text>
      </View>
    );
  }
}

//Setting
class SettingsScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Settings!</Text>
      </View>
    );
  }
}

//Stack
const RootStack = createStackNavigator(
  {
    Home: {
      screen: HomeScreen,
    },
    About: AboutScreen,
  }
  ,
  {
    initialRouteName: 'Home',
  }
);

//tab icon設定 
RootStack.navigationOptions = {
  tabBarIcon: ({ tintColor }) => <Entypo size={24} name="home" color={tintColor} />,
}

SettingsScreen.navigationOptions = {
  tabBarIcon: ({ tintColor }) => <Ionicons size={24} name="md-settings" color={tintColor} />,
}

//Tab
export default createBottomTabNavigator({
  Home: RootStack,
  Settings: SettingsScreen,
});

今後の課題

  • データ連携関連全般。特にReduxをどう統合すればいいのだろうか。調べて随時更新します。
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?