Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Add onWillFocus and onDidFocus props. #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,32 @@ var {
Navigator,
StatusBarIOS,
View,
PropTypes,
} = React;


var Router = React.createClass({
propTypes: {
onWillFocus: PropTypes.func,
onDidFocus: PropTypes.func,
customAction: PropTypes.func,
hideNavigationBar: PropTypes.bool,
bgStyle: PropTypes.any,
statusBarColor: PropTypes.string,
headerStyle: PropTypes.any,
backButtonComponent: PropTypes.any,
rightCorner: PropTypes.any,
titleStyle: PropTypes.any,
firstRoute: PropTypes.object,
},

getDefaultProps: function() {
return {
onWillFocus: () => {},
onDidFocus: () => {},
hideNavigationBar: false,
}
},

getInitialState: function() {
return {
Expand All @@ -25,13 +47,18 @@ var Router = React.createClass({
}
},

/*
onWillFocus: function(route) {
this.props.onWillFocus(route);
},

/*
* This changes the title in the navigation bar
* It should preferrably be called for "onWillFocus" instad >
* > but a recent update to React Native seems to break the animation
*/
onDidFocus: function(route) {
this.setState({ route: route });
this.props.onDidFocus(route);
},

onBack: function(navigator) {
Expand Down Expand Up @@ -71,8 +98,8 @@ var Router = React.createClass({
var didStartDrag = function(evt) {
var x = evt.nativeEvent.pageX;
if (x < 28) {
this.setState({
dragStartX: x,
this.setState({
dragStartX: x,
didSwitchView: false
});
return true;
Expand Down Expand Up @@ -100,7 +127,7 @@ var Router = React.createClass({
if (this.props.hideNavigationBar) {
extraStyling.marginTop = 0;
}

return (
<View
style={[styles.container, this.props.bgStyle, extraStyling]}
Expand All @@ -118,7 +145,7 @@ var Router = React.createClass({
/>
</View>
)

},

render: function() {
Expand All @@ -133,10 +160,10 @@ var Router = React.createClass({
var navigationBar;

if (!this.props.hideNavigationBar) {
navigationBar =
navigationBar =
<NavBarContainer
style={this.props.headerStyle}
navigator={navigator}
navigator={navigator}
currentRoute={this.state.route}
backButtonComponent={this.props.backButtonComponent}
rightCorner={this.props.rightCorner}
Expand All @@ -153,6 +180,7 @@ var Router = React.createClass({
navigationBar={navigationBar}
renderScene={this.renderScene}
onDidFocus={this.onDidFocus}
onWillFocus={this.onWillFocus}
/>
)
}
Expand Down