mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge pull request #26714 from osdiab/osdiab/bugfix/react-navigation/withNavigation-onRef
[react-navigation] Update withNavigation types, add test
This commit is contained in:
Vendored
+1
-1
@@ -1162,7 +1162,7 @@ export interface NavigationInjectedProps {
|
||||
|
||||
export function withNavigation<T = {}>(
|
||||
Component: React.ComponentType<T & NavigationInjectedProps>
|
||||
): React.ComponentType<T>;
|
||||
): React.ComponentType<T & { onRef?: React.Ref<typeof Component> }>;
|
||||
|
||||
export function withNavigationFocus<T = {}>(
|
||||
Component: React.ComponentType<T & NavigationInjectedProps>
|
||||
|
||||
@@ -40,6 +40,8 @@ import {
|
||||
NavigationPopToTopAction,
|
||||
NavigationScreenComponent,
|
||||
NavigationContainerComponent,
|
||||
withNavigation,
|
||||
NavigationInjectedProps,
|
||||
} from 'react-navigation';
|
||||
|
||||
// Constants
|
||||
@@ -514,3 +516,19 @@ class SetParamsTest extends React.Component<NavigationScreenProps<ScreenProps>>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Test withNavigation
|
||||
|
||||
interface BackButtonProps { title: string; }
|
||||
class MyBackButton extends React.Component<BackButtonProps & NavigationInjectedProps> {
|
||||
render() {
|
||||
return <button title={this.props.title} onClick={() => { this.props.navigation.goBack(); }} />;
|
||||
}
|
||||
}
|
||||
|
||||
// withNavigation returns a component that wraps MyBackButton and passes in the
|
||||
// navigation prop
|
||||
const BackButtonWithNavigation = withNavigation<BackButtonProps>(MyBackButton);
|
||||
const BackButtonInstance = <BackButtonWithNavigation
|
||||
title="Back" onRef={ref => { const backButtonRef = ref; }}
|
||||
/>;
|
||||
|
||||
Reference in New Issue
Block a user