바르고 뜨겁게
ReactNative - Tab Navigation 본문
App.js
export default class App extends React.Component {
render() {
<TabNavigation />
}
}
-
navigation/TabNavigation.js
import React from "react";
import { Platform } from "react-native";
import { createBottomTabNavigator, createAppContainer } from "react-navigation";
import MoviesScreen from "../screens/Movies";
import TVScreen from "../screens/TV";
import SearchScreen from "../screens/Search";
import { BG_COLOR } from "../constants/Colors";
import TabBarIcon from "../components/TabBarIcon";
const TabNavigation = createBottomTabNavigator(
{
Movies: { screen: MoviesScreen, navigationOptions: {
tabBarIcon: ({focused}) => <TabBarIcon focused={focused} name={Platform.OS === "ios" ? "ios-film" : "md-film"}/>
}} ,
TV: { screen: TVScreen, navigationOptions: {
tabBarIcon: ({focused}) => <TabBarIcon focused={focused} name={Platform.OS === "ios" ? "ios-tv" : "md-tv"}/>
}} ,
Search: { screen: SearchScreen, navigationOptions: {
tabBarIcon: ({focused}) => <TabBarIcon focused={focused} name={Platform.OS === "ios" ? "ios-search" : "md-search"}/>
}}
},
{
tabBarOptions: {
showLabel: false,
style: {
backgroundColor: BG_COLOR
}
}
}
);
export default createAppContainer(TabNavigation);
-
components/TabBarIcon.js
import React from "react";
import PropTypes from "prop-types";
import { Ionicons } from "@expo/vector-icons";
import { ACTIVE_COLOR, INACTIVE_COLOR } from "../constants/Colors";
const TabBarIcon = ({name, focused}) => (
<Ionicons
size={26}
name={name}
color={focused ? ACTIVE_COLOR : INACTIVE_COLOR}
/>
);
TabBarIcon.propTypes = {
name: PropTypes.string.isRequired,
focused: PropTypes.bool.isRequired
}
export default TabBarIcon;
'자바스크립트 > React Native' 카테고리의 다른 글
ReactNative - 슬라이드 배너 (0) | 2019.06.21 |
---|---|
ReactNative - CSS 두가지 방법 (0) | 2019.06.19 |
ReactNative - 화면이동 버튼 TouchableOpacity (1) | 2019.06.18 |
ReactNative - Assets PreLoad 세팅 (0) | 2019.06.18 |
ReactNative - 리액트란? + 환경 설정 (0) | 2019.06.18 |
Comments