SafeAreaView
iPhone X 이상 기종에서 디스플레이의 보이지 않는 영역 및 최하단 영역에 내용이 보여지는 것을 방지View
가장 기본적인 컴포넌트로 레이아웃 및 스타일을 담당Text
텍스트를 보여주는 역할import React from 'react';
import {View, Text} from 'react-native';
function Greeting(props) {
return (
<View>
<Text>안녕하세요 {props.name}</Text>
</View>
)
}
Greeting.defaultProps = {
name : '리액트 네이티브'
};
export default Greeting;
Props로 컴포넌트 스타일을 커스터마이징 가능
import React from 'react';
import {View, StyleSheet} from 'react-native';
function Box(props) {
return <View style={[styles.box, styles.rounded]} />;
}
const styles = StyleSheet.create({
box : {
width : 64,
height : 64,
backgroundColor: 'black'
},
rounded : {
borderRadius: 16
}
});
export default Box;
cf) 아래 코드는 props로 값이 전달될 때만 모서리가 둥글게 지정됨.
return <View style={[styles.box, props.rounded ? styles.rounded : null]}
(+) Boolean 타입의 Props를 설정할 때에는 코드를 아래와 같이 간소화할 수도 있음
<Box rounded />
funtion print(params){
console.log(params.name)
console.log(params.description)
}
function print({name, description}){
console.log(name);
console.log(description);
}
function Box({rounded, size, color}) {
return (
<View style={[
styles.box,
rounded && styles.rounded,
sizes[size],
{
backgroundColor : color
}
]}
/>
);
}
import React, {useState} from 'react';
.
.
.
const [visible, setVisible] = useState(true);
{
visible ? <Box rounded = {true} size = "large" /> : null
}
{
visible && <Box rounded = {true} size = "large" />
}