Skip to content

Commit b9bc386

Browse files
wschurmansatya164
authored andcommitted
Pass through screenProps to nested navigators
This changes the behaviour of screenProps so that the props no longer get splatted. Components will receive this as `this.props.screenProps`.
1 parent 797833a commit b9bc386

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

docs/api/navigators/DrawerNavigator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ The navigator component created by `DrawerNavigator(...)` takes the following pr
130130
});
131131

132132
<DrawerNav
133-
screenProps={/* these will get passed to the screen components */}
133+
screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
134134
/>
135135
```

docs/api/navigators/StackNavigator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ The navigator component created by `StackNavigator(...)` takes the following pro
139139
});
140140

141141
<SomeStack
142-
screenProps={/* these will get passed to the screen components */}
142+
screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
143143
/>
144144
```
145145

docs/api/navigators/TabNavigator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ The navigator component created by `TabNavigator(...)` takes the following props
162162
});
163163

164164
<TabNav
165-
screenProps={/* these will get passed to the screen components */}
165+
screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
166166
/>
167167
```
168168

src/views/SceneView.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import type {
1111

1212
type Props = {
1313
screenProps?: {};
14+
hideScreenPropsWarning?: boolean;
1415
navigation: NavigationScreenProp<NavigationState, NavigationAction>;
1516
component: ReactClass<*>;
1617
};
1718

1819
export default class SceneView extends PureComponent<void, Props, void> {
19-
2020
static childContextTypes = {
2121
navigation: React.PropTypes.object.isRequired,
2222
};
@@ -29,8 +29,30 @@ export default class SceneView extends PureComponent<void, Props, void> {
2929
};
3030
}
3131

32+
componentWillMount() {
33+
if (this.props.screenProps !== undefined && !this.props.hideScreenPropsWarning) {
34+
console.warn(
35+
'Behaviour of screenProps has changed from initial beta. ' +
36+
'Components will now receive it as `this.props.screenProps` instead.\n' +
37+
'Pass `hideScreenPropsWarning` to hide this warning.'
38+
);
39+
}
40+
}
41+
3242
render() {
33-
const { screenProps, navigation, component: Component } = this.props;
34-
return <Component {...screenProps} navigation={navigation} />;
43+
const {
44+
hideScreenPropsWarning,
45+
screenProps,
46+
navigation,
47+
component: Component,
48+
} = this.props;
49+
50+
return (
51+
<Component
52+
hideScreenPropsWarning={hideScreenPropsWarning}
53+
screenProps={screenProps}
54+
navigation={navigation}
55+
/>
56+
);
3557
}
3658
}

0 commit comments

Comments
 (0)