Skip to content

Commit 65ecba7

Browse files
author
aksonov
committed
allow to hide navbar, avoid scene type inheritance
1 parent b86a3b8 commit 65ecba7

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

Example/components/TabView.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,24 @@ const styles = StyleSheet.create({
2222
});
2323

2424
class TabView extends React.Component {
25+
state = { hideNavBar: false }
26+
27+
toggleNavBar = () => {
28+
this.setState({ hideNavBar: !this.state.hideNavBar }, () =>
29+
Actions.refresh({ hideNavBar: this.state.hideNavBar })
30+
);
31+
}
32+
2533
render() {
2634
return (
2735
<View style={[styles.container, this.props.sceneStyle]}>
2836
<Text>Tab title:{this.props.title} name:{this.props.name}</Text>
2937
<Text>Tab data:{this.props.data}</Text>
30-
{this.props.name === 'tab1_1' &&
31-
<Button onPress={() => Actions.tab1_2()}>next screen for tab1_1</Button>
38+
{this.props.name === 'tab_1_1' &&
39+
<Button onPress={() => Actions.tab_1_2()}>next screen for tab1_1</Button>
3240
}
3341
{this.props.name === 'tab_2_1' &&
34-
<Button onPress={() => Actions.tab_2_2()}>next screen for tab2_1</Button>
42+
<Button onPress={() => Actions.tab_2_2()}>next screen for tab2_1</Button>
3543
}
3644
<Button onPress={Actions.pop}>Back</Button>
3745
<Button onPress={() => { Actions.tab_1(); }}>Switch to tab1</Button>
@@ -40,6 +48,7 @@ class TabView extends React.Component {
4048
<Button onPress={() => { Actions.tab_4(); }}>Switch to tab4</Button>
4149
<Button onPress={() => { Actions.tab_5({ data: 'test!' }); }}>Switch to tab5 with data</Button>
4250
<Button onPress={() => { Actions.echo(); }}>push clone scene (EchoView)</Button>
51+
<Button onPress={() => { this.toggleNavBar(); }}>Toggle NavBar</Button>
4352
</View>
4453
);
4554
}

dist/navigationStore.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ res.tabBarVisible=false;
214214
res.tabBarVisible=false;
215215
}
216216

217-
if(hideNavBar){
217+
if(navigationParams.hideNavBar!=null){
218+
if(navigationParams.hideNavBar){
219+
res.header=null;
220+
}
221+
}else if(hideNavBar){
218222
res.header=null;
219223
}
220224

@@ -304,17 +308,17 @@ this.ref=ref;
304308
{
305309
var navigation=this.props.navigation;
306310
if(!navigation||!navigation.state){
307-
return _react2.default.createElement(Component,_extends({ref:this.onRef},this.props,{__source:{fileName:_jsxFileName,lineNumber:307}}));
311+
return _react2.default.createElement(Component,_extends({ref:this.onRef},this.props,{__source:{fileName:_jsxFileName,lineNumber:311}}));
308312
}
309-
return _react2.default.createElement(Component,_extends({ref:this.onRef},this.props,extendProps(navigation.state.params,store),{name:navigation.state.routeName,__source:{fileName:_jsxFileName,lineNumber:309}}));
313+
return _react2.default.createElement(Component,_extends({ref:this.onRef},this.props,extendProps(navigation.state.params,store),{name:navigation.state.routeName,__source:{fileName:_jsxFileName,lineNumber:313}}));
310314
}}]);return Wrapped;}(_react2.default.Component),_class.propTypes={navigation:_propTypes2.default.object},_temp);
311315

312316
return wrapper(Wrapped);
313317
}
314318

315319

316320
function StatelessWrapped(_ref5){var navigation=_ref5.navigation,props=_objectWithoutProperties(_ref5,['navigation']);
317-
return _react2.default.createElement(Component,_extends({},props,{navigation:navigation},extendProps(navigation.state.params,store),{name:navigation.state.routeName,__source:{fileName:_jsxFileName,lineNumber:317}}));
321+
return _react2.default.createElement(Component,_extends({},props,{navigation:navigation},extendProps(navigation.state.params,store),{name:navigation.state.routeName,__source:{fileName:_jsxFileName,lineNumber:321}}));
318322
}
319323
StatelessWrapped.propTypes={
320324
navigation:_propTypes2.default.object};
@@ -413,7 +417,7 @@ delete commonProps.children;
413417
delete commonProps.component;
414418

