Merge pull request #26916 from stigi/react-navigation-withNavigationFocus

[react-navigation] Fixing `withNavigationFocus` definition
This commit is contained in:
Paul van Brenk
2018-06-29 10:35:58 -07:00
committed by GitHub
2 changed files with 24 additions and 2 deletions
+6 -2
View File
@@ -18,6 +18,7 @@
// Edward Sammut Alessi <https://github.com/Slessi>
// Jérémy Magrin <https://github.com/magrinj>
// Luca Campana <https://github.com/TizioFittizio>
// Ullrich Schaefer <https://github.com/stigi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
@@ -1165,9 +1166,12 @@ export function withNavigation<T = {}>(
Component: React.ComponentType<T & NavigationInjectedProps>
): React.ComponentType<T & { onRef?: React.Ref<typeof Component> }>;
export interface NavigationFocusInjectedProps extends NavigationInjectedProps {
isFocused: boolean;
}
export function withNavigationFocus<T = {}>(
Component: React.ComponentType<T & NavigationInjectedProps>
): React.ComponentType<T>;
Component: React.ComponentType<T & NavigationFocusInjectedProps>
): React.ComponentType<T & { onRef?: React.Ref<typeof Component> }>;
/**
* SafeAreaView Component
@@ -42,6 +42,8 @@ import {
NavigationContainerComponent,
withNavigation,
NavigationInjectedProps,
withNavigationFocus,
NavigationFocusInjectedProps
} from 'react-navigation';
// Constants
@@ -532,3 +534,19 @@ const BackButtonWithNavigation = withNavigation<BackButtonProps>(MyBackButton);
const BackButtonInstance = <BackButtonWithNavigation
title="Back" onRef={ref => { const backButtonRef = ref; }}
/>;
// Test withNavigationFocus
interface MyFocusedComponentProps { expectsFocus: boolean; }
class MyFocusedComponent extends React.Component<MyFocusedComponentProps & NavigationFocusInjectedProps> {
render() {
return <button title={`${this.props.expectsFocus} vs ${this.props.isFocused}`} onClick={() => { this.props.navigation.goBack(); }} />;
}
}
// withNavigationFocus returns a component that wraps MyFocusedComponent and passes in the
// navigation and isFocused prop
const MyFocusedComponentWithNavigationFocus = withNavigationFocus<MyFocusedComponentProps>(MyFocusedComponent);
const MyFocusedComponentInstance = <MyFocusedComponentWithNavigationFocus
expectsFocus={true} onRef={ref => { const backButtonRef = ref; }}
/>;