๐ŸŽจ 34. React Native ์Šคํƒ€์ผ๋ง ์™„์ „ ์ •๋ฆฌ โ€” ์Šคํƒ€์ผ๋„ ์›น๊ณผ ๋‹ค๋ฅด๋‹ค!

JM_Devยท2025๋…„ 5์›” 12์ผ
0
post-thumbnail

React Native๋Š” ์›น์ด ์•„๋‹ˆ๋‹ค.
์ฆ‰, ์šฐ๋ฆฌ๊ฐ€ ํ”ํžˆ ์“ฐ๋˜ CSS๋‚˜ className ๊ธฐ๋ฐ˜์˜ ์Šคํƒ€์ผ๋ง ๋ฐฉ์‹์ด ํ†ตํ•˜์ง€ ์•Š๋Š”๋‹ค.
๋Œ€์‹  RN์€ ๋ชจ๋“  ์Šคํƒ€์ผ์„ ๊ฐ์ฒด ํ˜•ํƒœ๋กœ ๊ตฌ์„ฑํ•˜๊ณ ,
HTML ํƒœ๊ทธ ๋Œ€์‹  <View>, <Text> ๊ฐ™์€ ๋„ค์ดํ‹ฐ๋ธŒ ์ปดํฌ๋„ŒํŠธ์— ์Šคํƒ€์ผ์„ ์ ์šฉํ•œ๋‹ค.

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” React Native์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์Šคํƒ€์ผ๋ง ๋ฐฉ๋ฒ• 3๊ฐ€์ง€์™€
๊ฐ ๋ฐฉ์‹์˜ ํŠน์ง•, ์‹ค์ „ ํŒ์„ ์ •๋ฆฌํ•ด๋ดค๋‹ค.


โœ… ๊ธฐ๋ณธ ์Šคํƒ€์ผ๋ง: StyleSheet ๊ฐ์ฒด ์‚ฌ์šฉ

import { StyleSheet, View, Text } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Hello React Native</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
  title: {
    fontSize: 24,
    color: '#333',
  },
});

๐Ÿ“Œ ํŠน์ง•

  • CSS๊ฐ€ ์•„๋‹Œ JS ๊ฐ์ฒด ํ˜•์‹
  • StyleSheet.create()๋กœ ์ž‘์„ฑ ์‹œ ์ž๋™ ์ตœ์ ํ™”๋จ
  • ์ต์ˆ™ํ•ด์ง€๋ฉด ์˜คํžˆ๋ ค ๋” ๊ฐ€๋…์„ฑ ์ข‹์Œ

๐Ÿงฉ ์ฃผ์š” ์Šคํƒ€์ผ ์†์„ฑ ์ •๋ฆฌ

์†์„ฑ์„ค๋ช…
flex, flexDirection, justifyContent, alignItemsFlexbox ๊ธฐ๋ฐ˜ ๋ ˆ์ด์•„์›ƒ
padding, margin, borderWidth, borderRadius๋ฐ•์Šค ๋ชจ๋ธ
fontSize, fontWeight, colorํ…์ŠคํŠธ
backgroundColor, shadowColor๋ฐฐ๊ฒฝ ๋ฐ ๊ทธ๋ฆผ์ž

๐Ÿง  React Native๋Š” ์ „์ฒด๊ฐ€ Flexbox ๊ธฐ๋ฐ˜์ด๋‹ค
โ†’ display: flex๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ ์ƒ๋žต๋จ!


โœจ ์ธ๋ผ์ธ ์Šคํƒ€์ผ๋„ ๊ฐ€๋Šฅ

<Text style={{ fontSize: 20, color: 'blue' }}>์ง์ ‘ ์Šคํƒ€์ผ</Text>
  • ๋น ๋ฅด๊ฒŒ ํ…Œ์ŠคํŠธํ•  ๋• ์ข‹์ง€๋งŒ,
  • ์žฌ์‚ฌ์šฉ์„ฑ๊ณผ ์œ ์ง€๋ณด์ˆ˜์„ฑ์—์„œ๋Š” StyleSheet ๋ฐฉ์‹์ด ๋” ์ข‹์Œ

๐Ÿ’… styled-components/native ์‚ฌ์šฉํ•˜๊ธฐ

npm install styled-components
import styled from 'styled-components/native';

