diff --git a/example/StackNavigator.tsx b/example/StackNavigator.tsx index b2918182..1d804483 100644 --- a/example/StackNavigator.tsx +++ b/example/StackNavigator.tsx @@ -76,10 +76,10 @@ const StackRouter: Router = { }; } - if (state.names === undefined || state.key === undefined) { + if (state.routeNames === undefined || state.key === undefined) { state = { ...state, - names: state.names || routeNames, + routeNames: state.routeNames || routeNames, key: state.key || `stack-${shortid()}`, }; } @@ -90,7 +90,7 @@ const StackRouter: Router = { getStateForAction(state, action) { switch (action.type) { case 'PUSH': - if (state.names.includes(action.payload.name)) { + if (state.routeNames.includes(action.payload.name)) { return { ...state, index: state.index + 1, @@ -128,7 +128,7 @@ const StackRouter: Router = { }); case 'NAVIGATE': - if (state.names.includes(action.payload.name)) { + if (state.routeNames.includes(action.payload.name)) { // If the route already exists, navigate to that let index = -1; @@ -199,7 +199,7 @@ const StackRouter: Router = { return { ...action.payload, key: state.key, - names: state.names, + routeNames: state.routeNames, }; } diff --git a/example/TabNavigator.tsx b/example/TabNavigator.tsx index f0ad4b86..52ea5af2 100644 --- a/example/TabNavigator.tsx +++ b/example/TabNavigator.tsx @@ -60,10 +60,10 @@ const TabRouter: Router = { }; } - if (state.names === undefined || state.key === undefined) { + if (state.routeNames === undefined || state.key === undefined) { state = { ...state, - names: state.names || routeNames, + routeNames: state.routeNames || routeNames, key: state.key || `tab-${shortid()}`, }; } @@ -75,7 +75,7 @@ const TabRouter: Router = { switch (action.type) { case 'JUMP_TO': case 'NAVIGATE': - if (state.names.includes(action.payload.name)) { + if (state.routeNames.includes(action.payload.name)) { const index = state.routes.findIndex( route => route.name === action.payload.name ); @@ -125,7 +125,7 @@ const TabRouter: Router = { return { ...action.payload, key: state.key, - names: state.names, + routeNames: state.routeNames, }; } diff --git a/src/__tests__/index.test.tsx b/src/__tests__/index.test.tsx index 0b5130bb..4652c95b 100644 --- a/src/__tests__/index.test.tsx +++ b/src/__tests__/index.test.tsx @@ -24,10 +24,10 @@ const MockRouter: Router<{ type: string }> = { }; } - if (state.names === undefined || state.key === undefined) { + if (state.routeNames === undefined || state.key === undefined) { state = { ...state, - names: state.names || routeNames, + routeNames: state.routeNames || routeNames, key: state.key || 'root', }; } @@ -95,7 +95,7 @@ it('initializes state for a navigator on navigation', () => { expect(onStateChange).toBeCalledWith({ index: 0, key: 'root', - names: ['foo', 'bar', 'baz'], + routeNames: ['foo', 'bar', 'baz'], routes: [ { key: 'foo', name: 'foo' }, { key: 'bar', name: 'bar' }, @@ -148,7 +148,7 @@ it('initializes state for nested navigator on navigation', () => { expect(onStateChange).toBeCalledWith({ index: 2, key: 'root', - names: ['foo', 'bar', 'baz'], + routeNames: ['foo', 'bar', 'baz'], routes: [ { key: 'foo', name: 'foo' }, { key: 'bar', name: 'bar' }, @@ -158,7 +158,7 @@ it('initializes state for nested navigator on navigation', () => { state: { index: 0, key: 'root', - names: ['qux'], + routeNames: ['qux'], routes: [{ key: 'qux', name: 'qux' }], }, }, @@ -308,7 +308,7 @@ it("lets parent handle the action if child didn't", () => { expect(onStateChange).toBeCalledWith({ index: 2, key: 'root', - names: ['foo', 'bar', 'baz'], + routeNames: ['foo', 'bar', 'baz'], routes: [ { key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }, @@ -360,7 +360,7 @@ it('allows arbitrary state updates by dispatching a function', () => { expect(onStateChange).toBeCalledWith({ index: 1, key: 'root', - names: ['foo', 'bar'], + routeNames: ['foo', 'bar'], routes: [{ key: 'bar', name: 'bar' }, { key: 'foo', name: 'foo' }], }); }); @@ -403,7 +403,7 @@ it('updates route params with setParams', () => { expect(onStateChange).lastCalledWith({ index: 0, key: 'root', - names: ['foo', 'bar'], + routeNames: ['foo', 'bar'], routes: [ { key: 'foo', name: 'foo', params: { username: 'alice' } }, { key: 'bar', name: 'bar' }, @@ -416,7 +416,7 @@ it('updates route params with setParams', () => { expect(onStateChange).lastCalledWith({ index: 0, key: 'root', - names: ['foo', 'bar'], + routeNames: ['foo', 'bar'], routes: [ { key: 'foo', name: 'foo', params: { username: 'alice', age: 25 } }, { key: 'bar', name: 'bar' }, diff --git a/src/types.tsx b/src/types.tsx index 4d2f2979..62f4122b 100644 --- a/src/types.tsx +++ b/src/types.tsx @@ -12,18 +12,18 @@ export type NavigationState = { */ index: number; /** - * List if valid route names. + * List if valid route names as defined in the screen components. */ - names: string[]; + routeNames: string[]; /** * List of rendered routes. */ routes: Array; }; -export type InitialState = Omit, 'key'> & { +export type InitialState = Omit, 'key'> & { key?: undefined; - names?: undefined; + routeNames?: undefined; state?: InitialState; };