티스토리 뷰
안녕하세요 강정호입니다.
오늘은 리액트 Tab navigation에 대해서 알아보겠습니다.
TabNavigation.js
import React from "react";
import { createAppContainer } from "react-navigation";
import { View } from "react-native";
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import Home from "../screens/Home";
import Notifications from "../screens/Notifications";
import Profile from "../screens/Profile";
import Search from "../screens/Search";
const Tab = createBottomTabNavigator();
export default () => {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Profile" component={Profile} />
<Tab.Screen
name="Add"
component={View}
listeners={{
tabPress: e => {
// Prevent default action
e.preventDefault();
console.log("Add");
},
}}
/>
<Tab.Screen name="Search" component={Search} />
<Tab.Screen name="Notifications" component={Notifications} />
</Tab.Navigator>
</NavigationContainer>
);
};
//export default createAppContainer(TabNavigation);
Tab navigation 공식 문서
reactnavigation.org/docs/bottom-tab-navigator/
createBottomTabNavigator | React Navigation
A simple tab bar on the bottom of the screen that lets you switch between different routes. Routes are lazily initialized -- their screen components are not mounted until they are first focused.
reactnavigation.org
Tab navigation이란?
스마트폰 하단에서 클릭하여 화면 전환을 할 수 있도록 하는 탭 바
createBottomTabNavigator
이 함수를 사용하면 BottomTabNavigator 컴포넌트를 생성한다.
Tab.Navigator와 Tab.Screen
Tab의 Tab.Navigator 컴포넌트를 생성하고 그 안에 여러개의 Tab.Screen을 넣어준다.
그래서 Navigator가 Screen을 감싸고 있는 형태로 만들어 준다.
아래 공식문서에서도 이와 같이 사용하는 방법을 예시로 보여준다.
reactnavigation.org/docs/screen-options-resolution
Screen options with nested navigators | React Navigation
In this document we'll explain how screen options work when there are multiple navigators. It's important to understand this so that you put your options in the correct place and can properly configure your navigators. If you put them in the wrong place, a
reactnavigation.org
tabPress란?
유저가 현재 화면의 탭 버튼을 클릭 했을 때 활성화 되는 이벤트입니다. tabPress는 기본적인 기능으로는 아래와 같은 기능이 있습니다.
- 탭이 포커스 되어 있지 않다면, 탭을 누르는 것은 탭을 포커스 맞추게 함.
- 탭이 포커스 되어 있다면, 스크롤 뷰 화면일 경우 맨 상단으로 올리는 useScrollTop을 사용할 수 있다. 스택 화면일 경우에는 맨위에 있는 화면을 띄워주는 역할을 한다.
reactnavigation.org/docs/bottom-tab-navigator/#tabpress
createBottomTabNavigator | React Navigation
A simple tab bar on the bottom of the screen that lets you switch between different routes. Routes are lazily initialized -- their screen components are not mounted until they are first focused.
reactnavigation.org
'프로젝트' 카테고리의 다른 글
[인스타그램클론코딩] #11.4 Messages Navigation part One (StackNavigator) (0) | 2021.02.12 |
---|---|
[인스타그램클론코딩] #11.3 Photo Navigation (undefined 오류 찾기) (0) | 2021.02.07 |
[인스타그램클론코딩] #11.1 AuthNavigation (React Navigation) (0) | 2021.01.31 |
[인스타그램클론코딩] #10.6 AuthContext part One (useContext) (0) | 2021.01.30 |
[인스타그램클론코딩] #10.2 Preloading Cache (apollo-cache-persist) (0) | 2021.01.26 |
- Total
- Today
- Yesterday
- 열반스쿨기초반
- Spring boot
- 유즈케이스
- push_back
- resize
- 깃허브
- github
- 월급쟁이부자들
- 재테크공부
- front
- 깃
- Use case
- 파라메터
- 항해플러스후기
- pop_back
- 인셉션
- GIT
- 항해플러스백엔드
- ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
- 내년은 빡세게!!
- 부동산공부
- 폭포수
- Inception
- 관계대수
- 월부닷컴
- docker
- 개발자 회고
- 2023년
- 도커
- 항해솔직후기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |