mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-01 22:35:12 +08:00
Compare commits
1 Commits
2.8.0
...
@ericvicen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
655453aed3 |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -6,28 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [2.8.0] - [2018-07-19](https://github.com/react-navigation/react-navigation/releases/tag/2.8.0)
|
||||
### Added
|
||||
- `headerLeftContainerStyle`, `headerTitleContainerStyle`, and `headerRightContainerStyle` are exposed on `navigationOptions`. These properties allow you to customize the style of the container of `headerLeft`, `headerTitle` and `headerRight` components.
|
||||
|
||||
### Fixed
|
||||
- Fixed memory leaks in `createNavigator`: [closure scope leak](https://github.com/react-navigation/react-navigation/commit/1a765562905e93bbae0262dd20c2688221c999e8), and [clean up old descriptors](https://github.com/react-navigation/react-navigation/commit/93642e16e7ff029586b68ee732ec790504ee4862).
|
||||
|
||||
## [2.7.0] - [2018-07-17](https://github.com/react-navigation/react-navigation/releases/tag/2.7.0)
|
||||
### Added
|
||||
- The enableURLHandling prop on the top level navigator component allows you to disable deep linking handling. Currently it is always enabled. To disable it, `<RootNavigator enableURLHandling={false} />`
|
||||
|
||||
### Changed
|
||||
- StackNavigator.replace method no longer requires a key param. If the key is left undefined, the last screen in the stack will be replaced.
|
||||
|
||||
### Fixed
|
||||
- Support headerLeft component for the first screen in a stack (#4608).
|
||||
- Removed bottomBorder when `headerTransparent` is set to true.
|
||||
- Improve empty path and param handling in deep linking (#4671). This fixes issues with deep linking and fully tests the differences between path: '' and path: null. Empty string matches empty paths, and null path will let the child router handle paths at the same level. Also it makes sure that params are not duplicated between path and query when they are serialized with getPathAndParamsForState.
|
||||
- Fix onTransitionStart not being invoked when provided in navigator config.(#4100)
|
||||
- Rare case when users navigated back and forth quickly with exactly the right timing would cause a crash due to a scene being queued to transition, then clobbered, then attempted to render as a stale scene but without a descriptor. ([commit](https://github.com/react-navigation/react-navigation/commit/cab4d71a5e09188df3f4a294c98779eecb860a78))
|
||||
|
||||
## [2.6.2] - [2018-07-06](https://github.com/react-navigation/react-navigation/releases/tag/2.6.2)
|
||||
### Changed
|
||||
- Relax vertical padding warnings on header.
|
||||
@@ -90,9 +71,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
### Changed
|
||||
- Improved examples
|
||||
|
||||
[Unreleased]: https://github.com/react-navigation/react-navigation/compare/2.8.0...HEAD
|
||||
[2.8.0]: https://github.com/react-navigation/react-navigation/compare/2.7.0...2.8.0
|
||||
[2.7.0]: https://github.com/react-navigation/react-navigation/compare/2.6.2...2.7.0
|
||||
[Unreleased]: https://github.com/react-navigation/react-navigation/compare/2.6.2...HEAD
|
||||
[2.6.2]: https://github.com/react-navigation/react-navigation/compare/2.6.1...2.6.2
|
||||
[2.6.1]: https://github.com/react-navigation/react-navigation/compare/2.6.0...2.6.1
|
||||
[2.6.0]: https://github.com/react-navigation/react-navigation/compare/2.5.5...2.6.0
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"splash": {
|
||||
"image": "./assets/icons/splash.png"
|
||||
},
|
||||
"sdkVersion": "28.0.0",
|
||||
"sdkVersion": "27.0.0",
|
||||
"entryPoint": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
|
||||
"assetBundlePatterns": [
|
||||
"**/*"
|
||||
],
|
||||
|
||||
@@ -16,6 +16,9 @@ import {
|
||||
StatusBar,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
import Reactotron from 'reactotron-react-native';
|
||||
|
||||
import { SafeAreaView, createStackNavigator } from 'react-navigation';
|
||||
|
||||
import CustomTabs from './CustomTabs';
|
||||
@@ -39,6 +42,11 @@ import TabsWithNavigationFocus from './TabsWithNavigationFocus';
|
||||
import TabsWithNavigationEvents from './TabsWithNavigationEvents';
|
||||
import KeyboardHandlingExample from './KeyboardHandlingExample';
|
||||
|
||||
Reactotron.configure()
|
||||
.useReactNative()
|
||||
.connect();
|
||||
console.tron = Reactotron;
|
||||
|
||||
const ExampleInfo = {
|
||||
SimpleStack: {
|
||||
name: 'Stack Example',
|
||||
@@ -340,7 +348,9 @@ const AppNavigator = createStackNavigator(
|
||||
}
|
||||
);
|
||||
|
||||
export default AppNavigator;
|
||||
const App = () => <AppNavigator persistenceKey="yes" />;
|
||||
|
||||
export default App;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
item: {
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
Platform,
|
||||
ScrollView,
|
||||
StatusBar,
|
||||
StyleSheet,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import { Header, createStackNavigator } from 'react-navigation';
|
||||
@@ -232,10 +231,6 @@ const StackWithTranslucentHeader = createStackNavigator(
|
||||
headerTransitionPreset: 'uikit',
|
||||
navigationOptions: {
|
||||
headerTransparent: true,
|
||||
headerStyle: {
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
borderBottomColor: '#A7A7AA',
|
||||
},
|
||||
headerBackground: Platform.select({
|
||||
ios: <BlurView style={{ flex: 1 }} intensity={98} />,
|
||||
android: (
|
||||
|
||||
@@ -2,32 +2,34 @@
|
||||
"name": "NavigationPlayground",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"main": "node_modules/expo/AppEntry.js",
|
||||
"private": true,
|
||||
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
"android": "expo start --android",
|
||||
"ios": "expo start --ios",
|
||||
"start": "react-native-scripts start",
|
||||
"eject": "react-native-scripts eject",
|
||||
"android": "react-native-scripts android",
|
||||
"ios": "react-native-scripts ios",
|
||||
"test": "flow"
|
||||
},
|
||||
"dependencies": {
|
||||
"expo": "^28.0.0",
|
||||
"expo": "^27.0.0",
|
||||
"invariant": "^2.2.4",
|
||||
"react": "16.3.1",
|
||||
"react-native": "^0.55.0",
|
||||
"react-native-iphone-x-helper": "^1.0.2",
|
||||
"react-navigation": "link:../..",
|
||||
"react-navigation-header-buttons": "^0.0.4",
|
||||
"react-navigation-material-bottom-tabs": "^0.3.0",
|
||||
"react-navigation-tabs": "^0.5.1"
|
||||
"react-navigation-material-bottom-tabs": "0.1.3",
|
||||
"react-navigation-tabs": "^0.5.1",
|
||||
"reactotron-react-native": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-jest": "^22.4.1",
|
||||
"babel-plugin-transform-remove-console": "^6.9.0",
|
||||
"flow-bin": "^0.67.0",
|
||||
"jest": "^22.1.3",
|
||||
"jest-expo": "^28.0.0",
|
||||
"react-test-renderer": "16.3.1"
|
||||
"jest-expo": "^26.0.0",
|
||||
"react-native-scripts": "^1.5.0",
|
||||
"react-test-renderer": "16.3.0-alpha.1"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "jest-expo",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-navigation",
|
||||
"version": "2.8.0",
|
||||
"version": "2.6.2",
|
||||
"description": "Routing and navigation for your React Native apps",
|
||||
"main": "src/react-navigation.js",
|
||||
"repository": {
|
||||
|
||||
@@ -265,6 +265,16 @@ export default function createNavigationContainer(Component) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.tron &&
|
||||
console.tron.display({
|
||||
name: 'Navigation',
|
||||
preview: 'Initial State',
|
||||
value: {
|
||||
initialState: startupState,
|
||||
initialAction: this._initialAction,
|
||||
},
|
||||
});
|
||||
|
||||
this.setState({ nav: startupState }, () => {
|
||||
_reactNavigationIsHydratingState = false;
|
||||
dispatchActions();
|
||||
|
||||
@@ -4,9 +4,11 @@ exports[`Nested navigators renders succesfully as direct child 1`] = `
|
||||
<View
|
||||
onLayout={[Function]}
|
||||
style={
|
||||
Object {
|
||||
"flex": 1,
|
||||
}
|
||||
Array [
|
||||
Object {
|
||||
"flex": 1,
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<View
|
||||
@@ -75,9 +77,11 @@ exports[`Nested navigators renders succesfully as direct child 1`] = `
|
||||
<View
|
||||
onLayout={[Function]}
|
||||
style={
|
||||
Object {
|
||||
"flex": 1,
|
||||
}
|
||||
Array [
|
||||
Object {
|
||||
"flex": 1,
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<View
|
||||
|
||||
@@ -4,9 +4,11 @@ exports[`StackNavigator applies correct values when headerRight is present 1`] =
|
||||
<View
|
||||
onLayout={[Function]}
|
||||
style={
|
||||
Object {
|
||||
"flex": 1,
|
||||
}
|
||||
Array [
|
||||
Object {
|
||||
"flex": 1,
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<View
|
||||
@@ -208,9 +210,11 @@ exports[`StackNavigator renders successfully 1`] = `
|
||||
<View
|
||||
onLayout={[Function]}
|
||||
style={
|
||||
Object {
|
||||
"flex": 1,
|
||||
}
|
||||
Array [
|
||||
Object {
|
||||
"flex": 1,
|
||||
},
|
||||
]
|
||||
}
|
||||
>
|
||||
<View
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { TextInput } from 'react-native';
|
||||
|
||||
export default (Navigator, navigatorConfig) =>
|
||||
export default Navigator =>
|
||||
class KeyboardAwareNavigator extends React.Component {
|
||||
static router = Navigator.router;
|
||||
_previouslyFocusedTextInput = null;
|
||||
@@ -49,9 +49,7 @@ export default (Navigator, navigatorConfig) =>
|
||||
}
|
||||
}
|
||||
|
||||
const onTransitionStart =
|
||||
this.props.onTransitionStart || navigatorConfig.onTransitionStart;
|
||||
onTransitionStart &&
|
||||
onTransitionStart(transitionProps, prevTransitionProps);
|
||||
this.props.onTransitionStart &&
|
||||
this.props.onTransitionStart(transitionProps, prevTransitionProps);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ function createNavigator(NavigatorView, router, navigationConfig) {
|
||||
);
|
||||
}
|
||||
|
||||
const descriptors = {};
|
||||
const descriptors = { ...prevState.descriptors };
|
||||
|
||||
routes.forEach(route => {
|
||||
if (
|
||||
@@ -36,10 +36,8 @@ function createNavigator(NavigatorView, router, navigationConfig) {
|
||||
descriptors[route.key] = prevDescriptors[route.key];
|
||||
return;
|
||||
}
|
||||
const getComponent = router.getComponentForRouteName.bind(
|
||||
null,
|
||||
route.routeName
|
||||
);
|
||||
const getComponent = () =>
|
||||
router.getComponentForRouteName(route.routeName);
|
||||
const childNavigation = navigation.getChildNavigation(route.key);
|
||||
const options = router.getScreenOptions(childNavigation, screenProps);
|
||||
descriptors[route.key] = {
|
||||
|
||||
@@ -28,7 +28,7 @@ function createStackNavigator(routeConfigMap, stackConfig = {}) {
|
||||
// Create a navigator with StackView as the view
|
||||
let Navigator = createNavigator(StackView, router, stackConfig);
|
||||
if (!disableKeyboardHandling) {
|
||||
Navigator = createKeyboardAwareNavigator(Navigator, stackConfig);
|
||||
Navigator = createKeyboardAwareNavigator(Navigator);
|
||||
}
|
||||
|
||||
return Navigator;
|
||||
|
||||
@@ -107,7 +107,13 @@ export default (routeConfigs, stackConfig = {}) => {
|
||||
const {
|
||||
getPathAndParamsForRoute,
|
||||
getActionForPathAndParams,
|
||||
} = createPathParser(childRouters, routeConfigs, stackConfig.paths);
|
||||
} = createPathParser(
|
||||
childRouters,
|
||||
routeConfigs,
|
||||
stackConfig.paths,
|
||||
initialRouteName,
|
||||
initialRouteParams
|
||||
);
|
||||
|
||||
return {
|
||||
childRouters,
|
||||
|
||||
@@ -47,7 +47,13 @@ export default (routeConfigs, config = {}) => {
|
||||
const {
|
||||
getPathAndParamsForRoute,
|
||||
getActionForPathAndParams,
|
||||
} = createPathParser(childRouters, routeConfigs, config.paths);
|
||||
} = createPathParser(
|
||||
childRouters,
|
||||
routeConfigs,
|
||||
config.paths,
|
||||
initialRouteName,
|
||||
initialRouteParams
|
||||
);
|
||||
|
||||
if (initialRouteIndex === -1) {
|
||||
throw new Error(
|
||||
|
||||
@@ -13,50 +13,50 @@ beforeEach(() => {
|
||||
_TESTING_ONLY_normalize_keys();
|
||||
});
|
||||
|
||||
const performRouterTest = createTestRouter => {
|
||||
const ListScreen = () => <div />;
|
||||
const ListScreen = () => <div />;
|
||||
|
||||
const ProfileNavigator = () => <div />;
|
||||
ProfileNavigator.router = StackRouter({
|
||||
list: {
|
||||
path: 'list/:id',
|
||||
screen: ListScreen,
|
||||
const ProfileNavigator = () => <div />;
|
||||
ProfileNavigator.router = StackRouter({
|
||||
list: {
|
||||
path: 'list/:id',
|
||||
screen: ListScreen,
|
||||
},
|
||||
});
|
||||
|
||||
const MainNavigator = () => <div />;
|
||||
MainNavigator.router = StackRouter({
|
||||
profile: {
|
||||
path: 'p/:id',
|
||||
screen: ProfileNavigator,
|
||||
},
|
||||
});
|
||||
|
||||
const LoginScreen = () => <div />;
|
||||
|
||||
const AuthNavigator = () => <div />;
|
||||
AuthNavigator.router = StackRouter({
|
||||
login: {
|
||||
screen: LoginScreen,
|
||||
},
|
||||
});
|
||||
|
||||
const BarScreen = () => <div />;
|
||||
|
||||
class FooNavigator extends React.Component {
|
||||
static router = StackRouter({
|
||||
bar: {
|
||||
path: 'b/:barThing',
|
||||
screen: BarScreen,
|
||||
},
|
||||
});
|
||||
|
||||
const MainNavigator = () => <div />;
|
||||
MainNavigator.router = StackRouter({
|
||||
profile: {
|
||||
path: 'p/:id',
|
||||
screen: ProfileNavigator,
|
||||
},
|
||||
});
|
||||
|
||||
const LoginScreen = () => <div />;
|
||||
|
||||
const AuthNavigator = () => <div />;
|
||||
AuthNavigator.router = StackRouter({
|
||||
login: {
|
||||
screen: LoginScreen,
|
||||
},
|
||||
});
|
||||
|
||||
const BarScreen = () => <div />;
|
||||
|
||||
class FooNavigator extends React.Component {
|
||||
static router = StackRouter({
|
||||
bar: {
|
||||
path: 'b/:barThing',
|
||||
screen: BarScreen,
|
||||
},
|
||||
});
|
||||
render() {
|
||||
return <div />;
|
||||
}
|
||||
render() {
|
||||
return <div />;
|
||||
}
|
||||
}
|
||||
|
||||
const PersonScreen = () => <div />;
|
||||
const PersonScreen = () => <div />;
|
||||
|
||||
const performRouterTest = createTestRouter => {
|
||||
const testRouter = createTestRouter({
|
||||
main: {
|
||||
screen: MainNavigator,
|
||||
@@ -78,7 +78,7 @@ const performRouterTest = createTestRouter => {
|
||||
},
|
||||
});
|
||||
|
||||
test('Handles empty URIs with empty action', () => {
|
||||
test('Handles empty URIs', () => {
|
||||
const router = createTestRouter(
|
||||
{
|
||||
Foo: {
|
||||
@@ -91,8 +91,12 @@ const performRouterTest = createTestRouter => {
|
||||
{ initialRouteName: 'Bar', initialRouteParams: { foo: 42 } }
|
||||
);
|
||||
const action = router.getActionForPathAndParams('');
|
||||
expect(action).toEqual(null);
|
||||
const state = router.getStateForAction(action || NavigationActions.init());
|
||||
expect(action).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'Bar',
|
||||
params: { foo: 42 },
|
||||
});
|
||||
const state = router.getStateForAction(action);
|
||||
expect(state.routes[state.index]).toEqual(
|
||||
expect.objectContaining({
|
||||
routeName: 'Bar',
|
||||
@@ -101,244 +105,6 @@ const performRouterTest = createTestRouter => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Handles paths with several params', () => {
|
||||
const router = createTestRouter({
|
||||
Person: {
|
||||
path: 'people/:person',
|
||||
screen: () => <div />,
|
||||
},
|
||||
Task: {
|
||||
path: 'people/:person/tasks/:task',
|
||||
screen: () => <div />,
|
||||
},
|
||||
ThingA: {
|
||||
path: 'things/:good',
|
||||
screen: () => <div />,
|
||||
},
|
||||
Thing: {
|
||||
path: 'things/:good/:thing',
|
||||
screen: () => <div />,
|
||||
},
|
||||
});
|
||||
const action = router.getActionForPathAndParams(
|
||||
'people/brent/tasks/everything'
|
||||
);
|
||||
expect(action).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'Task',
|
||||
params: { person: 'brent', task: 'everything' },
|
||||
});
|
||||
|
||||
const action1 = router.getActionForPathAndParams('people/lucy');
|
||||
expect(action1).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'Person',
|
||||
params: { person: 'lucy' },
|
||||
});
|
||||
|
||||
const action2 = router.getActionForPathAndParams('things/foo/bar');
|
||||
expect(action2).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'Thing',
|
||||
params: { good: 'foo', thing: 'bar' },
|
||||
});
|
||||
|
||||
const action3 = router.getActionForPathAndParams('things/foo');
|
||||
expect(action3).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'ThingA',
|
||||
params: { good: 'foo' },
|
||||
});
|
||||
});
|
||||
|
||||
test('Handles empty path configuration', () => {
|
||||
const router = createTestRouter({
|
||||
Foo: {
|
||||
screen: () => <div />,
|
||||
},
|
||||
Bar: {
|
||||
screen: () => <div />,
|
||||
path: '',
|
||||
},
|
||||
});
|
||||
const action = router.getActionForPathAndParams('');
|
||||
expect(action).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'Bar',
|
||||
params: {},
|
||||
});
|
||||
});
|
||||
|
||||
test('Handles wildcard path configuration', () => {
|
||||
const router = createTestRouter({
|
||||
Foo: {
|
||||
screen: () => <div />,
|
||||
},
|
||||
Bar: {
|
||||
screen: () => <div />,
|
||||
path: ':something',
|
||||
},
|
||||
});
|
||||
const action = router.getActionForPathAndParams('');
|
||||
expect(action).toEqual(null);
|
||||
|
||||
const action1 = router.getActionForPathAndParams('Foo');
|
||||
expect(action1).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'Foo',
|
||||
params: {},
|
||||
});
|
||||
const action2 = router.getActionForPathAndParams('asdf');
|
||||
expect(action2).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
routeName: 'Bar',
|
||||
params: { something: 'asdf' },
|
||||
});
|
||||
});
|
||||
|
||||
test('Null path behavior', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const router = createTestRouter({
|
||||
Bar: {
|
||||
screen: ScreenA,
|
||||
},
|
||||
Foo: {
|
||||
path: null,
|
||||
screen: ScreenA,
|
||||
},
|
||||
Baz: {
|
||||
path: '',
|
||||
screen: ScreenA,
|
||||
},
|
||||
});
|
||||
const action0 = router.getActionForPathAndParams('test/random', {});
|
||||
expect(action0).toBe(null);
|
||||
|
||||
const action1 = router.getActionForPathAndParams('', {});
|
||||
expect(action1.routeName).toBe('Baz');
|
||||
const state1 = router.getStateForAction(action1);
|
||||
expect(state1.routes[state1.index].routeName).toBe('Baz');
|
||||
});
|
||||
|
||||
test('Multiple null path sub routers path behavior', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const ScreenB = () => <div />;
|
||||
ScreenB.router = createTestRouter({
|
||||
Foo: ScreenA,
|
||||
});
|
||||
const ScreenC = () => <div />;
|
||||
ScreenC.router = createTestRouter({
|
||||
Bar: {
|
||||
path: 'bar/:id',
|
||||
screen: ScreenA,
|
||||
},
|
||||
Empty: {
|
||||
path: '',
|
||||
screen: ScreenA,
|
||||
},
|
||||
});
|
||||
const router = createTestRouter({
|
||||
A: {
|
||||
screen: ScreenA,
|
||||
},
|
||||
B: {
|
||||
path: null,
|
||||
screen: ScreenB,
|
||||
},
|
||||
C: {
|
||||
path: null,
|
||||
screen: ScreenC,
|
||||
},
|
||||
});
|
||||
const action0 = router.getActionForPathAndParams('Foo', {});
|
||||
expect(action0.routeName).toBe('B');
|
||||
expect(action0.action.routeName).toBe('Foo');
|
||||
|
||||
const action1 = router.getActionForPathAndParams('', {});
|
||||
expect(action1.routeName).toBe('C');
|
||||
expect(action1.action.routeName).toBe('Empty');
|
||||
|
||||
const action2 = router.getActionForPathAndParams('A', {});
|
||||
expect(action2.routeName).toBe('A');
|
||||
|
||||
const action3 = router.getActionForPathAndParams('bar/asdf', {});
|
||||
expect(action3.routeName).toBe('C');
|
||||
expect(action3.action.routeName).toBe('Bar');
|
||||
expect(action3.action.params.id).toBe('asdf');
|
||||
});
|
||||
|
||||
test('Null and empty string path sub routers behavior', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const ScreenB = () => <div />;
|
||||
ScreenB.router = createTestRouter({
|
||||
Foo: ScreenA,
|
||||
Baz: {
|
||||
screen: ScreenA,
|
||||
path: '',
|
||||
},
|
||||
});
|
||||
const ScreenC = () => <div />;
|
||||
ScreenC.router = createTestRouter({
|
||||
Boo: ScreenA,
|
||||
Bar: ScreenA,
|
||||
Baz: {
|
||||
screen: ScreenA,
|
||||
path: '',
|
||||
},
|
||||
});
|
||||
const router = createTestRouter({
|
||||
B: {
|
||||
path: null,
|
||||
screen: ScreenB,
|
||||
},
|
||||
C: {
|
||||
path: '',
|
||||
screen: ScreenC,
|
||||
},
|
||||
});
|
||||
const action0 = router.getActionForPathAndParams('', {});
|
||||
expect(action0.routeName).toBe('C');
|
||||
expect(action0.action.routeName).toBe('Baz');
|
||||
|
||||
const action1 = router.getActionForPathAndParams('Foo', {});
|
||||
expect(action1.routeName).toBe('B');
|
||||
expect(action1.action.routeName).toBe('Foo');
|
||||
|
||||
const action2 = router.getActionForPathAndParams('Bar', {});
|
||||
expect(action2.routeName).toBe('C');
|
||||
expect(action2.action.routeName).toBe('Bar');
|
||||
|
||||
const action3 = router.getActionForPathAndParams('unknown', {});
|
||||
expect(action3).toBe(null);
|
||||
});
|
||||
|
||||
test('Empty path acts as wildcard for nested router', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const Foo = () => <div />;
|
||||
const ScreenC = () => <div />;
|
||||
ScreenC.router = createTestRouter({
|
||||
Boo: ScreenA,
|
||||
Bar: ScreenA,
|
||||
});
|
||||
Foo.router = createTestRouter({
|
||||
Quo: ScreenA,
|
||||
Qux: {
|
||||
screen: ScreenC,
|
||||
path: '',
|
||||
},
|
||||
});
|
||||
const router = createTestRouter({
|
||||
Bar: {
|
||||
screen: ScreenA,
|
||||
},
|
||||
Foo,
|
||||
});
|
||||
const action0 = router.getActionForPathAndParams('Foo/Bar', {});
|
||||
expect(action0.routeName).toBe('Foo');
|
||||
expect(action0.action.routeName).toBe('Qux');
|
||||
expect(action0.action.action.routeName).toBe('Bar');
|
||||
});
|
||||
|
||||
test('Gets deep path with pure wildcard match', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const ScreenB = () => <div />;
|
||||
@@ -387,6 +153,7 @@ const performRouterTest = createTestRouter => {
|
||||
const { path, params } = router.getPathAndParamsForState(state);
|
||||
expect(path).toEqual('baz/321');
|
||||
expect(params.id).toEqual('123');
|
||||
expect(params.bazId).toEqual('321');
|
||||
}
|
||||
|
||||
{
|
||||
@@ -441,31 +208,6 @@ const performRouterTest = createTestRouter => {
|
||||
});
|
||||
});
|
||||
|
||||
test('URI encoded path param gets parsed and correctly printed', () => {
|
||||
const router = createTestRouter({
|
||||
main: {
|
||||
screen: () => <div />,
|
||||
},
|
||||
person: {
|
||||
path: 'people/:name',
|
||||
screen: () => <div />,
|
||||
},
|
||||
});
|
||||
|
||||
const action = testRouter.getActionForPathAndParams('people/Henry%20L');
|
||||
expect(action).toEqual({
|
||||
routeName: 'person',
|
||||
params: {
|
||||
id: 'Henry L',
|
||||
},
|
||||
type: NavigationActions.NAVIGATE,
|
||||
});
|
||||
const s = testRouter.getStateForAction(action);
|
||||
const out = testRouter.getPathAndParamsForState(s);
|
||||
expect(out.path).toEqual('people/Henry%20L');
|
||||
expect(out.params).toEqual({});
|
||||
});
|
||||
|
||||
test('Querystring params get passed to nested deep link', () => {
|
||||
const action = testRouter.getActionForPathAndParams(
|
||||
'main/p/4/list/10259959195',
|
||||
@@ -555,24 +297,3 @@ describe('Path handling for stack router', () => {
|
||||
describe('Path handling for switch router', () => {
|
||||
performRouterTest(SwitchRouter);
|
||||
});
|
||||
|
||||
test('Handles nested switch routers', () => {
|
||||
const AScreen = () => <div />;
|
||||
const DocsNavigator = () => <div />;
|
||||
DocsNavigator.router = SwitchRouter({
|
||||
A: AScreen,
|
||||
B: AScreen,
|
||||
C: AScreen,
|
||||
});
|
||||
DocsNavigator.path = 'docs';
|
||||
const router = SwitchRouter({
|
||||
Docs: DocsNavigator,
|
||||
D: AScreen,
|
||||
});
|
||||
const action = router.getActionForPathAndParams('docs/B', {});
|
||||
|
||||
expect(action.type).toEqual(NavigationActions.NAVIGATE);
|
||||
expect(action.routeName).toEqual('Docs');
|
||||
expect(action.action.type).toEqual(NavigationActions.NAVIGATE);
|
||||
expect(action.action.routeName).toEqual('B');
|
||||
});
|
||||
|
||||
@@ -319,7 +319,7 @@ describe('StackRouter', () => {
|
||||
});
|
||||
|
||||
test('Correctly returns action chain for partially matched path', () => {
|
||||
const uri = 'auth/login';
|
||||
const uri = 'auth/login/2';
|
||||
const action = TestStackRouter.getActionForPathAndParams(uri);
|
||||
expect(action).toEqual({
|
||||
type: NavigationActions.NAVIGATE,
|
||||
@@ -1206,7 +1206,8 @@ describe('StackRouter', () => {
|
||||
};
|
||||
const { path, params } = router.getPathAndParamsForState(state);
|
||||
expect(path).toEqual('f/123/baz/321');
|
||||
expect(params).toEqual({});
|
||||
expect(params.id).toEqual('123');
|
||||
expect(params.bazId).toEqual('321');
|
||||
});
|
||||
|
||||
test('Handle goBack identified by key', () => {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import pathToRegexp from 'path-to-regexp';
|
||||
import NavigationActions from '../NavigationActions';
|
||||
import invariant from '../utils/invariant';
|
||||
|
||||
const queryString = require('query-string');
|
||||
|
||||
function isEmpty(obj) {
|
||||
@@ -12,37 +10,6 @@ function isEmpty(obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const getParamsFromPath = (inputParams, pathMatch, pathMatchKeys) => {
|
||||
const params = pathMatch.slice(1).reduce(
|
||||
// iterate over matched path params
|
||||
(paramsOut, matchResult, i) => {
|
||||
const key = pathMatchKeys[i];
|
||||
if (!key || key.asterisk) {
|
||||
return paramsOut;
|
||||
}
|
||||
const paramName = key.name;
|
||||
|
||||
let decodedMatchResult;
|
||||
try {
|
||||
decodedMatchResult = decodeURIComponent(matchResult);
|
||||
} catch (e) {
|
||||
// ignore `URIError: malformed URI`
|
||||
}
|
||||
|
||||
paramsOut[paramName] = decodedMatchResult || matchResult;
|
||||
return paramsOut;
|
||||
},
|
||||
{
|
||||
// start with the input(query string) params, which will get overridden by path params
|
||||
...inputParams,
|
||||
}
|
||||
);
|
||||
return params;
|
||||
};
|
||||
const getRestOfPath = (pathMatch, pathMatchKeys) => {
|
||||
const rest = pathMatch[pathMatchKeys.findIndex(k => k.asterisk) + 1];
|
||||
return rest;
|
||||
};
|
||||
export const urlToPathAndParams = (url, uriPrefix) => {
|
||||
const searchMatch = url.match(/^(.*)\?(.*)$/);
|
||||
const params = searchMatch ? queryString.parse(searchMatch[2]) : {};
|
||||
@@ -67,145 +34,138 @@ export const urlToPathAndParams = (url, uriPrefix) => {
|
||||
export const createPathParser = (
|
||||
childRouters,
|
||||
routeConfigs,
|
||||
pathConfigs = {}
|
||||
pathConfigs = {},
|
||||
initialRouteName,
|
||||
initialRouteParams
|
||||
) => {
|
||||
const pathsByRouteNames = {};
|
||||
let paths = [];
|
||||
|
||||
// Build pathsByRouteNames, which includes a regex to match paths for each route. Keep in mind, the regex will pass for the route and all child routes. The code that uses pathsByRouteNames will need to also verify that the child router produces an action, in the case of isPathMatchable false (a null path).
|
||||
// Build paths for each route
|
||||
Object.keys(childRouters).forEach(routeName => {
|
||||
let pathPattern = pathConfigs[routeName] || routeConfigs[routeName].path;
|
||||
|
||||
let matchExact = !!pathPattern && !childRouters[routeName];
|
||||
if (pathPattern === undefined) {
|
||||
// If the user hasn't specified a path at all, then we assume the routeName is an appropriate path
|
||||
pathPattern = routeName;
|
||||
}
|
||||
|
||||
invariant(
|
||||
pathPattern === null || typeof pathPattern === 'string',
|
||||
`Route path for ${routeName} must be specified as a string, or null.`
|
||||
);
|
||||
|
||||
// the path may be specified as null, which is similar to empty string because it allows child routers to handle the action, but it will not match empty paths
|
||||
const isPathMatchable = pathPattern !== null;
|
||||
// pathPattern is a string with inline params, such as people/:id/*foo
|
||||
const exactReKeys = [];
|
||||
const exactRe = isPathMatchable
|
||||
? pathToRegexp(pathPattern, exactReKeys)
|
||||
: null;
|
||||
const extendedPathReKeys = [];
|
||||
const isWildcard = pathPattern === '' || !isPathMatchable;
|
||||
const extendedPathRe = pathToRegexp(
|
||||
isWildcard ? '*' : `${pathPattern}/*`,
|
||||
extendedPathReKeys
|
||||
);
|
||||
|
||||
pathsByRouteNames[routeName] = {
|
||||
exactRe,
|
||||
exactReKeys,
|
||||
extendedPathRe,
|
||||
extendedPathReKeys,
|
||||
isWildcard,
|
||||
toPath:
|
||||
pathPattern === null ? () => '' : pathToRegexp.compile(pathPattern),
|
||||
};
|
||||
const keys = [];
|
||||
let re, toPath, priority;
|
||||
if (typeof pathPattern === 'string') {
|
||||
// pathPattern may be either a string or a regexp object according to path-to-regexp docs.
|
||||
re = pathToRegexp(pathPattern, keys);
|
||||
toPath = pathToRegexp.compile(pathPattern);
|
||||
priority = 0;
|
||||
} else if (pathPattern === null) {
|
||||
// for wildcard match
|
||||
re = pathToRegexp('*', keys);
|
||||
toPath = () => '';
|
||||
matchExact = true;
|
||||
priority = -1;
|
||||
}
|
||||
if (!matchExact) {
|
||||
const wildcardRe = pathToRegexp(`${pathPattern}/*`, keys);
|
||||
re = new RegExp(`(?:${re.source})|(?:${wildcardRe.source})`);
|
||||
}
|
||||
pathsByRouteNames[routeName] = { re, keys, toPath, priority, pathPattern };
|
||||
});
|
||||
|
||||
paths = Object.entries(pathsByRouteNames);
|
||||
paths.sort((a, b) => b[1].priority - a[1].priority);
|
||||
|
||||
const getActionForPathAndParams = (pathToResolve = '', inputParams = {}) => {
|
||||
// Attempt to match `pathToResolve` with a route in this router's routeConfigs, deferring to child routers
|
||||
const getActionForPathAndParams = (pathToResolve, inputParams = {}) => {
|
||||
// If the path is empty (null or empty string)
|
||||
// just return the initial route action
|
||||
if (!pathToResolve) {
|
||||
return NavigationActions.navigate({
|
||||
routeName: initialRouteName,
|
||||
params: { ...inputParams, ...initialRouteParams },
|
||||
});
|
||||
}
|
||||
|
||||
let matchedAction = null;
|
||||
// Attempt to match `pathToResolve` with a route in this router's
|
||||
// routeConfigs
|
||||
let matchedRouteName;
|
||||
let pathMatch;
|
||||
let pathMatchKeys;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const [routeName, path] of paths) {
|
||||
const { exactRe, exactReKeys, extendedPathRe, extendedPathReKeys } = path;
|
||||
const childRouter = childRouters[routeName];
|
||||
|
||||
const exactMatch = exactRe && exactRe.exec(pathToResolve);
|
||||
|
||||
if (exactMatch && exactMatch.length) {
|
||||
const extendedMatch =
|
||||
extendedPathRe && extendedPathRe.exec(pathToResolve);
|
||||
let childAction = null;
|
||||
if (extendedMatch && childRouter) {
|
||||
const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);
|
||||
childAction = childRouter.getActionForPathAndParams(
|
||||
restOfPath,
|
||||
inputParams
|
||||
);
|
||||
}
|
||||
|
||||
return NavigationActions.navigate({
|
||||
routeName,
|
||||
params: getParamsFromPath(inputParams, exactMatch, exactReKeys),
|
||||
action: childAction,
|
||||
});
|
||||
const { re, keys } = path;
|
||||
pathMatch = re.exec(pathToResolve);
|
||||
if (pathMatch && pathMatch.length) {
|
||||
pathMatchKeys = keys;
|
||||
matchedRouteName = routeName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const [routeName, path] of paths) {
|
||||
const { extendedPathRe, extendedPathReKeys } = path;
|
||||
const childRouter = childRouters[routeName];
|
||||
// We didn't match -- return null to signify no action available
|
||||
if (!matchedRouteName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const extendedMatch =
|
||||
extendedPathRe && extendedPathRe.exec(pathToResolve);
|
||||
|
||||
if (extendedMatch && extendedMatch.length) {
|
||||
const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);
|
||||
let childAction = null;
|
||||
if (childRouter) {
|
||||
childAction = childRouter.getActionForPathAndParams(
|
||||
restOfPath,
|
||||
inputParams
|
||||
);
|
||||
}
|
||||
if (!childAction) {
|
||||
continue;
|
||||
}
|
||||
return NavigationActions.navigate({
|
||||
routeName,
|
||||
params: getParamsFromPath(
|
||||
inputParams,
|
||||
extendedMatch,
|
||||
extendedPathReKeys
|
||||
),
|
||||
action: childAction,
|
||||
});
|
||||
// Determine nested actions:
|
||||
// If our matched route for this router is a child router,
|
||||
// get the action for the path AFTER the matched path for this
|
||||
// router
|
||||
let nestedAction;
|
||||
if (childRouters[matchedRouteName]) {
|
||||
nestedAction = childRouters[matchedRouteName].getActionForPathAndParams(
|
||||
pathMatch.slice(pathMatchKeys.length).join('/'),
|
||||
inputParams
|
||||
);
|
||||
if (!nestedAction) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
const params = pathMatch.slice(1).reduce(
|
||||
// iterate over matched path params
|
||||
(paramsOut, matchResult, i) => {
|
||||
const key = pathMatchKeys[i];
|
||||
if (!key || key.asterisk) {
|
||||
return paramsOut;
|
||||
}
|
||||
const paramName = key.name;
|
||||
|
||||
let decodedMatchResult;
|
||||
try {
|
||||
decodedMatchResult = decodeURIComponent(matchResult);
|
||||
} catch (e) {
|
||||
// ignore `URIError: malformed URI`
|
||||
}
|
||||
|
||||
paramsOut[paramName] = decodedMatchResult || matchResult;
|
||||
return paramsOut;
|
||||
},
|
||||
{
|
||||
// start with the input(query string) params, which will get overridden by path params
|
||||
...inputParams,
|
||||
}
|
||||
);
|
||||
|
||||
return NavigationActions.navigate({
|
||||
routeName: matchedRouteName,
|
||||
...(params ? { params } : {}),
|
||||
...(nestedAction ? { action: nestedAction } : {}),
|
||||
});
|
||||
};
|
||||
const getPathAndParamsForRoute = route => {
|
||||
const { routeName, params } = route;
|
||||
const childRouter = childRouters[routeName];
|
||||
const { toPath, exactReKeys } = pathsByRouteNames[routeName];
|
||||
const subPath = toPath(params);
|
||||
const nonPathParams = {};
|
||||
if (params) {
|
||||
Object.keys(params)
|
||||
.filter(paramName => !exactReKeys.find(k => k.name === paramName))
|
||||
.forEach(paramName => {
|
||||
nonPathParams[paramName] = params[paramName];
|
||||
});
|
||||
}
|
||||
const subPath = pathsByRouteNames[routeName].toPath(params);
|
||||
if (childRouter) {
|
||||
// If it has a router it's a navigator.
|
||||
// If it doesn't have router it's an ordinary React component.
|
||||
const child = childRouter.getPathAndParamsForState(route);
|
||||
return {
|
||||
path: subPath ? `${subPath}/${child.path}` : child.path,
|
||||
params: child.params
|
||||
? { ...nonPathParams, ...child.params }
|
||||
: nonPathParams,
|
||||
params: child.params ? { ...params, ...child.params } : params,
|
||||
};
|
||||
}
|
||||
return {
|
||||
path: subPath,
|
||||
params: nonPathParams,
|
||||
params,
|
||||
};
|
||||
};
|
||||
return { getActionForPathAndParams, getPathAndParamsForRoute };
|
||||
|
||||
@@ -141,7 +141,7 @@ class Header extends React.PureComponent {
|
||||
return options.headerLeft;
|
||||
}
|
||||
|
||||
if (!options.headerLeft && props.scene.index === 0) {
|
||||
if (props.scene.index === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -220,11 +220,6 @@ class Header extends React.PureComponent {
|
||||
|
||||
const { transitionPreset } = this.props;
|
||||
|
||||
let { style } = props;
|
||||
if (options.headerLeftContainerStyle) {
|
||||
style = [style, options.headerLeftContainerStyle];
|
||||
}
|
||||
|
||||
// On Android, or if we have a custom header left, or if we have a custom back image, we
|
||||
// do not use the modular header (which is the one that imitates UINavigationController)
|
||||
if (
|
||||
@@ -234,14 +229,14 @@ class Header extends React.PureComponent {
|
||||
options.headerLeft === null
|
||||
) {
|
||||
return this._renderSubView(
|
||||
{ ...props, style },
|
||||
props,
|
||||
'left',
|
||||
this._renderLeftComponent,
|
||||
this.props.leftInterpolator
|
||||
);
|
||||
} else {
|
||||
return this._renderModularSubView(
|
||||
{ ...props, style },
|
||||
props,
|
||||
'left',
|
||||
this._renderModularLeftComponent,
|
||||
this.props.leftLabelInterpolator,
|
||||
@@ -251,7 +246,7 @@ class Header extends React.PureComponent {
|
||||
}
|
||||
|
||||
_renderTitle(props, options) {
|
||||
let style = {};
|
||||
const style = {};
|
||||
const { transitionPreset } = this.props;
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
@@ -269,9 +264,6 @@ class Header extends React.PureComponent {
|
||||
style.left = 0;
|
||||
style.right = 0;
|
||||
}
|
||||
if (options.headerTitleContainerStyle) {
|
||||
style = [style, options.headerTitleContainerStyle];
|
||||
}
|
||||
|
||||
return this._renderSubView(
|
||||
{ ...props, style },
|
||||
@@ -284,15 +276,8 @@ class Header extends React.PureComponent {
|
||||
}
|
||||
|
||||
_renderRight(props) {
|
||||
const { options } = props.scene.descriptor;
|
||||
|
||||
let { style } = props;
|
||||
if (options.headerRightContainerStyle) {
|
||||
style = [style, options.headerRightContainerStyle];
|
||||
}
|
||||
|
||||
return this._renderSubView(
|
||||
{ ...props, style },
|
||||
props,
|
||||
'right',
|
||||
this._renderRightComponent,
|
||||
this.props.rightInterpolator
|
||||
@@ -407,7 +392,6 @@ class Header extends React.PureComponent {
|
||||
const title = this._renderTitle(props, {
|
||||
hasLeftComponent: !!left,
|
||||
hasRightComponent: !!right,
|
||||
headerTitleContainerStyle: options.headerTitleContainerStyle,
|
||||
});
|
||||
|
||||
const { isLandscape, transitionPreset } = this.props;
|
||||
@@ -602,8 +586,6 @@ const styles = StyleSheet.create({
|
||||
left: 0,
|
||||
right: 0,
|
||||
...platformContainerStyles,
|
||||
borderBottomWidth: 0,
|
||||
borderBottomColor: 'transparent',
|
||||
elevation: 0,
|
||||
},
|
||||
header: {
|
||||
|
||||
@@ -130,26 +130,16 @@ export default function ScenesReducer(
|
||||
return;
|
||||
}
|
||||
const lastScene = scenes.find(scene => scene.route.key === route.key);
|
||||
const descriptor = lastScene && lastScene.descriptor;
|
||||
|
||||
// We can get into a weird place where we have a queued transition and then clobber
|
||||
// that transition without ever actually rendering the scene, in which case
|
||||
// there is no lastScene. If the descriptor is not available on the lastScene
|
||||
// or the descriptors prop then we just skip adding it to stale scenes and it's
|
||||
// not ever rendered.
|
||||
const descriptor = lastScene
|
||||
? lastScene.descriptor
|
||||
: descriptors[route.key];
|
||||
|
||||
if (descriptor) {
|
||||
staleScenes.set(key, {
|
||||
index,
|
||||
isActive: false,
|
||||
isStale: true,
|
||||
key,
|
||||
route,
|
||||
descriptor,
|
||||
});
|
||||
}
|
||||
staleScenes.set(key, {
|
||||
index,
|
||||
isActive: false,
|
||||
isStale: true,
|
||||
key,
|
||||
route,
|
||||
descriptor,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,10 @@ class StackView extends React.Component {
|
||||
screenProps={this.props.screenProps}
|
||||
navigation={this.props.navigation}
|
||||
descriptors={this.props.descriptors}
|
||||
onTransitionStart={
|
||||
this.props.onTransitionStart ||
|
||||
this.props.navigationConfig.onTransitionStart
|
||||
}
|
||||
onTransitionStart={this.props.onTransitionStart}
|
||||
onTransitionEnd={(transition, lastTransition) => {
|
||||
const { navigationConfig, navigation } = this.props;
|
||||
const onTransitionEnd =
|
||||
this.props.onTransitionEnd || navigationConfig.onTransitionEnd;
|
||||
const { onTransitionEnd } = navigationConfig;
|
||||
if (transition.navigation.state.isTransitioning) {
|
||||
navigation.dispatch(
|
||||
StackActions.completeTransition({
|
||||
|
||||
@@ -166,7 +166,7 @@ class Transitioner extends React.Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View onLayout={this._onLayout} style={styles.main}>
|
||||
<View onLayout={this._onLayout} style={[styles.main]}>
|
||||
{this.props.render(this._transitionProps, this._prevTransitionProps)}
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import ScenesReducer from '../ScenesReducer';
|
||||
|
||||
const MOCK_DESCRIPTOR = {};
|
||||
|
||||
/**
|
||||
* Simulate scenes transtion with changes of navigation states.
|
||||
*/
|
||||
function testTransition(states) {
|
||||
let descriptors = states
|
||||
.reduce((acc, state) => acc.concat(state), [])
|
||||
.reduce((acc, key) => {
|
||||
acc[key] = MOCK_DESCRIPTOR;
|
||||
return acc;
|
||||
}, {});
|
||||
const routes = states.map(keys => ({
|
||||
index: 0,
|
||||
routes: keys.map(key => ({ key, routeName: '' })),
|
||||
@@ -21,7 +13,7 @@ function testTransition(states) {
|
||||
let scenes = [];
|
||||
let prevState = null;
|
||||
routes.forEach(nextState => {
|
||||
scenes = ScenesReducer(scenes, nextState, prevState, descriptors);
|
||||
scenes = ScenesReducer(scenes, nextState, prevState);
|
||||
prevState = nextState;
|
||||
});
|
||||
|
||||
@@ -37,7 +29,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: true,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_1',
|
||||
route: {
|
||||
key: '1',
|
||||
@@ -48,7 +39,6 @@ describe('ScenesReducer', () => {
|
||||
index: 1,
|
||||
isActive: false,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_2',
|
||||
route: {
|
||||
key: '2',
|
||||
@@ -67,7 +57,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: true,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_1',
|
||||
route: {
|
||||
key: '1',
|
||||
@@ -78,7 +67,6 @@ describe('ScenesReducer', () => {
|
||||
index: 1,
|
||||
isActive: false,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_2',
|
||||
route: {
|
||||
key: '2',
|
||||
@@ -89,7 +77,6 @@ describe('ScenesReducer', () => {
|
||||
index: 2,
|
||||
isActive: false,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_3',
|
||||
route: {
|
||||
key: '3',
|
||||
@@ -149,10 +136,8 @@ describe('ScenesReducer', () => {
|
||||
isTransitioning: false,
|
||||
};
|
||||
|
||||
const descriptors = { 1: jest.mock(), 2: jest.mock() };
|
||||
|
||||
const scenes1 = ScenesReducer([], state1, null, descriptors);
|
||||
const scenes2 = ScenesReducer(scenes1, state2, state1, descriptors);
|
||||
const scenes1 = ScenesReducer([], state1, null);
|
||||
const scenes2 = ScenesReducer(scenes1, state2, state1);
|
||||
expect(scenes1).not.toBe(scenes2);
|
||||
});
|
||||
|
||||
@@ -175,10 +160,8 @@ describe('ScenesReducer', () => {
|
||||
isTransitioning: false,
|
||||
};
|
||||
|
||||
const descriptors = { 1: MOCK_DESCRIPTOR, 2: MOCK_DESCRIPTOR };
|
||||
|
||||
const scenes1 = ScenesReducer([], state1, null, descriptors);
|
||||
const scenes2 = ScenesReducer(scenes1, state2, state1, descriptors);
|
||||
const scenes1 = ScenesReducer([], state1, null);
|
||||
const scenes2 = ScenesReducer(scenes1, state2, state1);
|
||||
expect(scenes1).not.toBe(scenes2);
|
||||
});
|
||||
|
||||
@@ -201,9 +184,8 @@ describe('ScenesReducer', () => {
|
||||
isTransitioning: false,
|
||||
};
|
||||
|
||||
const descriptors = { 1: MOCK_DESCRIPTOR, 2: MOCK_DESCRIPTOR };
|
||||
const scenes1 = ScenesReducer([], state1, null, descriptors);
|
||||
const scenes2 = ScenesReducer(scenes1, state2, state1, descriptors);
|
||||
const scenes1 = ScenesReducer([], state1, null);
|
||||
const scenes2 = ScenesReducer(scenes1, state2, state1);
|
||||
expect(scenes1).not.toBe(scenes2);
|
||||
});
|
||||
|
||||
@@ -216,7 +198,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: true,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_1',
|
||||
route: {
|
||||
key: '1',
|
||||
@@ -227,7 +208,6 @@ describe('ScenesReducer', () => {
|
||||
index: 1,
|
||||
isActive: false,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_2',
|
||||
route: {
|
||||
key: '2',
|
||||
@@ -238,7 +218,6 @@ describe('ScenesReducer', () => {
|
||||
index: 2,
|
||||
isActive: false,
|
||||
isStale: true,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_3',
|
||||
route: {
|
||||
key: '3',
|
||||
@@ -256,7 +235,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: false,
|
||||
isStale: true,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_1',
|
||||
route: {
|
||||
key: '1',
|
||||
@@ -267,7 +245,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: true,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_3',
|
||||
route: {
|
||||
key: '3',
|
||||
@@ -278,7 +255,6 @@ describe('ScenesReducer', () => {
|
||||
index: 1,
|
||||
isActive: false,
|
||||
isStale: true,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_2',
|
||||
route: {
|
||||
key: '2',
|
||||
@@ -296,7 +272,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: false,
|
||||
isStale: true,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_1',
|
||||
route: {
|
||||
key: '1',
|
||||
@@ -307,7 +282,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: true,
|
||||
isStale: false,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_2',
|
||||
route: {
|
||||
key: '2',
|
||||
@@ -318,7 +292,6 @@ describe('ScenesReducer', () => {
|
||||
index: 0,
|
||||
isActive: false,
|
||||
isStale: true,
|
||||
descriptor: MOCK_DESCRIPTOR,
|
||||
key: 'scene_3',
|
||||
route: {
|
||||
key: '3',
|
||||
|
||||
Reference in New Issue
Block a user