일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- 2022 플러터 안드로이드 스튜디오
- rxjava disposable
- 클래스
- 안드로이드 레트로핏 사용법
- jvm 작동 원리
- 서비스 쓰레드 차이
- jvm이란
- 안드로이드 유닛 테스트
- 큐 자바 코드
- 안드로이드 레트로핏 crud
- 객체
- ar vr 차이
- 2022 플러터 설치
- 자바 다형성
- ANR이란
- 안드로이드 라이선스
- android ar 개발
- rxjava hot observable
- android retrofit login
- 스택 자바 코드
- 플러터 설치 2022
- 안드로이드 os 구조
- 안드로이드 유닛 테스트 예시
- 서비스 vs 쓰레드
- 안드로이드 라이선스 종류
- 멤버변수
- Rxjava Observable
- rxjava cold observable
- 스택 큐 차이
- 안드로이드 유닛테스트란
- Today
- Total
나만을 위한 블로그
[React-Native] View란? 본문
https://reactnative.dev/docs/view
View · React Native
The most fundamental component for building a UI, View is a container that supports layout with flexbox, style, some touch handling, and accessibility controls. View maps directly to the native view equivalent on whatever platform React Native is running o
reactnative.dev
UI를 구축하는 가장 기본 컴포넌트. View는 flexbox, style, 일부 터치와 접근성 컨트롤을 갖춘 레이아웃을 지원하는 컨테이너다. View는 UIView, <div>, android.view 등 리액트 네이티브가 실행되는 플랫폼에 상관없이 네이티브 뷰에 해당하는 뷰에 직접 매핑된다
View는 다른 View 안에 중첩되도록 설계됐으며 모든 유형의 자식을 n개 가질 수 있다
https://reactnative.dev/docs/intro-react-native-components
Core Components and Native Components · React Native
React Native lets you compose app interfaces using Native Components. Conveniently, it comes with a set of these components for you to get started with right now—the Core Components!
reactnative.dev
안드로이드, iOS 개발에서 View는 UI의 기본 컴포넌트로 텍스트, 이미지를 표시하거나 유저 입력에 응답하는 데 쓸 수 있는 화면의 작은 직사각형 요소다. 텍스트 한 줄이나 버튼 같은 앱의 가장 작은 시각적 요소도 View의 일종이다. 일부 종류의 View는 다른 View를 포함할 수 있다. 모든 것이 View다
리액트 네이티브의 View는 리액트 네이티브의 가장 기본적인 컴포넌트다. 다른 컴포넌트들을 감싸고 배치하는 역할을 수행하고 css와 비슷한 스타일 속성들을 적용하거나 터치 이벤트 처리에 사용한다.
아래는 리액트 네이티브 문서의 View 예시를 조금 수정한 코드다. 이 코드를 실행하기 전 터미널에서 아래 명령어를 실행한다.
npm install react-native-safe-area-context
만약 위 명령어를 실행한 것만으로 안 된다면 아래 명령어들도 순서대로 실행한다.
cd ios
pod install
cd ..
npx react-native run-ios
아래가 코드다.
import React from 'react';
import {Text, SafeAreaView, View} from 'react-native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
return (
<SafeAreaProvider>
<SafeAreaView style={{height: 100, flexDirection: 'row'}}>
<View style={{backgroundColor: 'blue', flex: 0.2}} />
<View style={{backgroundColor: 'red', flex: 0.4}} />
<Text>Hello World!</Text>
</SafeAreaView>
</SafeAreaProvider>
);
};
export default App;
이걸 실행하면 아래와 같은 화면이 나온다.
아이폰의 노치 영역을 건들지 않도록 SafeAreaProvider와 SafeAreaView를 사용하고 그 안에서 View 2개와 텍스트를 배치했다.
flexDirection이 row로 설정됐기 때문에 가로로 표시되는 것이고, 첫 번째 View는 전체 너비의 20%를 차지하고 두 번째 뷰는 40%를 차지한다.
"Hello World!"는 flexbox의 특징 중 하나인 남은 공간이 있으면 그 공간을 차지하는 특성 때문에 자연스럽게 가로 영역의 남은 40%를 차지한다.
아래는 좀 더 기본적인 사용법이다.
import React from 'react';
import {Text, SafeAreaView, View} from 'react-native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
return (
<SafeAreaProvider>
<SafeAreaView>
<View>
<Text>안녕하세요</Text>
<Text>식사하셨나요?</Text>
</View>
</SafeAreaView>
</SafeAreaProvider>
);
};
export default App;
아래는 View에 스타일을 적용한 예시다.
import React from 'react';
import {Text, SafeAreaView, View} from 'react-native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
return (
<SafeAreaProvider>
<SafeAreaView>
<View
style={{
backgroundColor: '#FFF000',
padding: 20,
margin: 10,
borderRadius: 8,
borderWidth: 1,
borderColor: '#FF00FF',
}}>
<Text>스타일을 적용해 봤습니다</Text>
</View>
</SafeAreaView>
</SafeAreaProvider>
);
};
export default App;
아래는 flexbox 레이아웃 형태의 예시다.
import React from 'react';
import {SafeAreaView, View} from 'react-native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
return (
<SafeAreaProvider>
<SafeAreaView>
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 20,
}}>
<View style={{backgroundColor: 'red', width: 50, height: 50}} />
<View style={{backgroundColor: 'green', width: 50, height: 50}} />
<View style={{backgroundColor: 'blue', width: 50, height: 50}} />
</View>
</SafeAreaView>
</SafeAreaProvider>
);
};
export default App;
'React Native' 카테고리의 다른 글
[React-Native] Failed to build ios project. "xcodebuild" exited with error code '65'. 에러 수정 (0) | 2025.05.25 |
---|---|
[React-Native] 맥북 M2 Pro에 리액트 네이티브 환경설정하기 (2025 업데이트) (0) | 2025.05.25 |
[React-Native] Expo 기반 프로젝트 생성하기 (0) | 2024.11.12 |
[React-Native] SafeAreaView란? (0) | 2022.06.19 |
[React-Native] 윈도우에서 vs code에 리액트 네이티브 개발 환경 설정하는 법 (2022 ver) (0) | 2021.11.02 |