์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- ๋ฅ๋ฌ๋
- Git
- ์๊ณ ๋ฆฌ์ฆ
- nlp
- linearalgebra
- ์ํ์ฝ๋ฉ
- cs231n
- AI
- Kaggle
- ๋ฆฌ์กํธ
- react
- ํ์ดํ๋
- ์ ํ๋์ํ
- c++
- ๊ฒฐ์ ํธ๋ฆฌ
- ๋จธ์ ๋ฌ๋
- ๋ฐฑ์ค
- ๊นํ
- ๋ฐ์ดํฐ๋ถ์
- ๋ค์ดํฐ๋ธ
- ๋ฐ์ดํฐ์๊ฐํ
- ๋ฐ์ดํฐ
- ๋์
- Titanic
- ์ธํ๋ฐ
- ์๋๋ก์ด๋์คํ๋์ค
- native
- ํ๊ตญ์ด์๋ฒ ๋ฉ
- ๋ถ์
- ์๋ฒ ๋ฉ
- Today
- Total
yeon's ๐ฉ๐ป๐ป
[React-Native] Stack | Header Bar ์ปค์คํฐ๋ง์ด์ง & ๋ฒํผ ์ถ๊ฐ ๋ณธ๋ฌธ
[React-Native] Stack | Header Bar ์ปค์คํฐ๋ง์ด์ง & ๋ฒํผ ์ถ๊ฐ
yeon42 2021. 7. 28. 23:39pictogram free
์ ์ฌ์ดํธ์์ ์๋ฌด ์ฌ์ง ํ๋ ๋ค์ด๋ก๋ ๋ฐ์ src/assets/pics ํด๋์ ์ฝ์
logoTitle = () => {
return (
<Image
style={{width: 40, height: 40}}
source={require('./src/assets/pics/ํ์ผ์ด๋ฆ.png')}
/>
)
}
- ํ์ผ source๋ฅผ inline์ผ๋ก ๋ฐ์์ฌ ๋๋ require() ์ฌ์ฉ
- ์ฝ๋ ๋ ๊น๋ํ๊ฒ ์์ฑํ๊ณ ์ถ๋ค๋ฉด?
-> ๋ฐ๋ก ํด๋์ค ์ ์ํ๊ธฐ
- ์ฐ๋ฆฌ๋ logo.js๋ผ๋ ํ์ผ์ ๋ง๋ค์ด LogoTitle๋ผ๋ ํด๋์ค๋ฅผ ์์ฑํด import ํด์๋ค.
- App.js์์ headerTitle์ <LogoTitle/>๋ก ๋ณ๊ฒฝํ๋ฉด ๋๊ฐ์ ๊ฒฐ๊ณผ !
- User Screen์์ Back ๋ฒํผ์ ์ด๋ฏธ์ง๊ฐ ์๋ Text๋ฅผ ์ ๋ ฅํ๊ณ ์ถ๋ค๋ฉด?
headerBackTitle: 'BACK'
- UserScreen ํด๋์ค ์์ headerStyle()์ headerBackTitle ์ฝ์
render() {
this.headerStyle();
- ์๋ render()์์ ์ ์ฝ๋ ์ฃผ์ ํด์ง
- BACK ํ ์คํธ ์์ฑ๋จ
- Home Screen์ ๋ฒํผ์ ์ถ๊ฐํด๋ณด์
import { StyleSheet, View, Text, Image, Button } from 'react-native';
- Button ์ฝ์ ์ ์ํ ํด๋์ค import
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
title: 'Home Screen',
headerTitle: <LogoTitle/>,
headerRight: () => (
<Button
title="Info"
onPress={()=>alert('I am a button!!')}
color='orange'
/>
)
}}
/>
- <Stack.Screen> ์ฝ๋ ์์ headerRight ์์ฑ ์ฝ์
- ์ผ๋จ ์ ๋์ํ๋์ง alert ๋์๋ณด๊ธฐ
- ์ค๋ฅธ์ชฝ(headerRight)์ Info๋ผ๋ ๋ฒํผ์ด ์๊ฒผ๊ณ , ํด๋ฆญํ์ ๋ alert ์ฐฝ์ด ์ ๋ฌ๋ค !
- User Screen์๋ ๋ฒํผ ์ถ๊ฐํด๋ณด๊ธฐ
headerBackTitle: 'BACK',
headerRight: () => (
<Button
title="Go Back"
onPress={()=>{
this.props.navigation.navigate('Home')
}}
color='orange'
/>
)
- ๋ง์ฐฌ๊ฐ์ง๋ก headerStyle() ํจ์ ์์ ์์ฑ
- ํ๋ฉด์ ์ด๋ํ๋ ์ด๋ฒคํธ(ํจ์) ์์ฑํด๋ณด์
- User Screen์์ ์ฐ์ธก ์๋จ(headerRight)์ Go Back ๋ฒํผ์ ๋๋ฅด๋ฉด Home Screen์ผ๋ก ์ด๋ํ๋ค.
* ์ข์ธก์ BACK ๋ฒํผ
- default๋ก ์์ฑ๋๋ ๋ฐฑ๋ฒํผ
- ์ ๋ง๋ก ๊ทธ ๋จ๊ณ๋ก ๋์๊ฐ๊ธฐ
* ์ฐ์ธก์ Go Back ๋ฒํผ
- ์ฐ๋ฆฌ๊ฐ ๋ง๋ ๋ฒํผ
- navigate ํจ์๋ฅผ ํตํด hoem ํ๋ฉด์ผ๋ก ๊ฐ๊ฒ ๋ง๋๋ ๊ฒ
-> ์ฌ๋ฌ ๊ฐ์ ํ๋ฉด์ ๊ฐ์ง๋ค๋ฉด, ๋ค๋ฅธ ํน์ screen์ผ๋ก ์ด๋ํ ์ ์์ ๊ฒ์ด๋ค !
'Computer ๐ป > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React-Native] Drawer | Style ์ค์ 01 (0) | 2021.07.29 |
---|---|
[React-Native] Drawer | ์ค์น ๋ฐ ํ๋ฉด Linking (0) | 2021.07.29 |
[React-Native] Stack | ์ฌ๋ฌ ํ๋ฉด์ ๊ณตํต Style ์ ์ฉ (0) | 2021.07.28 |
[React-Native] Stack | Header Bar ์ค์ (0) | 2021.07.27 |
[React-Native] Stack | Navigation Params (0) | 2021.07.27 |