415419
for(var _iterator4=Object.keys(commonProps),_isArray4=Array.isArray(_iterator4),_i5=0,_iterator4=_isArray4?_iterator4:_iterator4[typeof Symbol==='function'?typeof Symbol==='function'?typeof Symbol==='function'?Symbol.iterator:'@@iterator':'@@iterator':'@@iterator']();;){var _ref7;if(_isArray4){if(_i5>=_iterator4.length)break;_ref7=_iterator4[_i5++];}else{_i5=_iterator4.next();if(_i5.done)break;_ref7=_i5.value;}var pkey=_ref7;
416-
if(dontInheritKeys.includes(pkey)&&!parentProps[pkey]){
420+
if(dontInheritKeys.includes(pkey)&&(pkey==='type'||pkey==='hideNavBar'||!parentProps[pkey])){
417421
delete commonProps[pkey];
418422
}
419423
}
@@ -465,7 +469,7 @@ _this2.states[key].path=path;
465469

466470
var screen={
467471
screen:createWrapper(component,wrapBy,_this2)||_this2.processScene(_child,commonProps,clones)||lightbox&&_reactNative.View,
468-
navigationOptions:createNavigationOptions(_extends({},commonProps,getProperties(component),_child.props,{init:init,component:component}))};
472+
navigationOptions:createNavigationOptions(_extends({},commonProps,{hideNavBar:parentProps.hideNavBar},getProperties(component),_child.props,{init:init,component:component}))};
469473

470474

471475

@@ -476,7 +480,7 @@ wrapNavBar=false;
476480
if(component&&wrapNavBar){
477481
res[key]={
478482
screen:_this2.processScene({key:key,props:{children:{key:'_'+key,props:_extends({},_child.props,{wrap:false})}}},commonProps,clones,wrapBy),
479-
navigationOptions:createNavigationOptions(_extends({},commonProps,_child.props))};
483+
navigationOptions:createNavigationOptions(_extends({},commonProps,_child.props,{hideNavBar:true}))};
480484

481485
}else{
482486
res[key]=screen;
@@ -511,8 +515,8 @@ if(lightbox){
511515
return(0,_LightboxNavigator2.default)(res,_extends({mode:mode,initialRouteParams:initialRouteParams,initialRouteName:initialRouteName},commonProps,{navigationOptions:createNavigationOptions(commonProps)}));
512516
}else if(tabs){
513517
if(!tabBarComponent){
514-
tabBarComponent=tabBarPosition==='top'?function(props){return _react2.default.createElement(_reactNavigation.TabBarTop,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:514}}));}:
515-
function(props){return _react2.default.createElement(_reactNavigation.TabBarBottom,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:515}}));};
518+
tabBarComponent=tabBarPosition==='top'?function(props){return _react2.default.createElement(_reactNavigation.TabBarTop,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:518}}));}:
519+
function(props){return _react2.default.createElement(_reactNavigation.TabBarBottom,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:519}}));};
516520
}
517521
if(!tabBarPosition){
518522
tabBarPosition=_reactNative.Platform.OS==='android'?'top':'bottom';

src/navigationStore.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ function createNavigationOptions(params) {
214214
res.tabBarVisible = false;
215215
}
216216

217-
if (hideNavBar) {
217+
if (navigationParams.hideNavBar != null) {
218+
if (navigationParams.hideNavBar) {
219+
res.header = null;
220+
}
221+
} else if (hideNavBar) {
218222
res.header = null;
219223
}
220224

@@ -413,7 +417,7 @@ class NavigationStore {
413417
delete commonProps.component;
414418
// add inherit props
415419
for (const pkey of Object.keys(commonProps)) {
416-
if (dontInheritKeys.includes(pkey) && !parentProps[pkey]) {
420+
if (dontInheritKeys.includes(pkey) && (pkey === 'type' || pkey === 'hideNavBar' || !parentProps[pkey])) {
417421
delete commonProps[pkey];
418422
}
419423
}
@@ -465,7 +469,7 @@ class NavigationStore {
465469
// console.log(`KEY ${key} PATH ${path} DRAWER ${drawer} TABS ${tabs} WRAP ${wrap}`, JSON.stringify(commonProps));
466470
const screen = {
467471
screen: createWrapper(component, wrapBy, this) || this.processScene(child, commonProps, clones) || (lightbox && View),
468-
navigationOptions: createNavigationOptions({ ...commonProps, ...getProperties(component), ...child.props, init, component }),
472+
navigationOptions: createNavigationOptions({ ...commonProps, hideNavBar: parentProps.hideNavBar, ...getProperties(component), ...child.props, init, component }),
469473
};
470474

471475
// wrap component inside own navbar for tabs/drawer parent controllers
@@ -476,7 +480,7 @@ class NavigationStore {
476480
if (component && wrapNavBar) {
477481
res[key] = {
478482
screen: this.processScene({ key, props: { children: { key: `_${key}`, props: { ...child.props, wrap: false } } } }, commonProps, clones, wrapBy),
479-
navigationOptions: createNavigationOptions({ ...commonProps, ...child.props }),
483+
navigationOptions: createNavigationOptions({ ...commonProps, ...child.props, hideNavBar: true }),
480484
};
481485
} else {
482486
res[key] = screen;

0 commit comments

Comments
 (0)