๐Ÿ“ฑ

006. React Native

1. Native App

Android, ios์ฒ˜๋Ÿผ ๊ฐ๊ฐ์˜ ์šด์˜์ฒด์ œ ํ™˜๊ฒฝ์— ๋งž์ถฐ์„œ ๊ฐœ๋ฐœํ•œ ์•ฑ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, ๊ฐœ๋ฐœ์„ ํ•  ๋•Œ Android๋Š” Android Studio, ios๋Š” Swift๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐœ๋ฐœํ•ฉ๋‹ˆ๋‹ค. Native App์€ ์„ฑ๋Šฅ์ด ์›น์•ฑ , ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์•ฑ์— ๋น„ํ•˜์—ฌ ๊ฐ€์žฅ ๋†’์ง€๋งŒ, ํ”Œ๋žซํผ์— ์˜์กด์ ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ์–ธ์–ด๋ฅผ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ์–ด์•ผ ๊ฐœ๋ฐœ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
ย 

2. React Native

Native App๊ณผ ๋‹ฌ๋ฆฌ, ์šด์˜์ฒด์ œ์— ๊ตฌ์•  ๋ฐ›์ง€ ์•Š๊ณ  ํ•˜๋‚˜์˜ ์–ธ์–ด๋กœ ์•ฑ์„ ๊ฐœ๋ฐœํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ Hybrid App์ด๋ผ๊ณ  ํ•˜๊ณ , React Native๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐœ๋ฐœ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
ย 

3. Electron

Node.js ๊ธฐ๋ฐ˜์˜ ํ”Œ๋žซํผ์œผ๋กœ, ๋ฐ์Šคํฌํƒ‘ App ๊ฐœ๋ฐœ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๋Œ€ํ‘œ์ ์ธ ์•ฑ์œผ๋กœ๋Š” VScode, Atom ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
ย 

4. Reactive Native ์‹ค์Šต

๐Ÿ’ก
React Native๋กœ 5๋ถ„๋งŒ์— ์™„์„ฑํ•˜๋Š” ์›น์•ฑ(๊ตฌ๋ฆ„IDE + Expo) ์‹ค์Šต์€ ์œ ํŠœ๋ธŒ์—์„œ๋„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.๐Ÿ˜‰ (https://bit.ly/3iN5Bb9)
ย 

4.1. ์‹ค์Šต ์ „ ์ค€๋น„ ์‚ฌํ•ญ

  1. ๊ตฌ๋ฆ„ IDE ๋กœ๊ทธ์ธ & React Native ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ (ํšŒ์›์ด ์•„๋‹ˆ๋ฉด ํšŒ์›๊ฐ€์ž…๋ถ€ํ„ฐ ์ง„ํ–‰ํ•ด ์ฃผ์„ธ์š”!)
  1. ์•ฑ์Šคํ† ์–ด / ํ”Œ๋ ˆ์ด์Šคํ† ์–ด์—์„œ Expo ์„ค์น˜ ๋˜๋Š” snack(https://snack.expo.io/) ์ค€๋น„ ๋‹ค๋งŒ, Snack์˜ ๊ฒฝ์šฐ ๋Œ€๊ธฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— Expo ์„ค์น˜๋ฅผ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.
ย 

snack ์‚ฌ์šฉ๋ฒ•

notion imagenotion image
ย 
์‹ค์Šต ์ค‘ ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋œจ๋ฉด 'Add dependency'๋ฅผ ํด๋ฆญํ•ด ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
notion imagenotion image

4.2. App.js

import * as React from 'react'; import { Text, View, StyleSheet } from 'react-native'; import Constants from 'expo-constants'; // You can import from local files import AssetExample from './components/AssetExample'; // or any pure javascript modules available in npm import { Card } from 'react-native-paper'; export default function App() { return ( <View style={styles.container}> <Text style={styles.paragraph}> Change code in the editor and watch it change on your phone! Save to get a shareable url. </Text> <Card> <AssetExample /> </Card> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', paddingTop: Constants.statusBarHeight, backgroundColor: '#ecf0f1', padding: 8, }, paragraph: { margin: 24, fontSize: 18, fontWeight: 'bold', textAlign: 'center', }, });
ย 
notion imagenotion image
ย 

4.3. App.js ์ฝ”๋“œ ์ˆ˜์ • (Text ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •)

import * as React from 'react'; import { Text, View, StyleSheet } from 'react-native'; import Constants from 'expo-constants'; // You can import from local files import AssetExample from './components/AssetExample'; // or any pure javascript modules available in npm import { Card } from 'react-native-paper'; export default function App() { return ( <View style={styles.container}> <Text style={styles.paragraph}> Hello World! </Text> <Card> <AssetExample /> </Card> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', paddingTop: Constants.statusBarHeight, backgroundColor: '#ecf0f1', padding: 8, }, paragraph: { margin: 24, fontSize: 18, fontWeight: 'bold', textAlign: 'center', }, });
ย 
notion imagenotion image

4.4. WebView

import * as React from 'react'; import { WebView } from 'react-native-webview'; export default class App extends React.Component { render() { return <WebView source={{ uri: 'https://paullab.co.kr/about.html' }} style={{ marginTop: 20 }} />; } }
ย 
notion imagenotion image
ย 

4.5. ํ™”๋ฉด ๋ถ„ํ•  1

import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; export default class App extends Component<Props> { render() { return ( <View style={styles.container}> <View style={styles.case1} /> <View style={styles.case2} /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'white', }, case1: { flex: 1, backgroundColor: 'red', }, case2: { flex: 1, backgroundColor: 'blue', }, });
ย 
notion imagenotion image
ย 

4.6. ํ™”๋ฉด ๋ถ„ํ•  2

import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; export default class App extends Component<Props> { render() { return ( <View style={styles.container}> <View style={styles.case1} /> <View style={styles.case2} /> <View style={styles.case3} /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'white', }, case1: { flex: 1, backgroundColor: 'red', }, case2: { flex: 2, backgroundColor: 'green', }, case3: { flex: 1, backgroundColor: 'blue', }, });
ย 
notion imagenotion image

4.7. ์นด๋ฉ”๋ผ ๋กค

import React, { useState, useEffect } from 'react'; import { Button, Image, View, Platform } from 'react-native'; import * as ImagePicker from 'expo-image-picker'; import Constants from 'expo-constants'; export default function ImagePickerExample() { const [image, setImage] = useState(null); useEffect(() => { (async () => { if (Platform.OS !== 'web') { const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync(); if (status !== 'granted') { alert('Sorry, we need camera roll permissions to make this work!'); } } })(); }, []); const pickImage = async () => { let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.All, allowsEditing: true, aspect: [4, 3], quality: 1, }); console.log(result); if (!result.cancelled) { setImage(result.uri); } }; return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Button title="Pick an image from camera roll" onPress={pickImage} /> {image && <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />} </View> ); }
ย 
notion imagenotion image
ย 

5. ๊ณต์‹๋ฌธ์„œ