mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 08:05:34 +00:00
[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:
parent
1a68585990
commit
6a699302c8
@ -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>
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user