Merge pull request #26714 from osdiab/osdiab/bugfix/react-navigation/withNavigation-onRef

[react-navigation] Update withNavigation types, add test
This commit is contained in:
Nathan Shively-Sanders
2018-06-22 09:23:29 -07:00
committed by GitHub
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -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; }}
/>;