Skip to content
This repository was archived by the owner on Feb 8, 2020. It is now read-only.

Commit 8f16085

Browse files
committed
fix: improve type annotation for screens
1 parent 58fbfdf commit 8f16085

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

packages/core/src/SceneView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ export default function SceneView<
9090
route={route}
9191
>
9292
{'component' in screen && screen.component !== undefined ? (
93+
// @ts-ignore
9394
<screen.component navigation={navigation} route={route} />
9495
) : 'children' in screen && screen.children !== undefined ? (
96+
// @ts-ignore
9597
screen.children({ navigation, route })
9698
) : null}
9799
</StaticContainer>

packages/core/src/types.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,19 @@ export type RouteConfig<
521521
/**
522522
* React component to render for this screen.
523523
*/
524-
component: React.ComponentType<any>;
524+
component: React.ComponentType<{
525+
route: RouteProp<ParamList, RouteName>;
526+
navigation: any;
527+
}>;
525528
}
526529
| {
527530
/**
528531
* Render callback to render content of this screen.
529532
*/
530-
children: (props: any) => React.ReactNode;
533+
children: (props: {
534+
route: RouteProp<ParamList, RouteName>;
535+
navigation: any;
536+
}) => React.ReactNode;
531537
});
532538

533539
export type NavigationContainerRef =

packages/example/src/Screens/BottomTabs.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export default function BottomTabsScreen() {
4141
tabBarButtonComponent: TouchableBounce,
4242
}}
4343
>
44-
{props => (
45-
<SimpleStackScreen {...props} options={{ headerMode: 'none' }} />
46-
)}
44+
{props => <SimpleStackScreen {...props} headerMode="none" />}
4745
</BottomTabs.Screen>
4846
<BottomTabs.Screen
4947
name="chat"

packages/example/src/Screens/MaterialBottomTabs.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export default function MaterialBottomTabsScreen() {
2828
tabBarColor: '#C9E7F8',
2929
}}
3030
>
31-
{props => (
32-
<SimpleStackScreen {...props} options={{ headerMode: 'none' }} />
33-
)}
31+
{props => <SimpleStackScreen {...props} headerMode="none" />}
3432
</MaterialBottomTabs.Screen>
3533
<MaterialBottomTabs.Screen
3634
name="chat"

packages/example/src/Screens/SimpleStack.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { RouteProp, ParamListBase } from '@react-navigation/core';
55
import {
66
createStackNavigator,
77
StackNavigationProp,
8-
StackNavigationOptions,
98
} from '@react-navigation/stack';
109
import Article from '../Shared/Article';
1110
import Albums from '../Shared/Albums';
@@ -77,18 +76,17 @@ const AlbumsScreen = ({
7776

7877
const SimpleStack = createStackNavigator<SimpleStackParams>();
7978

80-
type Props = {
81-
options?: StackNavigationOptions;
79+
type Props = Partial<React.ComponentProps<typeof SimpleStack.Navigator>> & {
8280
navigation: StackNavigationProp<ParamListBase>;
8381
};
8482

85-
export default function SimpleStackScreen({ navigation, options }: Props) {
83+
export default function SimpleStackScreen({ navigation, ...rest }: Props) {
8684
navigation.setOptions({
8785
headerShown: false,
8886
});
8987

9088
return (
91-
<SimpleStack.Navigator {...options}>
89+
<SimpleStack.Navigator {...rest}>
9290
<SimpleStack.Screen
9391
name="article"
9492
component={ArticleScreen}

0 commit comments

Comments
 (0)