Intro
์ค๋์ React Native์์ ์์ฃผ ์ฌ์ฉํ๋ ๊ธฐ๋ณธ ์ปดํฌ๋ํธ๋ฅผ ์์๋ณด๊ณ ์ฝ๋์ ์ง์ ์ ์ฉํด๋ณด๋ ์ค์ต ๊ฐ์๋ฅผ ๋ค์๋ค.
์ค๋ ํ์ตํ ๋ด์ฉ
View, Text
๊ฐ์ฅ ๋ง์ด ์ฐ์ด๋ ๊ธฐ๋ณธ ์ปดํฌ๋ํธ๋ View, Text์ด๋ค.
๐ฉ๐ป View๋ html์ div ํ๊ทธ์ ๋น์ทํ ์ญํ ์ ํ๋ค. ๋ฌด์กฐ๊ฑด flex์ ํจ๊ป ์ฐ์ฌ alignItems, justifyContent๋ก ์ ๋ ฌ์ ํ ์ ์๋ค.
Text๋ ๊ธฐ๋ณธ ๊ธ์ ์ปดํฌ๋ํธ๋ก ๊ธ์๋ฅผ ๋ฃ์ผ๋ ค๋ฉด Text๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
๐ฉ๐ป allowFontScaling={false}๋ก ์ค์ ํ๋ฉด ๊ฐ์ธ ๋๋ฐ์ด์ค์์ ๊ธ์จ๋ฅผ ํฌ๊ฒ ํ์ ๋ ๊ฐ์ด ์ปค์ง๋ ๊ฒ์ ๋ง๋ ์ค์ ์ ํ ์ ์๋ค. (default=true)
<Text ellipsizeMode="tail" numberOfLines={1} allowFontScaling={false}
style={{color: '#fff', fontSize: 24, fontWeight: 'bold'}}>
React Native {test}React Native {test}React Native {test}React Native{' '}
{test}React Native {test}React Native {test}React Native {test}React
Native {test}React Native {test}
</Text>
Text์์ ellipsizeMode ์์ฑ์ผ๋ก ๊ธ์๊ฐ ๊ธธ์ด์ก์ ๋ ์๋ต์ ๋ํ ๋ชจ๋๋ฅผ ์ ํํ ์ ์๊ณ , numberOfLines๋ก ํ ์คํธ ์ค ๊ธธ์ด๋ฅผ ์ค์ ํ ์ ์๋ค.
ScrollView
- View๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์์๋ฐ์ View์ ๊ด๋ จ๋ ๊ธฐ๋ฅ์ ๋ชจ๋ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
- horizontal๋ก ๊ฐ๋ก ์คํฌ๋กค ์ค์ ์ด ๊ฐ๋ฅํ๋ค.
- showVerticalScrollIndicator=false, showHorizontalScrollIndicator=false๋ก ์คํฌ๋กค์ด ๋ณด์ด๋ ๊ฑธ ์์จ ์ ์๋ค.
StyleSheet
React Native์์ ์ถ์ฒํ๋ ์คํ์ผ๋ง ๋ฐฉ๋ฒ์ด๋ค.
const styles = StyleSheet.create({
basicWrapper: {
height: 2000, flexDirection: 'row', justifyContent: 'center', alignItems: 'flex-start',
})
์ปดํฌ๋ํธ์ style ์์ฑ์ styles.(์คํ์ผ ๋ช )๋ก ์คํ์ผ์ ์ ์ฉํ ์ ์๋ค.
SafeAreaView
- ์์ดํฐ์ ์ํ ํ์์ฐฝ์ด๋ผ ios์์ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
- ์๋๋ก์ด๋์์ ์๋์ผ๋ก ๋ฌด์๋๋ค.
- iOS V11 ์ด์๋ถํฐ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
TouchableOpacity
- ํฐ์นํ ๋ ๋ถํฌ๋ช ํ๊ฒ ๋ณํ๋ฉด์ ํฐ์น๋จ์ ์ ์ ์๋ ์ปดํฌ๋ํธ์ด๋ค.
- onPress ์์ฑ์ผ๋ก ํฐ์นํ์ ๋ ๋์์ ์ฝ๋ฐฑํจ์๋ก ๋ฃ์ด์ค๋ค.
<TouchableOpacity onPress={() => Alert.alert('์๋
ํ์ธ์')}
style={{
flex: 1,
alignItems: 'flex-end',
backgroundColor: 'beige',
}}>
<Text style={{fontSize: 24}}>์ค์ </Text>
</TouchableOpacity>
- activeOpacity๋ก ํฌ๋ช ๋ ์ค์ ์ด ๊ฐ๋ฅํ๋ค.
- onLongPress ์์ฑ์ ํฐ์น๋ฅผ ๊ธธ๊ฒ ๋๋ ์ ๋ ๋์ํ๋ ํจ์๋ฅผ ์ค์ ํ๋ค.
- React Native์์ Button ์ปดํฌ๋ํธ๋ณด๋ค๋ TouchableOpacity๋ฅผ ์ฃผ๋ก ์ฌ์ฉํ๋ค.
TextInput
- ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ์ ์๋ ์ ๋ ฅ์ฐฝ ์ปดํฌ๋ํธ
- width, height๋ฅผ ํ์๋ก ์ค์ผ ํ๋ค.
- KeyboardAvoidingView ์ปดํฌ๋ํธ๋ฅผ ํจ๊ป ์จ์ ํค๋ณด๋ ์กฐ์ ๋ ํ ์ ์๋ค.
Image
<Image source={leftArrow} style={styles.backButton} />
source์ img ํ์ผ์ด๋ url์ ๋ถ๋ฌ์จ๋ค.
๋ง๋ฌด๋ฆฌ
๋ณธ๊ฒฉ์ ์ผ๋ก React Native๋ฅผ ๋ค๋ค๋ดค๋๋ฐ ๋ง๋ค์ด์ ธ ์๋ ์ปดํฌ๋ํธ๋ฅผ ๊ฐ์ง๊ณ ๋ธ๋ญ์ฒ๋ผ ์กฐ๋ฆฝํ๋ ๋๋์ด๋ผ ์ฌ๋ฐ์๋ค.
๋์์ธ์ด ๋ถ์กฑํ๋๋ผ๋ ๊ทธ๋ด๋ฏํ ์ฑ์ ๋ง๋ค ์ ์์ ๊ฒ ๊ฐ๋ค.
