๋๋ ๋ชจ๋ฌ์ ๋ํ ๋ฌธ์๊ฐ ์๊ณ ์์ ์ ํน์ ์ฅ๋ฉด์ด ๋ชจ๋ฌ๋ก ํ์๋๊ณ ๋ค๋ฅธ ์ฅ๋ฉด์ด ํ์๋์ง ์๋ ๋ฐฉ๋ฒ์ ๋ํ ์ค๋ช ์ด๋ ํ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋ชจ๋ฌ์ ์ฌ์ฉํ๋ ๋ฐ ์ ๋ง ์ด๋ ค์์ ๊ฒช๊ณ ์์ต๋๋ค. ์ฌ๊ธฐ ๋ด ์ฝ๋๊ฐ ์์ต๋๋ค.
<Router>
<Scene key="root" hideNavBar hideTabBar>
<Scene key="tabBar" tabs>
<Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
<Scene key="favorites" component={Favorites} title="Favorites" />
<Scene key="messages" component={Messages} title="Messages" />
<Scene key="profile" component={Profile} title="Profile" />
</Scene>
<Scene key="modal" modal>
<Scene key="map" component={Map} title="Map" hideNavBar />
</Scene>
<Scene key="listingDetail" component={ListingDetail} title="Listing Detail" clone />
</Scene>
</Router>;
Map ๊ตฌ์ฑ ์์๊ฐ ๋ชจ๋ฌ๋ก ํ์๋๋๋ก ํ๋ ค๊ณ ํฉ๋๋ค.
MapButton
๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
const MapButton = () =>
<TouchableWithoutFeedback onPress={Actions.map}>
<Text>Map</Text>
</TouchableWithoutFeedback>;
rightText๊ฐ ๋งค์ฐ ๋ฒ๊ทธ๊ฐ ๋ง๊ณ ์ ๋ฐ์ ์๊ฐ์ ๋ ๋๋งํ์ง ์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
root
์ฅ๋ฉด์ ๋ชจ๋ฌ ์์ ๋ฃ์ด๋ณด์ญ์์ค.
์ด์ ๊ฐ์ด:
<Router>
<Scene key="modal" modal>
<Scene key="root" hideNavBar hideTabBar>
<Scene key="tabBar" tabs>
<Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
<Scene key="favorites" component={Favorites} title="Favorites" />
<Scene key="messages" component={Messages} title="Messages" />
<Scene key="profile" component={Profile} title="Profile" />
</Scene>
</Scene>
<Scene key="map" component={Map} title="Map" hideNavBar />
@luco ๊ฐ ์ ์ํ ๊ฒ์ฒ๋ผ ๋ฃจํธ ์ฅ๋ฉด์ modal
๋ก ๋ง๋ค์ด์ผ ํฉ๋๋ค. ์์ ํ๋ก์ ํธ๋ฅผ ํ์ธํ์ญ์์ค. ๋ก๊ทธ์ธ์ ๋ชจ๋ฌ๋ก ๊ตฌํ๋ฉ๋๋ค.
์ด๊ฒ์ ์ฌ์ ํ โโ์๋ํ์ง ์์ต๋๋ค.
<Router>
<Scene key="modal" modal>
<Scene key="root" hideNavBar hideTabBar>
<Scene key="tabBar" tabs>
<Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
<Scene key="favorites" component={Favorites} title="Favorites" />
<Scene key="messages" component={Messages} title="Messages" />
<Scene key="profile" component={Profile} title="Profile" />
</Scene>
<Scene key="map" component={Map} title="Map" hideNavBar />
<Scene key="listingDetail" component={ListingDetail} title="Listing Detail" clone />
</Scene>
</Scene>
</Router>
๋๋จธ์ง(ListingDetail ๊ฐ์)๊ฐ ๋ชจ๋ฌ์ด ๋๋ ๊ฒ์ ์ํ์ง ์์ ๋ ๋ชจ๋ฌ ์ฅ๋ฉด์ ๋ชจ๋ ๊ฒ์ ๋ํํ๋ฉด ํ๋์ ํน์ ์ฅ๋ฉด ์ด ๋ชจ๋ฌ์ด ๋๋ค๋ ๊ฒ์ ์๋ฏธ๊ฐ ์์ต๋๋ค. Actions.map
์ ์ฌ์ฉํด์ผ ํ๋ ํน์ ๋งค๊ฐ๋ณ์๊ฐ ์์ต๋๊น?
๋ถํํ๋ ๋ฐ์ ํ์์ ๋ฌธ์ ์ ๋๋ค. ์คํ ์์์ ๋ํด ๋ค๋ฅธ ์ ๋๋ฉ์ด์ ์ ์ง์ํ์ง ์์ต๋๋ค. ๋๋ ๋น์ ์ ๋ฌธ์ ๋ฅผ ์ฌํํ ์ ์์ต๋๋ค(์ฝ๋๋ ๊ด์ฐฎ์ ๋ณด์ ๋๋ค). ๊ทธ๋์ ๋ชจ๋ ์ฌ๋๋ค์๊ฒ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๊ธฐ๋ฅผ ์ํ๋ ๊ฒฝ์ฐ ์ด ๋ฆฌํฌ์งํ ๋ฆฌ ์์ ๋ฅผ ๋ถ๊ธฐํ๊ณ ์์ ํ๋๋ก ์์ฒญํฉ๋๋ค. ์์ ์ ๋ก๊ทธ์ธ ๋ชจ๋ฌ์ ๋ณด์๋ค์ํผ ์ ์๋ํฉ๋๋ค.
๋ชจ๋ฌ iOS ์ ํ์ ์ง์ํ ๋ฐฉ๋ฒ์ด ์๋ค๋ ๋ง์์ด์ ๊ฐ์? ์ฆ, ์๋์์ ๋ฏธ๋๋ฌ์ง๋ ํ๋?
๋ฌด์จ ๋ป์ด์์? ๋๋ Example์ ๋ชจ๋ฌ ๋ก๊ทธ์ธ ํ๋ฉด์ด ์๋ค๊ณ ๋ ๋ฒ ๋งํ์ต๋๋ค(ํ๋จ์์ ์ฌ๋ผ์ด๋)
์ข์, ํ์ง๋ง ๋น์ ์ ๋ํ ๋ด ์ฝ๋๊ฐ ๊ด์ฐฎ์ ๋ณด์ธ๋ค๊ณ ๋งํ๋ค....
๋๋ ์์ ๋ฅผ ๋ฐ๋ฅด๊ธฐ ์ํด ์ต์ ์ ๋คํ์ง๋ง ๋ฌธ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋ชจ๋ ๊ฒ์ด ๊ฑฐ๊ธฐ์ ์๋ ์ด์ ๋ฅผ ๋งํ ์ ์์ต๋๋ค. ๋ถ๋ช ํ ๋ด ๊ฒฝ๋ก๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ํด๋น ์ฝ๋๋ฅผ ๋ณต์ฌํ์ฌ ๋ถ์ฌ ๋ฃ์ ์ ์์ต๋๋ค.
๊ทํ์ ์ฝ๋์ ๋ํด ๋ง์๋๋ฆด ์ ์๋ ๊ฒ๊ณผ ๋์ผํฉ๋๋ค. ์ ์ฒด ํ๋ก์ ํธ์ ๋ชจ๋ ์ธ๋ถ์ฌํญ์ ๋ณผ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด Actions.map
๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ ์ปดํ์ผํ๋ ๋์ ์์ฑ๋์ง ์๊ณ null์ด ๋ ์๋ ์์ต๋๋ค.
ํ์ํ ๊ฒ์ด ๋ฌด์์ธ์ง ์๋ ค์ฃผ์๋ฉด ๋ ๋ง์ ์ฝ๋ ์ํ์ ์ ๊ณตํด ๋๋ฆฌ๊ฒ ์ต๋๋ค. Actions.map
์๋ํฉ๋๋ค. ์๋์ชฝ์์ ์์ํ๋ ๊ฒ์ ์์ชฝ์์ ๊ทธ๋ฅ ์ ํ๋ฉ๋๋ค.
๋์ผํ ์ฑ์์ push
๋ฐ modal
์ ํ์ ๋ชจ๋ ๊ฐ์ง ์ ์๋ค๋ ๋ง์์ด์ ๊ฐ์?
์ด๋จธ๋. ์ฑ์ด ์๋๋ผ ํ๋์ ์ปจํ ์ด๋์ ์์ต๋๋ค. ๋ ์์ธํ ์ดํด๋ณด๋ฉด ์ฝ๋์ ์ค๋ฅ๊ฐ ์์ต๋๋ค. 'map'์ ์ฌ์ ํ โโ๋ชจ๋ฌ(key='modal')์ด ์๋ '์ผ๋ฐ' ์ปจํ ์ด๋(key=root)์ ์์์ ๋๋ค. ๋น์ ์ดํ๋ ์ผ์ ์ดํดํ์ง ๋ชปํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด์ฉ๋ฉด ์ด ๊ตฌ์ฑ ์์๊ฐ ๋น์ ์๊ฒ ๋๋ฌด ๋ณต์กํ ์๋ ์์ต๋๋ค...
์ด ์๋:
<Router>
<Scene key="modal" modal>
<Scene key="root" hideNavBar hideTabBar>
<Scene key="tabBar" tabs>
<Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
<Scene key="favorites" component={Favorites} title="Favorites" />
<Scene key="messages" component={Messages} title="Messages" />
<Scene key="profile" component={Profile} title="Profile" />
</Scene>
</Scene>
<Scene key="map" component={Map} title="Map" hideNavBar />
<Scene key="listingDetail" component={ListingDetail} title="Listing Detail" clone />
</Scene>
</Router>
๋๋ถ์ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค. ๊ด๋ จ ๋ฌธ์๊ฐ ์๋๋ฐ ๋ด๊ฐ ์ด๋ป๊ฒ ์ดํดํ๊ธฐ๋ฅผ ๊ธฐ๋ํฉ๋๊น? ์ด ๋ชจ๋ฌ ๊ธฐ๋ฅ์ ๋ํด ๋ง์ ์ฌ๋๋ค์ด ๋ฌธ์ ๋ฅผ ์ ๊ธฐํด ์์ผ๋ฉฐ ์๋ง๋ ๋ฌธ์์ ํ์์ฑ์ ๋ํ๋ด๋ ๊ฒ์ผ ์ ์์ต๋๋ค.
์ฌ๊ธฐ์ ์๋ ์ต๊ทผ ๊ฒ์๋ฌผ์ ๋ฌธ์๊ฐ ์๋๋ผ JSX ๊ตฌ๋ฌธ ๋ฐ ํ์ ์ปจํ
์ด๋์ ๋ํ ์ดํด์ ๊ดํ ๊ฒ์
๋๋ค.
๋ชจ๋ฌ์ ๋ํ ์ถ๊ฐ ์ ๋ณด๋ฅผ ์ถ๊ฐํ์ต๋๋ค.
์๋ ,
๋๋ฅผ ์ํด ์ผํ๋ค
<Router navigationBarStyle={{backgroundColor: '#FF5722'}} titleStyle={{color: '#fff'}}>
<Modal>
<Stack key="root">
<Scene key='login_screen' component={LoginScreen} title='login' hideNavBar={true} />
</Stack>
<Scene key='cadastro_screen' component={CadastroScreen} title='Cadastro' hideNavBar={false} />
</Modal>
</Router>
๋ชจ๋ฌ ๋ํผ๋ฅผ ์ถ๊ฐํ๋ฉด ๋ณด๊ธฐ ์๋จ์ 2๊ฐ์ ํ์ ๋ชจ์์ด ํ์๋๊ณ , hideNavBar๋ฅผ ์ถ๊ฐํ๋ฉด ๋ ๋ค ์ฌ๋ผ์ง๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ์ด๋ป๊ฒ ํด๊ฒฐํ ์ ์์ต๋๊น? ๋ถ๋ช ํ ํ๋์ ํญ ๋ง๋๊ฐ ์๋ ๋ ๊ฐ์ ํญ ๋ง๋๋ฅผ ์ํฉ๋๋ค... ?
<Modal hideNavBar>
์ฌ์ฉํ๋ฉด $# <Modal>
์์ฒด ํ์ ๋ชจ์์ด ์ถ๊ฐ๋๋ฏ๋ก ๋ฃจํธ ์ฅ๋ฉด์ ํ๋์ ํจ๊ป ๋ ๊ฐ๋ฅผ ๊ฐ๊ฒ ๋ฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ถ์ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค. ๊ด๋ จ ๋ฌธ์๊ฐ ์๋๋ฐ ๋ด๊ฐ ์ด๋ป๊ฒ ์ดํดํ๊ธฐ๋ฅผ ๊ธฐ๋ํฉ๋๊น? ์ด ๋ชจ๋ฌ ๊ธฐ๋ฅ์ ๋ํด ๋ง์ ์ฌ๋๋ค์ด ๋ฌธ์ ๋ฅผ ์ ๊ธฐํด ์์ผ๋ฉฐ ์๋ง๋ ๋ฌธ์์ ํ์์ฑ์ ๋ํ๋ด๋ ๊ฒ์ผ ์ ์์ต๋๋ค.