๐Ÿ’ป[React Native] Expo๋กœ TodoList ๋งŒ๋“ค๊ธฐ

ํ˜ฑยท2023๋…„ 1์›” 14์ผ

import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";

console.log("hello")
export default function App() {
  return (
    <View style={styles.container}>
      <Text></Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

container style์„ ์ œ๊ฑฐํ•˜๋ฉด, ๋„์น˜๊ฐ€ ์žˆ๋Š” ํ”Œ๋žซํผ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ ์ด์— ๊ฐ€๋ ค์ง€๊ฑฐ๋‚˜ ์ƒ๋‹จ ์œ„๋กœ ์˜ฌ๋ผ๊ฐ€์„œ ๋ ˆ์ด์•„์›ƒ์ด ๊นจ์ง€๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ์ด๋•Œ, ๊ฐ ๊ธฐ๊ธฐ๋งˆ๋‹ค ๋˜ํ•œ ํ™”๋ฉด ๋น„์œจ์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์—, React Native์—์„œ๋Š” SafeAreaView๋ผ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ๊ณตํ•จ.
  • ์ด์— ๋”ฐ๋ผ์„œ ์œ„์—๋„ ์ผ๋ถ€๋ถ„ ์•„๋ž˜์—๋„ ์ผ๋ถ€๋ถ„(ํ™ˆ๋ฒ„ํŠผ๊ณผ ๊ด€๋ จ๋œ ๊ธฐ๋Šฅ์ด ๋” ์šฐ์„ ๊ถŒ์„ ๊ฐ€์ ธ์„œ, ๋ฒ„ํŠผ ๋“ฑ์˜ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ) ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ์กฐ์ •ํ•ด์คŒ
  • ์•ˆ๋“œ๋กœ์ด๋“œ์˜ ๊ฒฝ์šฐ ์šด์˜์ฒด์ œ ์ƒ๋‹จ์— ์ƒํƒœ๋ฐ”๊ฐ€ ์กด์žฌํ•จ, ์ด๋•Œ ์ƒํƒœ๋ฐ”์— ์˜ํ•ด ์ปดํฌ๋„ŒํŠธ ์ผ๋ถ€๊ฐ€ ๊นจ์ง€๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Œ, ๋”ฐ๋ผ์„œ ์ด๋ฅผ ๋ ˆ์ด์•„์›ƒ์ธก๋ฉด์—์„œ ์žก์•„์ฃผ์–ด์•ผ ํ•จ
    ์ด๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํŒจํ‚ค์ง€๋Š” Constants
  • import Constants from 'expo-constants'; ํŒจํ‚ค์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ , paddingTop: Constants.statusBarHeight, style์— ์ด๋ฅผ ์ €์žฅ but ์•„์ดํฐ์—์„œ๋Š” ์“ธ๋ฐ ์—†๋Š”? ๋นˆ ๊ณต๊ฐ„์ด ์ƒ๊ธธ ์ˆ˜ ์žˆ๋‹ค๋Š” ๋‹จ์ ์ด ์กด์žฌ
  • ํ”Œ๋žซํผ์„ ์ง€์ •ํ•œ ํ›„ ์ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•จ Platform์„ ์ด์šฉ
    paddingTop: Platform.OS === 'android' ? Constants.statusBarHeight : 0

Padding, Row์™€ ๊ฐ™์€ style์„ ์ž์ฒด component๋กœ ๋ฐ”๊พธ์–ด์„œ ์„ค์ •ํ•ด ์ฃผ๊ธฐ
App.js

<Padding padding={12}>
        <TodoItem />
        <Row>
          <TextInput style={styles.input} />
          <Button title="Send" onPress={() => {}} />
        </Row>
      </Padding>

Padding.js

function Padding({ children, padding }) {
  return <View style={{ padding: padding ?? 20 }}>{children}</View>;
}

### Expo checkbox
profile
new blog: https://hae0-02ni.tistory.com/

0๊ฐœ์˜ ๋Œ“๊ธ€