mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 17:34:59 +08:00
feat: support options
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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} />
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user