React Native๋ ์น์ด ์๋๋ค.
์ฆ, ์ฐ๋ฆฌ๊ฐ ํํ ์ฐ๋ CSS๋ className ๊ธฐ๋ฐ์ ์คํ์ผ๋ง ๋ฐฉ์์ด ํตํ์ง ์๋๋ค.
๋์ RN์ ๋ชจ๋ ์คํ์ผ์ ๊ฐ์ฒด ํํ๋ก ๊ตฌ์ฑํ๊ณ ,
HTML ํ๊ทธ ๋์ <View>
, <Text>
๊ฐ์ ๋ค์ดํฐ๋ธ ์ปดํฌ๋ํธ์ ์คํ์ผ์ ์ ์ฉํ๋ค.
์ด๋ฒ ๊ธ์์๋ React Native์์ ์ฌ์ฉํ ์ ์๋ ์คํ์ผ๋ง ๋ฐฉ๋ฒ 3๊ฐ์ง์
๊ฐ ๋ฐฉ์์ ํน์ง, ์ค์ ํ์ ์ ๋ฆฌํด๋ดค๋ค.
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',
},
});
๐ ํน์ง
StyleSheet.create()
๋ก ์์ฑ ์ ์๋ ์ต์ ํ๋จ ์์ฑ | ์ค๋ช |
---|---|
flex , flexDirection , justifyContent , alignItems | Flexbox ๊ธฐ๋ฐ ๋ ์ด์์ |
padding , margin , borderWidth , borderRadius | ๋ฐ์ค ๋ชจ๋ธ |
fontSize , fontWeight , color | ํ ์คํธ |
backgroundColor , shadowColor | ๋ฐฐ๊ฒฝ ๋ฐ ๊ทธ๋ฆผ์ |
๐ง React Native๋ ์ ์ฒด๊ฐ Flexbox ๊ธฐ๋ฐ์ด๋ค
โdisplay: flex
๋ ๊ธฐ๋ณธ๊ฐ์ด๋ผ ์๋ต๋จ!
<Text style={{ fontSize: 20, color: 'blue' }}>์ง์ ์คํ์ผ</Text>
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>
);
}
โ ์ฅ์
styled-components/native
์ฌ์ฉ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์ ๊ฐ์ฒด๋ก ์์ฑ๋๋ค."