feat: support options

This commit is contained in:
satyajit.happy
2019-06-10 04:43:42 +02:00
parent 48fec1aa47
commit 57cfb9a512
4 changed files with 28 additions and 5 deletions

View File

@@ -106,6 +106,22 @@ export default function StackNavigator(props: Props) {
{descriptors[route.key].render()}
</div>
))}
<div
style={{
position: 'absolute',
left: 40,
width: 120,
padding: 10,
backgroundColor: 'tomato',
borderRadius: 3,
boxShadow: '0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23)',
}}
>
{
descriptors[navigation.state.routes[navigation.state.index].key]
.options.title
}
</div>
</div>
);
}

View File

@@ -89,9 +89,9 @@ function App() {
return (
<NavigationContainer initialState={initialState}>
<StackNavigator>
<Screen name="first" component={First} />
<Screen name="second" component={Second} />
<Screen name="third">
<Screen name="first" component={First} options={{ title: 'Foo' }} />
<Screen name="second" component={Second} options={{ title: 'Bar' }} />
<Screen name="third" options={{ title: 'Baz' }}>
{() => (
<TabNavigator initialRouteName="fifth">
<Screen name="fourth" component={Fourth} />

View File

@@ -1,6 +1,8 @@
import { Options } from './types';
export type Props = {
name: string;
options?: object;
options?: Options;
} & (
| { component: React.ComponentType<any> }
| { children: (props: any) => React.ReactNode });

View File

@@ -36,7 +36,12 @@ export type NavigationProp<
state: Route | NavigationState;
};
export type Descriptor<Options = {}> = {
export type Descriptor = {
render(): React.ReactNode;
options: Options;
};
export type Options = {
title?: string;
[key: string]: any;
};