์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- ํ์ดํ๋
- native
- ๋์
- Kaggle
- ๋ฅ๋ฌ๋
- ์ธํ๋ฐ
- ์ํ์ฝ๋ฉ
- ๋ฆฌ์กํธ
- Git
- ๋ฐ์ดํฐ์๊ฐํ
- cs231n
- c++
- ๋ถ์
- ํ๊ตญ์ด์๋ฒ ๋ฉ
- ๊นํ
- ๋ฐฑ์ค
- ์๋ฒ ๋ฉ
- ๋ฐ์ดํฐ
- ์ ํ๋์ํ
- ๋ค์ดํฐ๋ธ
- Titanic
- ๋ฐ์ดํฐ๋ถ์
- ๋จธ์ ๋ฌ๋
- ์๊ณ ๋ฆฌ์ฆ
- ๊ฒฐ์ ํธ๋ฆฌ
- ์๋๋ก์ด๋์คํ๋์ค
- linearalgebra
- react
- AI
- nlp
- Today
- Total
yeon's ๐ฉ๐ป๐ป
[React-Native] Drawer | Custom Component ๋ณธ๋ฌธ
* Side Drawer์ ์ปค์คํฐ๋ง์ด์งํ๊ธฐ
- my_drawer.js ๋ผ๋ ์๋ก์ด ํ์ผ ์์ฑ
class SideDrawer extends Component {
render() {
return (
<View style={styles.container}>
<Text>Hello World</Text>
</View>
)
}
}
- App.js์์ CustomDrawerContent ํจ์ ๋์ SideDrawer ํจ์๋ก ๋ณ๊ฒฝ
drawerContent={props => <SideDrawer {...props} />}
* ์ฌ๊ธฐ์ ๊ทธ๋ฆผ๋ ๋ฃ์ด๋ณด๊ณ , drawer Content๋ค๋ ์ถ๊ฐํด๋ณด์
class SideDrawer extends Component {
render() {
return (
<View style={styles.container}>
<ScrollView>
<View>
<View style={styles.imageContainer}>
<Image
source={Logo}
style={{width: 40, height: 40}}
/>
</View>
</View>
</ScrollView>
</View>
)
}
}
- rendering๋๋ ๊ณณ์ <ScrollView> - <Image> ํ๊ทธ ์์ ์ฌ์ง์ source ๋ถ๋ฌ์ค๊ธฐ
- ์๋ก์ด ํ๊ทธ ๋ง๋ค์ด Content ์ถ๊ฐํ๊ธฐ
<Text style={styles.sectionHeading}>Section 1</Text>
<View style={styles.navSectionStyle}>
<Text style={styles.navItemStyle}>Home</Text>
<Text style={styles.navItemStyle}>User</Text>
<Text style={styles.navItemStyle}>Help</Text>
<Text style={styles.navItemStyle}>Info</Text>
</View>
* Content ๋๋ฅด๋ฉด ํด๋น ์คํฌ๋ฆฐ์ผ๋ก ๋์ด๊ฐ๋๋ก ํ์
-> onPress ์์ฑ ์ด์ฉ
import { CommonActions } from '@react-navigation/native';
- CommonActions
navigateToScreen = (route) => () => {
this.props.navigation.dispatch(
CommonActions.navigate({
name: route,
params: {},
})
)
}
- ์ฌ๋ฌ action creaters๋ฅผ ์ฐ๊ฒ ๋์์ค
- ๊ทธ ์ค navigation๋ผ๋ ction์ ํน์ ๋ฃจํธ๋ก ์ด๋ํ๊ฒ๋ ๋์์ฃผ๋ ction์ด๊ณ ,
์ด action์ด ๋ฐ์ํ๊ฒ ๋๋ฉด, dispatch๋ฅผ ํตํด state ๊ฐ์ ์ ๋ฐ์ดํธ ์์ผ์ค๋ค.
- arrow function์ด 2๊ฐ ํ์ํ๋ค. ==> return ๊ฐ๋ 2๊ฐ๋ค.
- ์ค๊ดํธ ์์ ๊ฐ์ returnํ๋ ํจ์๋ฅผ ๋ return ๊ฐ์ผ๋ก ๋ฐ์์ด
<View style={styles.navSectionStyle}>
<Text
style={styles.navItemStyle}
onPress={this.navigateToScreen('Home')}
>
Home
</Text>
- Screen์ด๋์ ์ํด Home๊ณผ User์ ์ด๋ ๊ฒ ์คํ์ผ์ ์ฃผ๊ณ ,
<Text
style={styles.navItemStyle}
onPress={()=>alert('Help Window')}
>
Help
</Text>
- alert ์ฐฝ์ ๋์ฐ๊ธฐ ์ํ Help์ Info๋ ์ด๋ ๊ฒ ์คํ์ผ์ ์ค๋ค.
'Computer ๐ป > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React-Native] Tab | Style ์ค์ (0) | 2021.07.31 |
---|---|
[React-Native] Tab | ์ค์น ๋ฐ ํ๋ฉด Linking (0) | 2021.07.31 |
[React-Native] Drawer | Style ์ค์ 02 (0) | 2021.07.29 |
[React-Native] Drawer | Style ์ค์ 01 (0) | 2021.07.29 |
[React-Native] Drawer | ์ค์น ๋ฐ ํ๋ฉด Linking (0) | 2021.07.29 |