mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-20 15:17:24 +08:00
feat: add basic nesting example
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
|
||||
type Props = {
|
||||
initialRouteName?: string;
|
||||
navigation?: NavigationProp;
|
||||
children: React.ReactElement[];
|
||||
};
|
||||
|
||||
@@ -42,6 +43,7 @@ const StackRouter = {
|
||||
switch (action.type) {
|
||||
case 'PUSH':
|
||||
return {
|
||||
...state,
|
||||
index: state.index + 1,
|
||||
routes: [
|
||||
...state.routes,
|
||||
@@ -54,6 +56,7 @@ const StackRouter = {
|
||||
case 'POP':
|
||||
return state.index > 0
|
||||
? {
|
||||
...state,
|
||||
index: state.index - 1,
|
||||
routes: state.routes.slice(0, state.routes.length - 1),
|
||||
}
|
||||
@@ -73,13 +76,10 @@ const StackRouter = {
|
||||
},
|
||||
};
|
||||
|
||||
export default function StackNavigator({ initialRouteName, children }: Props) {
|
||||
export default function StackNavigator(props: Props) {
|
||||
// The `navigation` object contains the navigation state and some helpers (e.g. push, pop)
|
||||
// The `descriptors` object contains `navigation` objects for children routes and helper for rendering a screen
|
||||
const { navigation, descriptors } = useNavigationBuilder(StackRouter, {
|
||||
initialRouteName,
|
||||
children,
|
||||
});
|
||||
const { navigation, descriptors } = useNavigationBuilder(StackRouter, props);
|
||||
|
||||
return (
|
||||
<div style={{ position: 'relative' }}>
|
||||
|
||||
Reference in New Issue
Block a user