const Container = styled.View`
  flex: 1;
  justify-content: center;
  align-items: center;
  background-color: #f9f9f9;
`;

const Title = styled.Text`
  font-size: 24px;
  color: #333;
`;

export default function App() {
  return (
    <Container>
      <Title>Hello styled-components!</Title>
    </Container>
  );
}

โœ… ์žฅ์ 

  • ๊ธฐ์กด ์›น React์˜ ๊ฐ์„ฑ์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
  • ๋‹คํฌ๋ชจ๋“œ, ์กฐ๊ฑด๋ถ€ ์Šคํƒ€์ผ๋ง, theme ์—ฐ๋™์ด ํŽธํ•จ
  • Emotion ๋Œ€์‹  styled-components/native ์‚ฌ์šฉ

โš ๏ธ ์ฃผ์˜ํ•  ์ 

  • CSS ๋ฌธ๋ฒ• ๊ทธ๋Œ€๋กœ๋Š” ์•ˆ ๋จ
    โ†’ ๋‹จ์œ„ ์—†์Œ (px, rem โŒ), ๋ชจ๋‘ ์ˆซ์ž ๋˜๋Š” ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌ
  • margin: auto ์•ˆ ๋จ (Flex๋กœ ๋Œ€์ฒด)
  • position: fixed โŒ (RN์—” ์—†์Œ โ†’ ๋Œ€์‹  absolute + ์œ„์น˜ ๊ณ„์‚ฐ)

๐Ÿ“ฑ ์‹ค๋ฌด์—์„œ ์ž์ฃผ ์“ฐ๋Š” ํŒจํ„ด

const Button = styled.TouchableOpacity`
  background-color: ${(props) => (props.disabled ? '#ccc' : '#ff6600')};
  padding: 12px 24px;
  border-radius: 8px;
`;

<Button disabled={isSubmitting}>
  <Text>์ „์†ก</Text>
</Button>
  • ์กฐ๊ฑด๋ถ€ ์Šคํƒ€์ผ๋ง๋„ ํ›จ์”ฌ ์ง๊ด€์ 
  • ํ…Œ๋งˆ ๋ถ„๋ฆฌ๋„ ์‰ฌ์›Œ์„œ ๋””์ž์ธ ์‹œ์Šคํ…œ ๋งŒ๋“ค๊ธฐ ์ข‹์Œ

๐Ÿ“ ๋‚ด๊ฐ€ ๋А๋‚€ ์ 

์ฒ˜์Œ์—” CSS ์™œ ์•ˆ ์จ์ง?? ์ด๋žฌ๋Š”๋ฐ,
Flexbox๋งŒ ์ตํžˆ๊ณ  ๋‚˜๋‹ˆ๊นŒ React Native๋Š” ์˜คํžˆ๋ ค ์Šคํƒ€์ผ ๊ตฌ์กฐ๊ฐ€ ๋” ๊น”๋”ํ•˜๊ณ  ์˜ˆ์ธก ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ๋А๊ผˆ๋‹ค.
์ง€๊ธˆ์€ styled-components/native๋กœ ํ†ต์ผํ•ด์„œ ๋‹คํฌ๋ชจ๋“œ๋„ ThemeProvider๋กœ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๊ณ ,
์•ฑ ์Šคํƒ€์ผ๋ง์ด ์ ์  ์›น์ฒ˜๋Ÿผ ์ž์—ฐ์Šค๋Ÿฌ์›Œ์ง€๊ณ  ์žˆ๋‹ค๋Š” ๊ฑธ ์‹ค๊ฐ ์ค‘์ด๋‹ค.


๐ŸŽจ "์Šคํƒ€์ผ์ด ์˜ˆ๋ป์•ผ UX๋„ ์ข‹๋‹ค. React Native์˜ ์Šคํƒ€์ผ์€ Flex์™€ ๊ฐ์ฒด๋กœ ์™„์„ฑ๋œ๋‹ค."


profile
๊ฐœ๋ฐœ์ž๋กœ ์ทจ์—…์„ ์ค€๋น„ ์ค‘ ์ด๋ฉฐ, ์—ด์‹ฌํžˆ ๊ณต๋ถ€ ์ค‘ ์ž…๋‹ˆ๋‹ค!

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