This commit is contained in:
Eric Vicenti
2018-10-11 21:33:34 -07:00
parent 86da163891
commit 136ffb09fe
13 changed files with 29 additions and 48 deletions

View File

@@ -69,8 +69,8 @@ export default function getChildEventSubscriber(addListener, key) {
const lastRoutes = lastState && lastState.routes;
const routes = state && state.routes;
const lastFocusKey =
lastState && lastState.routes && lastState.routes[lastState.index].key;
// const lastFocusKey =
// lastState && lastState.routes && lastState.routes[lastState.index].key;
const focusKey = routes && routes[state.index].key;
const isChildFocused = focusKey === key;

View File

@@ -1,7 +1,6 @@
import getChildEventSubscriber from './getChildEventSubscriber';
import getChildRouter from './getChildRouter';
import getNavigationActionCreators from './routers/getNavigationActionCreators';
import invariant from './utils/invariant';
const createParamGetter = route => (paramName, defaultValue) => {
const params = route.params;

View File

@@ -1,4 +1,4 @@
/* eslint global-require: 0 */
/* eslint-disable import/no-commonjs */
module.exports = {
get StateUtils() {

View File

@@ -15,7 +15,7 @@ function behavesLikePushAction(action) {
);
}
const defaultActionCreators = (route, navStateKey) => ({});
const defaultActionCreators = () => ({});
function isResetToRootStack(action) {
return action.type === StackActions.RESET && action.key === null;

View File

@@ -7,7 +7,7 @@ import StackActions from './StackActions';
import validateRouteConfigMap from './validateRouteConfigMap';
import { createPathParser } from './pathUtils';
const defaultActionCreators = (route, navStateKey) => ({});
const defaultActionCreators = () => ({});
function childrenUpdateWithoutSwitchingIndex(actionType) {
return [
@@ -36,7 +36,6 @@ export default (routeConfigs, config = {}) => {
const initialRouteIndex = order.indexOf(initialRouteName);
const childRouters = {};
order.forEach(routeName => {
const routeConfig = routeConfigs[routeName];
childRouters[routeName] = null;
const screen = getScreenForRouteName(routeConfigs, routeName);
if (screen.router) {

View File

@@ -5,7 +5,6 @@ import React from 'react';
import SwitchRouter from '../SwitchRouter';
import StackRouter from '../StackRouter';
import TabRouter from '../TabRouter';
import StackActions from '../StackActions';
import NavigationActions from '../../NavigationActions';
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator';

View File

@@ -19,7 +19,7 @@ const ROUTERS = {
SwitchRouter,
};
const dummyEventSubscriber = (name, handler) => ({
const dummyEventSubscriber = () => ({
remove: () => {},
});

View File

@@ -397,7 +397,6 @@ describe('StackRouter', () => {
},
state
);
const barKey = state2.routes[1].routes[0].key;
const state3 = router.getStateForAction(
{
type: StackActions.PUSH,
@@ -429,7 +428,6 @@ describe('StackRouter', () => {
},
state
);
const barKey = state2.routes[1].routes[0].key;
const state3 = router.getStateForAction(
{
type: StackActions.POP,
@@ -440,9 +438,6 @@ describe('StackRouter', () => {
});
test('Handle navigation to nested navigator', () => {
const state = TestStackRouter.getStateForAction({
type: NavigationActions.INIT,
});
const action = TestStackRouter.getActionForPathAndParams('fo/22/b/hello');
/* $FlowFixMe */
const state2 = TestStackRouter.getStateForAction(action);
@@ -734,19 +729,17 @@ describe('StackRouter', () => {
bar: { screen: () => <div /> },
});
const initState = TestRouter.getStateForAction(NavigationActions.init());
for (key of ['a', null]) {
const pushedState = TestRouter.getStateForAction(
NavigationActions.navigate({ routeName: 'bar', key: 'a' }),
initState
);
expect(pushedState.index).toEqual(1);
expect(pushedState.routes[1].routeName).toEqual('bar');
const pushedTwiceState = TestRouter.getStateForAction(
NavigationActions.navigate({ routeName: 'bar', key: 'a' }),
pushedState
);
expect(pushedTwiceState).toEqual(null);
}
const pushedState = TestRouter.getStateForAction(
NavigationActions.navigate({ routeName: 'bar', key: 'a' }),
initState
);
expect(pushedState.index).toEqual(1);
expect(pushedState.routes[1].routeName).toEqual('bar');
const pushedTwiceState = TestRouter.getStateForAction(
NavigationActions.navigate({ routeName: 'bar', key: 'a' }),
pushedState
);
expect(pushedTwiceState).toEqual(null);
});
// https://github.com/react-navigation/react-navigation/issues/4063
@@ -1905,7 +1898,7 @@ describe('StackRouter', () => {
expect(activeState5.routes[activeState5.index].routeName).toEqual('Bar');
});
test('order of handling navigate action is correct for nested stackrouters', () => {
test('order of handling navigate action is correct for nested stackrouters 2', () => {
const Screen = () => <div />;
const NestedStack = () => <div />;
const OtherNestedStack = () => <div />;

View File

@@ -527,7 +527,7 @@ describe('TabRouter', () => {
});
});
test.only('Handles path configuration', () => {
test('Handles path configuration', () => {
const ScreenA = () => <div />;
const ScreenB = () => <div />;
const router = TabRouter({

View File

@@ -1,13 +1,11 @@
import { Component } from 'react';
import createConfigGetter from '../createConfigGetter';
const dummyEventSubscriber = (name: string, handler: (*) => void) => ({
const dummyEventSubscriber = () => ({
remove: () => {},
});
test('should get config for screen', () => {
/* eslint-disable react/no-multi-comp */
class HomeScreen extends Component {
static navigationOptions = ({ navigation }) => ({
title: `Welcome ${
@@ -147,8 +145,6 @@ test('should get config for screen', () => {
});
test('should throw if the route does not exist', () => {
/* eslint-disable react/no-multi-comp */
const HomeScreen = () => null;
HomeScreen.navigationOptions = {
title: 'Home screen',

View File

@@ -1,17 +1,11 @@
/* eslint-disable import/no-commonjs */
import pathToRegexp, { compile } from 'path-to-regexp';
import NavigationActions from '../NavigationActions';
import invariant from '../utils/invariant';
const queryString = require('query-string');
function isEmpty(obj) {
if (!obj) return true;
for (let key in obj) {
return false;
}
return true;
}
export const getParamsFromPath = (inputParams, pathMatch, pathMatchKeys) => {
const params = pathMatch.slice(1).reduce(
// iterate over matched path params
@@ -123,9 +117,6 @@ export const createPathParser = (
const getActionForPathAndParams = (pathToResolve = '', inputParams = {}) => {
// Attempt to match `pathToResolve` with a route in this router's routeConfigs, deferring to child routers
let matchedAction = null;
// eslint-disable-next-line no-restricted-syntax
for (const [routeName, path] of paths) {
const { exactRe, exactReKeys, extendedPathRe, extendedPathReKeys } = path;
const childRouter = childRouters[routeName];
@@ -152,7 +143,6 @@ export const createPathParser = (
}
}
// eslint-disable-next-line no-restricted-syntax
for (const [routeName, path] of paths) {
const { extendedPathRe, extendedPathReKeys } = path;
const childRouter = childRouters[routeName];

View File

@@ -1,3 +1,5 @@
/* eslint-disable import/no-commonjs */
/**
* Use invariant() to assert state which your program assumes to be true.
*
@@ -9,7 +11,7 @@
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function(format) {};
var validateFormat = function() {};
if (__DEV__) {
validateFormat = function(format) {

View File

@@ -3,7 +3,7 @@ import renderer from 'react-test-renderer';
import NavigationEvents from '../NavigationEvents';
import { NavigationProvider } from '../NavigationContext';
const createListener = () => payload => {};
const createListener = () => () => {};
// An easy way to create the 4 listeners prop
const createEventListenersProp = () => ({
@@ -101,6 +101,7 @@ describe('NavigationEvents', () => {
checkAddListenerCalledWith('willFocus', eventListenerProps.onWillFocus);
checkAddListenerCalledWith('didBlur', eventListenerProps.onDidBlur);
checkAddListenerCalledWith('didFocus', eventListenerProps.onDidFocus);
component.unmount();
});
it('add all listeners with navigation context', () => {
@@ -122,6 +123,7 @@ describe('NavigationEvents', () => {
checkAddListenerCalledWith('willFocus', eventListenerProps.onWillFocus);
checkAddListenerCalledWith('didBlur', eventListenerProps.onDidBlur);
checkAddListenerCalledWith('didFocus', eventListenerProps.onDidFocus);
component.unmount();
});
it('remove all listeners on unmount', () => {
@@ -159,6 +161,7 @@ describe('NavigationEvents', () => {
);
checkAddListenerCalled(1);
checkAddListenerCalledWith('didFocus', listener);
component.unmount();
});
it('do not attempt to add/remove stable listeners on update', () => {