mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
Merge pull request #26629 from iRoachie/react-navigation
(react-navigation) Allow setParams to be partial
This commit is contained in:
2
types/react-navigation/index.d.ts
vendored
2
types/react-navigation/index.d.ts
vendored
@@ -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
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user