avatar
Published on

TIL๐Ÿ“š ์•ฑ๊ฐœ๋ฐœ ์Šคํ„ฐ๋”” - 2 week

Authors
  • avatar
    Name
    Haneul
    Twitter

TIL๐Ÿ“š ์•ฑ๊ฐœ๋ฐœ ์Šคํ„ฐ๋”” - 2 week

Expo ์„ค์น˜ ๐Ÿ‘‰

Expo ๋ž€?

expo๋Š” ๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ๋ฅผ ํฌ๋กœ์Šค ํ”Œ๋žซํผ์œผ๋กœ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•œ ๋นŒ๋“œ๋„๊ตฌ ๋„ค์ดํ‹ฐ๋ธŒ ๋ชจ๋“ˆ์„ ๋ณด๋‹ค ์‰ฝ๊ณ  ํŽธํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋น ๋ฅด๊ฒŒ ์‹ค์ œ ๊ธฐ๊ธฐ์—์„œ ํ…Œ์ŠคํŠธํ•ด๋ณผ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ํ…Œ์ŠคํŠธ ํ†ตํ•ฉ ํ™˜๊ฒฝ

npm install -g expo-cli // expo ์„ค์น˜ (npm)
yarn -global add expo-cli // expo ์„ค์น˜ (yarn)

expo init [ํ”„๋กœ์ ํŠธ ์ด๋ฆ„] // ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
expo start // ์‹คํ–‰


React Native ๐Ÿค”

React Native is like React, but it uses native components instead of web components as building blocks. So to understand the basic structure of a React Native app, you need to understand some of the basic React concepts, like JSX, components, state, and props. If you already know React, you still need to learn some React-Native-specific stuff, like the native components. This tutorial is aimed at all audiences, whether you have React experience or not.

React Native ์žฅ๋‹จ์  ๐Ÿ‘

์žฅ์ 

  • ๋„ค์ดํ‹ฐ๋ธŒ์™€ ๋น„๊ตํ•ด ์›”๋“ฑํžˆ ๋น ๋ฅธ ์ƒ์‚ฐ์„ฑ. ์ฒด๊ฐ์œผ๋ก  3~4๋ฐฐ
  • UI ๋“ฑ ํŒจํ‚ค์ง€ 40์—ฌ๊ฐœ
  • ๋ผ์ด๋ธŒ ๋ฆฌ๋กœ๋”ฉ
  • ์ฝ”๋“œ ํ‘ธ์‹œ
  • ๊ฐ„ํŽธํ•œ ๋ฌธ๋ฒ•

๋‹จ์ 

  • ์ดˆ๊ธฐ ํผํฌ๋จผ์Šค๋Š” ์ข‹์ง€๋งŒ ๋ทฐ ์Šคํƒ์ด ์Œ“์ผ์ˆ˜๋ก ๋Š๋ ค์ง
  • ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์ด ๋ณต์žกํ•˜๋ฉด ๋Š๋ ค์ง
  • ๋„ค์ดํ‹ฐ๋ธŒ ๋ทฐ, JS ๋กœ์ง๊ฐ„ ์†Œํ†ต์ด ๋งŽ์œผ๋ฉด ๋Š๋ ค์ง
  • ๋ฏธ๋ฌ˜ํ•œ UI ์˜ ์ด์ƒ ๋™์ž‘
  • ์จ๋“œํŒŒํ‹ฐ SDK ํƒ‘์žฌ ์ œ์•ฝ

React Native Components

View

  • The most fundamental component for building a UI, View is a container that supports layout with flexbox, style, some touch handling, and accessibility controls.
  • div ํƒœ๊ทธ์™€ ๋น„์Šท
import React from "react";
import { View, Text } from "react-native";

