하단에 메뉴바를 사용하기 위해 패키지 설치 및 gradle 의존성 추가가 필요하다(주석처리된 내용 참조).
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { NavigationContainer } from "@react-navigation/native";
import React from "react";
import Icon from "react-native-vector-icons/Ionicons";
import BaseScreen from "./src/screens/BaseScreen";
import HomeScreen from "./src/screens/HomeScreen";
import SettingScreen from "./src/screens/SettingScreen";
/*
npm install react-native-gesture-handler
npm install @react-navigation/native
npm install @react-navigation/bottom-tabs
npm install react-native-safe-area-context
npm install react-native-screens
npm install react-native-vector-icons
<< android -> app -> src -> build.gradle >>
project.ext.vectoricons = [
iconFontNames: [ 'Ionicons.ttf', 'FontAwesome.ttf' ]
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
*/
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator
screenOptions = {
({route}) => (
{tabBarIcon: ({focused, color, size}) => {
let iconName;
if (route.name === "메인") {
iconName = focused ? "cafe" : "cafe-outline";
} else if (route.name === "통계") {
iconName = focused ? "podium" : "podium-outline";
} else if (route.name === "설정") {
iconName = focused ? "settings" : "settings-outline";
}
return <Icon name={iconName} size={size} color={color}/>
},
})}
>
<Tab.Screen name="메인" component={HomeScreen} />
<Tab.Screen name="통계" component={BaseScreen} />
<Tab.Screen name="설정" component={SettingScreen} />
</Tab.Navigator>
</NavigationContainer>
);
};
'Study > React' 카테고리의 다른 글
[React Native] axios를 사용하여 spring boot로 비동기 통신 하기 (0) | 2022.03.10 |
---|---|
[React Native] 다른 화면으로 전환하기 (0) | 2022.03.09 |
[React Native] useContext (0) | 2022.03.09 |
[React Native] useMemo, useCallback (0) | 2022.03.08 |
[React Native] useEffect (0) | 2022.03.08 |