[React Native] 03-4 ์ปดํฌ๋ํธ ๋ฐฐ์น ๊ด๋ จ ์คํ์ผ ์์ฑ ํ๊ตฌํ๊ธฐ
flex:1 ๊ณผ height: '100%'์ ์ฐจ์ด
const styles = StyleSheet.create({
view: {
flex: 1,
height: '100%',
padding: 5,
backgroundColor: MD2Colors.lightBlue500,
},
text: {fontSize: 20, color: 'white'},
})
flex: 1 โก๏ธ ํ์ ์์์ ๋์ด๊ฐ ๋ฐ์๋ ๋ถ๋ชจ ์ปดํฌ๋ํธ์ ๋์ด์ ์ฌ๋ถ์ ๊ฐ์ ธ์ด
height: '100%' โก๏ธ ํ์ ์์์ ๋์ด์ ๋ฌด๊ดํ๊ฒ ๋ถ๋ชจ ์ปดํฌ๋ํธ์ ๋์ด๋ฅผ ๋ชจ๋ ๊ฐ์ ธ์ด
โ ๋ฃจํธ view์ Dimensions.get('window').height ์ ๊ฐ์ ๊ฒ
<์คํ์ผ ์์ฑ ์ ๋ฆฌ>
flexDirection ์คํ์ผ ์์ฑ
๋ถ๋ชจ ์ปดํฌ๋ํธ๊ฐ ๊ณ ์ ์ผ ๋ ์์ ์ปดํฌ๋ํธ๋ฅผ ์์ ์ ์์ญ์ ๋ฐฐ์นํ๋ ๊ธฐ๋ฒ
โก๏ธ 'row' (๊ฐ๋ก) ์ 'column'(์ธ๋ก) ์ผ๋ก ์ค์ ํ ์ ์์
โ ๊ธฐ๋ณธ๊ฐ์ 'column'
alignItems ์คํ์ผ ์์ฑ
๋ถ๋ชจ ์์์ ๋์ด๋ ๋์ด์ ์ฌ๋ถ์ด ์์ ๋ ์ด ์ฌ๋ถ์ ์ด์ฉํ์ฌ ์์ ์์์ ๋ฐฐ์น ๊ฐ๊ฒฉ์ ์กฐ์ ํ ์ ์์
โก๏ธ left, center, right, stretch
justifyContent ์คํ์ผ ์์ฑ
์ปดํฌ๋ํธ ์ฌ์ด์ ๊ณต๊ฐ ๋์ด๋ฅผ ๋ถ๋ฐฐํ๋ ๋ฐฉ๋ฒ
โก๏ธ flex-start, center, flex-end, space-around, space-between, space-evenly
flexWrap ์คํ์ผ ์์ฑ
์ปดํฌ๋ํธ๋ค์ด ํ๋ฉด ์์ ์ ๋๋ก ๋ค์ด์ค๋๋ก ์ฌ์ฉ
โก๏ธ nowrap, wrap, wrap-reverse
โ ๊ธฐ๋ณธ๊ฐ์ nowrap
overflow ์คํ์ผ ์์ฑ
์ ์ฒด ์ฝํ ์ธ ์ ํฌ๊ธฐ๊ฐ ์ปดํฌ๋ํธ ํฌ๊ธฐ๋ณด๋ค ํด ๋ ์ด๋ฅผ ์ด๋ป๊ฒ ํ ์ง ๊ฒฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ๋ ์์ฑ
โก๏ธ visible, hidden, scroll
โ ๊ธฐ๋ณธ๊ฐ์ visible ๐ ์ปดํฌ๋ํธ ๋ฐ๊นฅ์ชฝ์ผ๋ก๋ ๋ ๋๋ง๋จ
โ scroll ์ ์ค์ ํ๋ค๊ณ ์คํฌ๋กค ํจ๊ณผ๊ฐ ๋ฐ์ํ๋ ๊ฒ์ XX
ScrollView์ contentContainerStyle ์์ฑ
- ScrollView๋ style ๋ฟ๋ง ์๋๋ผ contentContainerStyle ์์ฑ๋ ์ ๊ณตํจ
- โก๏ธ ์คํฌ๋กค ๋์ ์ฝํ ์ธ ์ปดํฌ๋ํธ์ ์ ์ฉ๋๋ ์์ฑ
โ flex ์์ฑ์ ์ฌ์ฉํ์ง ์์์ผ ์คํฌ๋กค์ด ์ ์ ์๋ํจ
left, right top, bottom ๊ณผ position ์คํ์ผ ์์ฑ
์ปดํฌ๋ํธ๊ฐ ๋ ๋๋ง๋๋ ์์น๋ฅผ ๋ฐ๊พธ๊ณ ์ถ์ ๋ ์ฌ์ฉ
โ position ์คํ์ผ ์์ฑ๊ฐ์ 'absolute'๋ก ์ง์ ํด์ผ ํจ
ex) left: 10์ผ๋ก ์ค์ ์ ์ปดํฌ๋ํธ ์ผ์ชฝ์ ๊ธฐ์ค์ผ๋ก 10ํฝ์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ด๋/ right: 10์ผ๋ก ์ค์ ์ ์ปดํฌ๋ํธ ์ค๋ฅธ์ชฝ์ ๊ธฐ์ค์ผ๋ก 10ํฝ์ ์ผ์ชฝ์ผ๋ก ์ด๋
<ํ๋ฉด์ ๋ฌ ํจ๊ณผ ์ฃผ๋ ๋ฒ>
ํ๋ฉด์ ๋ฌ ํจ๊ณผ๋ฅผ ์ฃผ๋ ค๋ฉด ์์ด์ฝ์ด SafeAreaView์ ์์ ์ปดํฌ๋ํธ์ด๋ฉด ์๋จ
โ Fragment ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉ
import React, {Fragment} fron 'react'
โก๏ธ ์ค์ ์กด์ฌํ์ง๋ ์์ง๋ง XML ๋ฌธ๋ฒ์ด ์๊ตฌํ๋ ๋ถ๋ชจ ์ปดํฌ๋ํธ๋ก ๋์ํ๋๋ก ๋ง๋ค์ด์ง ์ปดํฌ๋ํธ
โก๏ธ <Fragment> </Fragment> ๋์ <></>์ผ๋ก ๋จ์ถ ์ฌ์ฉ ๊ฐ๋ฅ