This is one of the great navigation library, just with too little doc on customization, and unfortunately tab is one of them.
<Scene key="myTabBar" tabs={true} hideNavBar tabBarStyle={style.tabBarStyle}>
<Scene
key="myTab"
title="My Tab"
icon={MyTabIcon}
>
<Scene key="myTab_1" component={MyTabComponent} />
<Scene key="myTab_2" component={MyTabComponent} />
</Scene>
</Scene>
Reference
In the following, Tab refer to <Scene> with icon , Child refer to <Scene> wrapped by Tab
Tabtree/tabbar refer to Tab's parent <Scene> with tabs=true: <Scene tabs=true>...</Scene>
Tabmust has at least 1Childto enable its own navigation stack- Default Actions' behaviour (or scene type) of
TabisJUMP - If you want to intercrept
Tabtapping or changing the default behaviour, write your ownonPressfunction
<Scene
key="myTab"
title="My Tab"
icon={MyTabIcon}
onPress={()=> {
...
}}
>
- You should call the the
Tabkey inActions.KEYin order triggerJUMPbehaviour when using your ownonPressfunction or from elsewhere, notChildkey. (See inner routing)
Actions.myTab({propsToPass})
- To "reset" the
Tab's history and back to the firstChild, use
Actions.myTab_1({type: ActionConst.PUSH_OR_POP, refresh:{propsToPass} });
- To reuse scenes in tab, put them outside the
Tabbar, with propsclone=true
//under same root
<Scene key="myTabBar" tabs={true} hideNavBar tabBarStyle={style.tabBarStyle}>
<Scene
key="myTab"
title="My Tab"
icon={MyTabIcon}
onPress={()=> {
Actions.myTab_1({type: ActionConst.REFRESH});
}}
>
<Scene key="myTab_1" component={MyTabComponent} hideNavBar/>
</Scene>
</Scene>
<Scene key="info" clone ... />
- No RNRF lifecycle method is called during switching to mounted tab except props changed.
- no
componentWillUnmount()called by RNRF - no
componentWillMount()will be called again by RNRF - no
componentDidMount()will be called again by RNRF - At most of the time
constructor()will be called only when new instance is created (first load or clonable scene)
- no
- Do something onMount or unMount of
Child=> seek alternative - Intercept => See Detailed Example) for reducer demo
- Different OS tab behaviour:
- iOS: static tabbar, tab switching will not destroy the navigation stack and scroll position, but tapping the icon will reset the navigation stack
- Andriod: tabbar may hide (TBC)
could you please tell me how to get a navbar and tabs at the same time on same page