๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš€ Development/React Native

React Native ์ปดํฌ๋„ŒํŠธ๋ž€? / ํด๋ž˜์Šคํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์˜ ํŠน์ง•

by Jay Din 2023. 6. 15.
728x90
๋ฐ˜์‘ํ˜•

์ปดํฌ๋„ŒํŠธ๋ž€?

์ปดํฌ๋„ŒํŠธ๋Š” UI๋ฅผ ๋…๋ฆฝ์ ์ด๊ณ  ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ธฐ๋Šฅ ๋‹จ์œ„๋ณ„๋กœ ๋‚˜๋ˆ  ๋†“์€ ๋‹จ์œ„์ด๋‹ค.

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

๋ฐ˜์‘ํ˜•

 

์ฃผ์š” ์ปดํฌ๋„ŒํŠธ

SafeAreaView
์ƒ๋‹จ์— ์ƒํƒœ ๋ฐ”์™€ ํ•˜๋‹จ์— ํ™ˆ ๋ฒ„ํŠผ ์˜์—ญ์„ ์ œ์™ธํ•œ ์˜์—ญ์— ์ฝ˜ํ…์ธ ๋ฅผ ํ‘œ์‹œํ•  ๋•Œ ์‚ฌ์šฉ
View
์ƒํƒœ๋ฐ”์™€ ํ™ˆ ๋ฒ„ํŠผ ์˜์—ญ๊นŒ์ง€ ์ฝ˜ํ…์ธ  ํ‘œ์‹œ
StyleSheet
๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ ์ปดํฌ๋„ŒํŠธ์— ์Šคํƒ€์ผ ์ ์šฉํ•  ๋•Œ ์‚ฌ์šฉ
๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ์—์„œ ์Šคํƒ€์ผ์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ธ๋ผ์ธ ์Šคํƒ€์ผ๊ณผ StyleSheet๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์Œ
ScrollView
ํ™”๋ฉด ์Šคํฌ๋กค์ด ๊ฐ€๋Šฅํ•œ ์ปดํฌ๋„ŒํŠธ
ํ™”๋ฉด ์Šคํฌ๋กค์ด ๊ฐ€๋Šฅํ•œ ์ปดํฌ๋„ŒํŠธ๋กœ๋Š” FlatList, ScrollView ๋“ฑ์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Œ
Text
ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ
Button
๋ฒ„ํŠผ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ปดํฌ๋„ŒํŠธ

 

ํด๋ž˜์Šคํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์˜ ํŠน์ง•

ํด๋ž˜์Šคํ˜• ์ปดํฌ๋„ŒํŠธ

import React, {Component} from "react";
import {View, Text} from 'react-native';
class App extends Component {
const name = ‘๋ฆฌ์•กํŠธ’;
  render(){
    return(
      <View>
        <Text> {name} </Text>
      </VIew>
    );
  } }
export default App;
  • class ํ‚ค์›Œ๋“œ ํ•„์š”
  • Component๋กœ ์ƒ์†์„ ๋ฐ›์•„์•ผํ•œ๋‹ค.
  • render() ๋ฉ”์†Œ๋“œ๊ฐ€ ๋ฐ˜๋“œ์‹œ ์žˆ์–ด์•ผํ•œ๋‹ค.
  • state, lifeCycle ๊ด€๋ จ ๊ธฐ๋Šฅ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ๋ฉ”๋ชจ๋ฆฌ ์ž์›์„ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ๋ณด๋‹ค ์กฐ๊ธˆ ๋” ์‚ฌ์šฉํ•œ๋‹ค.

ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ

import React from "react";
import {View, Text} from 'react-native';
const App = () => {
  const name = ‘๋ฆฌ์•กํŠธ’;
  return(
       <View>
              <Text> {name} </Text>
        </VIew>
}
export default App;
  • state, lifeCycle ๊ด€๋ จ ๊ธฐ๋Šฅ ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅ [Hook์„ ํ†ตํ•ด ํ•ด๊ฒฐ ๋จ]
  • ๋ฉ”๋ชจ๋ฆฌ ์ž์›์„ ํด๋ž˜์Šคํ˜• ์ปดํฌ๋„ŒํŠธ๋ณด๋‹ค ๋œ ์‚ฌ์šฉํ•œ๋‹ค.
  • ์ปดํฌ๋„ŒํŠธ ์„ ์–ธ์ด ํŽธํ•˜๋‹ค.
๋ฐ˜์‘ํ˜•

ํด๋ž˜์Šคํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ ๋น„๊ต

์œ„ ์ฝ”๋“œ๋Š” ํด๋ž˜์Šคํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์˜ ์‹คํ–‰๊ฒฐ๊ณผ๊ฐ€ ๋™์ผํ•˜๋‹ค.

ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ํด๋ž˜์Šคํ˜• ์ปดํฌ๋„ŒํŠธ๋ณด๋‹ค ์„ ์–ธํ•˜๊ธฐ๊ฐ€ ์ข€ ๋” ํŽธํ•˜๊ณ , ๋ฉ”๋ชจ๋ฆฌ ์ž์›์„ ๋œ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹ค. ๊ณผ๊ฑฐ์—๋Š” ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์—์„œ state์™€ ๋ผ์ดํ”„์‚ฌ์ดํด API๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ์—ˆ๋Š”๋ฐ, ์ด๋Ÿฌํ•œ ๋‹จ์ ์€ ์•ž์„œ ์–ธ๊ธ‰ํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ฆฌ์•กํŠธ ํ›…์ด ๋„์ž…๋˜๋ฉด์„œ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋Š” render ํ•จ์ˆ˜๊ฐ€ ๊ผญ ์žˆ์–ด์•ผ ํ•˜๊ณ , ๊ทธ ์•ˆ์—์„œ ๋ณด์—ฌ ์ฃผ์–ด์•ผ ํ•  JSX๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ(return) ํ•ฉ๋‹ˆ๋‹ค. ์•ž์— class ํ‚ค์›Œ๋“œ๋ฅผ ์ ๊ณ  Component๋ฅผ ์ƒ์† ๋ฐ›์•„์•ผํ•œ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•