diff --git a/example/StackNavigator.tsx b/example/StackNavigator.tsx index 8eef73e6..c9be5f16 100644 --- a/example/StackNavigator.tsx +++ b/example/StackNavigator.tsx @@ -115,9 +115,18 @@ const StackRouter = { case 'NAVIGATE': if (state.names.includes(action.payload.name)) { // If the route already exists, navigate to that - const index = state.routes.findIndex( - route => route.name === action.payload.name - ); + let index = -1; + + if (state.routes[state.index].name === action.payload.name) { + index = state.index; + } else { + for (let i = state.routes.length - 1; i >= 0; i--) { + if (state.routes[i].name === action.payload.name) { + index = i; + break; + } + } + } if (index === -1) { return StackRouter.reduce(state, { @@ -161,13 +170,13 @@ const StackRouter = { } default: - return state; + return null; } }, actions: { - push(name: string): Action { - return { type: 'PUSH', payload: { name } }; + push(name: string, params?: object): Action { + return { type: 'PUSH', payload: { name, params } }; }, pop(): Action { return { type: 'POP' }; diff --git a/example/TabNavigator.tsx b/example/TabNavigator.tsx index c6e617c0..b24cdb68 100644 --- a/example/TabNavigator.tsx +++ b/example/TabNavigator.tsx @@ -139,11 +139,8 @@ const TabRouter = { return null; - case 'GO_BACK': - return null; - default: - return state; + return null; } }, diff --git a/example/index.tsx b/example/index.tsx index 90fbd2a4..137f2f6b 100644 --- a/example/index.tsx +++ b/example/index.tsx @@ -6,6 +6,7 @@ import { Screen, CompositeNavigationProp, TypedNavigator, + NavigationHelpers, } from '../src'; import StackNavigator, { StackNavigationProp } from './StackNavigator'; import TabNavigator, { TabNavigationProp } from './TabNavigator'; @@ -34,7 +35,10 @@ const Tab: TypedNavigator = { const First = ({ navigation, }: { - navigation: StackNavigationProp; + navigation: CompositeNavigationProp< + StackNavigationProp, + NavigationHelpers + >; }) => (

First, {navigation.state.params.author}

@@ -44,6 +48,9 @@ const First = ({ +