Skip to content

Commit

Permalink
[Navigator] Pass route into onItemRef
Browse files Browse the repository at this point in the history
The index alone isn't so useful; pass the route as well. (I am using this to implement componentWill/DidFocus in a library instead of onWill/DidFocus).

Test Plan: Set up a navigator with a couple of scenes, and see that when onItemRef is called for each one, the route is passed in as the third argument.
  • Loading branch information
ide committed May 8, 2015
1 parent 41612f3 commit a2975f4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Libraries/CustomComponents/Navigator/Navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ var Navigator = React.createClass({
onDidFocus: PropTypes.func,

/**
* Will be called with (ref, indexInStack) when the scene ref changes
* Will be called with (ref, indexInStack, route) when the scene ref changes
*/
onItemRef: PropTypes.func,

Expand Down Expand Up @@ -1159,13 +1159,13 @@ var Navigator = React.createClass({
return this.state.routeStack;
},

_handleItemRef: function(itemId, ref) {
_handleItemRef: function(itemId, route, ref) {
this._itemRefs[itemId] = ref;
var itemIndex = this.state.idStack.indexOf(itemId);
if (itemIndex === -1) {
return;
}
this.props.onItemRef && this.props.onItemRef(ref, itemIndex);
this.props.onItemRef && this.props.onItemRef(ref, itemIndex, route);
},

_cleanScenesPastIndex: function(index) {
Expand Down Expand Up @@ -1273,7 +1273,7 @@ var Navigator = React.createClass({
}}
style={[styles.baseScene, this.props.sceneStyle, disabledSceneStyle]}>
{React.cloneElement(child, {
ref: this._handleItemRef.bind(null, this.state.idStack[i]),
ref: this._handleItemRef.bind(null, this.state.idStack[i], route),
})}
</View>
);
Expand Down

0 comments on commit a2975f4

Please sign in to comment.