feat: add basic nesting example

This commit is contained in:
satyajit.happy
2019-06-09 20:19:50 +02:00
parent a78bbbc569
commit 0514ca7fca
5 changed files with 152 additions and 15 deletions

View File

@@ -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' }}>