react native 친해지자! - rule, layout

lionloopy·2024년 12월 19일

리액트 네이티브

목록 보기
2/5
post-thumbnail

RN의 rule

  1. html은 쓸 수 없다. 즉 div를 쓸 수 없고, 대신 view를 쓸 수 있다.
import {View} from "react-native"
  1. 모든 text는 text component에 들어가야 한다.
    p, span은 사용 할 수 없다.
<Text> 글자 </Text>
  1. 일부 style을 사용할 수 없다. (border 등)
    그래도 css만 안다면 98%는 가능!

  2. status bar은 third party 패키지다.
    시계, 배터리, wifi를 의미한다!

import { StatusBar } from "expo-status-bar"

layout

웹의 기본 flexDirection은 row지만,
앱의 기본 flexDirection은 column이다.

웹과 달리 스타일을 지정할 때 width, height로 잘 하지 않고 flex를 활용한다.
flex는 비율과 같다고 생각하면 된다.

    <View style={{ flex: 5 }}>
      <View style={{ flex: 5, backgroundColor: "tomato" }}></View>
      <View style={{ flex: 3, backgroundColor: "teal" }}></View>
      <View style={{ flex: 1, backgroundColor: "orange" }}></View>
    </View>

이렇게 있다면, 부모 컴포넌트의 flex가 필수적이고,
그 밑에 flex는 비율이라고 생각하면 된다.

profile
기록은 담백하게, 성장은 빠르게! 🐘

0개의 댓글