Skip to content

Commit

Permalink
Merge pull request #2 from exponentjs/augment_scene_and_navigation_bar
Browse files Browse the repository at this point in the history
Add augmentScene and augmentNavigationBar methods
  • Loading branch information
James Ide committed Oct 7, 2015
2 parents 1779cdc + 96db52d commit d2f7520
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions ExNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ export default class ExNavigator extends React.Component {
titleStyle: Text.propTypes.style,
barButtonTextStyle: Text.propTypes.style,
barButtonIconStyle: Image.propTypes.style,
renderNavigationBar: PropTypes.func,
augmentScene: PropTypes.func,
};

static defaultProps = {
...Navigator.defaultProps,
showNavigationBar: true,
renderNavigationBar: props => {
return <Navigator.NavigationBar {...props} />
},
};

constructor(props, context) {
Expand All @@ -46,10 +52,6 @@ export default class ExNavigator extends React.Component {
});
}

get navigationContext() {
return this._navigator ? this._navigator.navigationContext : null;
}

render() {
return (
<Navigator
Expand All @@ -70,10 +72,13 @@ export default class ExNavigator extends React.Component {
// mounted because it emits a didfocus event when it is mounted, before we
// can get a ref to it
if (!this._subscribedToFocusEvents) {
this._subscribeToFocusEvents(this);
this._subscribeToFocusEvents(navigator);
}

let scene = this._routeRenderer.renderScene(route, this);
if (typeof this.props.augmentScene === 'function') {
scene = this.props.augmentScene(scene, route);
}
let firstRoute = navigator.getCurrentRoutes()[0];
if (route === firstRoute) {
scene = cloneReferencedElement(scene, {
Expand All @@ -88,12 +93,10 @@ export default class ExNavigator extends React.Component {
return null;
}

return (
<Navigator.NavigationBar
routeMapper={this._routeRenderer.navigationBarRouteMapper}
style={[ExNavigatorStyles.bar, this.props.navigationBarStyle]}
/>
);
return this.props.renderNavigationBar({
routeMapper: this._routeRenderer.navigationBarRouteMapper,
style: [ExNavigatorStyles.bar, this.props.navigationBarStyle],
});
}

@autobind
Expand Down Expand Up @@ -139,6 +142,10 @@ export default class ExNavigator extends React.Component {
return this._navigator.navigationContext;
}

get parentNavigator() {
return this._navigator.parentNavigator;
}

getCurrentRoutes() {
return this._navigator.getCurrentRoutes();
}
Expand Down

0 comments on commit d2f7520

Please sign in to comment.