[Navigator] Pass route into onItemRef

Summary:
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; #1153).

Closes https://github.com/facebook/react-native/pull/1154
Github Author: James Ide <ide@jameside.com>

@public

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.
This commit is contained in:
James Ide 2015-05-12 15:28:58 -07:00 коммит произвёл Christopher Chedeau
Родитель 1a68585990
Коммит 6a699302c8
1 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -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,
@ -1181,13 +1181,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) {
@ -1296,7 +1296,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>
);