- Published on
TIL๐ ์ฑ๊ฐ๋ฐ ์คํฐ๋ - 2 week
- Authors
- Name
- Haneul
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 ๋น๊ต