Merge pull request #26629 from iRoachie/react-navigation

(react-navigation) Allow setParams to be partial
This commit is contained in:
Nathan Shively-Sanders
2018-06-18 09:53:32 -07:00
committed by GitHub
2 changed files with 26 additions and 1 deletions

View File

@@ -576,7 +576,7 @@ export interface NavigationScreenProp<S, P = NavigationParams> {
closeDrawer: () => any;
toggleDrawer: () => any;
getParam: <T extends keyof P>(param: T, fallback?: P[T]) => P[T];
setParams: (newParams: P) => boolean;
setParams: (newParams: Partial<P>) => boolean;
addListener: (
eventName: string,
callback: NavigationEventCallback

View File

@@ -489,3 +489,28 @@ const CustomHeaderStack = createStackNavigator({
}
}
});
interface ScreenProps {
name: string;
onPlay(): void;
}
class SetParamsTest extends React.Component<NavigationScreenProps<ScreenProps>> {
componentDidMount() {
this.props.navigation.setParams({
onPlay: this.onPlay
});
}
onPlay = () => {
//
}
render() {
const name = this.props.navigation.getParam('name');
return (
<Text>My name is {name}</Text>
);
}
}