const ViewBoxesWithColorAndText = () => {
  return (
    <View
      style={{
        flexDirection: "row",
        height: 100,
        padding: 20
      }}
    >
      <View style={{ backgroundColor: "blue", flex: 0.3 }} />
      <View style={{ backgroundColor: "red", flex: 0.5 }} />
      <Text>Hello World!</Text>
    </View>
  );
};

export default ViewBoxesWithColorAndText;

Text

  • A React component for displaying text.
  • Text supports nesting, styling, and touch handling.
import React, { useState } from "react";
import { Text, StyleSheet } from "react-native";

const TextInANest = () => {
  const [titleText, setTitleText] = useState("Bird's Nest");
  const bodyText = "This is not really a bird nest.";

  const onPressTitle = () => {
    setTitleText("Bird's Nest [pressed]");
  };

  return (
    <Text style={styles.baseText}>
      <Text style={styles.titleText} onPress={onPressTitle}>
        {titleText}
        {"\n"}
        {"\n"}
      </Text>
      <Text numberOfLines={5}>{bodyText}</Text>
    </Text>
  );
};

const styles = StyleSheet.create({
  baseText: {
    fontFamily: "Cochin"
  },
  titleText: {
    fontSize: 20,
    fontWeight: "bold"
  }
});

export default TextInANest;

ScrollView

  • Component that wraps platform ScrollView while providing integration with touch locking "responder" system.
  • ์ปจํ…์ธ ๊ฐ€ ๋„˜์ณค์„ ๋•Œ ์Šคํฌ๋กค์„ ์ƒ์„ฑํ•˜๊ณ  ๊ฐ€๋ ค์ง€๋Š” ๋ถ€๋ถ„์„ ๋ณด์—ฌ์คŒ
  • https://reactnative.dev/docs/scrollview
import React from 'react';
import { StyleSheet, Text, SafeAreaView, ScrollView, StatusBar } from 'react-native';

const App = () => {
  return (
    <SafeAreaView style={styles.container}>
      <ScrollView style={styles.scrollView}>
        <Text style={styles.text}>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
          eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
          minim veniam, quis nostrud exercitation ullamco laboris nisi ut
          aliquip ex ea commodo consequat. Duis aute irure dolor in
          reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
          pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
          culpa qui officia deserunt mollit anim id est laborum.
        </Text>
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingTop: StatusBar.currentHeight,
  },
  scrollView: {
    backgroundColor: 'pink',
    marginHorizontal: 20,
  },
  text: {
    fontSize: 42,
  },
});

export default App;

TextInput

  • A foundational component for inputting text into the app via a keyboard.
import React from "react";
import { SafeAreaView, StyleSheet, TextInput } from "react-native";

const UselessTextInput = () => {
  const [text, onChangeText] = React.useState("Useless Text");
  const [number, onChangeNumber] = React.useState(null);

  return (
    <SafeAreaView>
      <TextInput
        style={styles.input}
        onChangeText={onChangeText}
        value={text}
      />
      <TextInput
        style={styles.input}
        onChangeText={onChangeNumber}
        value={number}
        placeholder="useless placeholder"
        keyboardType="numeric"
      />
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
    padding: 10,
  },
});

export default UselessTextInput;

TIL โœ…

react native ๋กœ ์‹ค์ œ ๋ฉ”์ธ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“œ๋Š” ์ž‘์—…์„ ์ง„ํ–‰ ๊ธฐ๋ณธ์ ์ธ ์ปดํฌ๋„ŒํŠธ๋“ค ์‚ฌ์šฉ ์—ฐ์Šต ๋ฐ ํ…Œ์ŠคํŠธํ•จ ! ๋ผ์šฐํŒ…์„ ์‚ฌ์šฉํ•ด ๋‹ค์–‘ํ•œ ํŽ˜์ด์ง€ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ์„ ํ•ด๋ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค.

์ฐธ๊ณ  : ์ŠคํŒŒ๋ฅดํƒ€ ์ฝ”๋”ฉํด๋Ÿฝ, React Naitve, RN vs Native vs Flutter ๋น„๊ต