Compare commits

...

4 Commits

Author SHA1 Message Date
Michal Osadnik
d5b4210eb2 chore: publish
- @react-navigation/bottom-tabs@5.0.0-alpha.5
 - @react-navigation/drawer@5.0.0-alpha.5
 - @react-navigation/material-bottom-tabs@5.0.0-alpha.5
 - @react-navigation/material-top-tabs@5.0.0-alpha.5
 - @react-navigation/routers@5.0.0-alpha.5
 - @react-navigation/stack@5.0.0-alpha.6
2019-08-28 11:22:18 +01:00
Michal Osadnik
38336b0290 feat: disable gesture logic when no gesture stack 2019-08-28 11:22:04 +01:00
satyajit.happy
fc37e93b5b chore: add some badges 2019-08-27 17:09:59 +02:00
satyajit.happy
093858b68b test: improve coverage for router tests 2019-08-27 16:58:43 +02:00
17 changed files with 1163 additions and 51 deletions

View File

@@ -1,5 +1,9 @@
# Rethinking Navigation # Rethinking Navigation
[![Build Status][build-badge]][build]
[![Code Coverage][coverage-badge]][coverage]
[![MIT License][license-badge]][license]
An exploration of a component-first API for React Navigation for building more dynamic navigation solutions. An exploration of a component-first API for React Navigation for building more dynamic navigation solutions.
## Considerations ## Considerations
@@ -530,3 +534,12 @@ yarn lerna publish
``` ```
This will automatically bump the version and publish the packages. It'll also publish the changelogs on GitHub for each package. This will automatically bump the version and publish the packages. It'll also publish the changelogs on GitHub for each package.
<!-- badges -->
[build-badge]: https://img.shields.io/circleci/project/github/react-navigation/navigation-ex/master.svg?style=flat-square
[build]: https://circleci.com/gh/react-navigation/navigation-ex
[coverage-badge]: https://img.shields.io/codecov/c/github/react-navigation/navigation-ex.svg?style=flat-square
[coverage]: https://codecov.io/github/react-navigation/navigation-ex
[license-badge]: https://img.shields.io/npm/l/@react-navigation/core.svg?style=flat-square
[license]: https://opensource.org/licenses/MIT

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.4...@react-navigation/bottom-tabs@5.0.0-alpha.5) (2019-08-28)
**Note:** Version bump only for package @react-navigation/bottom-tabs
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.3...@react-navigation/bottom-tabs@5.0.0-alpha.4) (2019-08-27) # [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.3...@react-navigation/bottom-tabs@5.0.0-alpha.4) (2019-08-27)

View File

@@ -10,7 +10,7 @@
"android", "android",
"tab" "tab"
], ],
"version": "5.0.0-alpha.4", "version": "5.0.0-alpha.5",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
@@ -33,7 +33,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/routers": "^5.0.0-alpha.4", "@react-navigation/routers": "^5.0.0-alpha.5",
"react-native-safe-area-view": "^0.14.6" "react-native-safe-area-view": "^0.14.6"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.4...@react-navigation/drawer@5.0.0-alpha.5) (2019-08-28)
**Note:** Version bump only for package @react-navigation/drawer
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.3...@react-navigation/drawer@5.0.0-alpha.4) (2019-08-27) # [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.3...@react-navigation/drawer@5.0.0-alpha.4) (2019-08-27)
**Note:** Version bump only for package @react-navigation/drawer **Note:** Version bump only for package @react-navigation/drawer

View File

@@ -11,7 +11,7 @@
"material", "material",
"drawer" "drawer"
], ],
"version": "5.0.0-alpha.4", "version": "5.0.0-alpha.5",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
@@ -34,7 +34,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/routers": "^5.0.0-alpha.4", "@react-navigation/routers": "^5.0.0-alpha.5",
"react-native-safe-area-view": "^0.14.6" "react-native-safe-area-view": "^0.14.6"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.4...@react-navigation/material-bottom-tabs@5.0.0-alpha.5) (2019-08-28)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.3...@react-navigation/material-bottom-tabs@5.0.0-alpha.4) (2019-08-27) # [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.3...@react-navigation/material-bottom-tabs@5.0.0-alpha.4) (2019-08-27)

View File

@@ -11,7 +11,7 @@
"material", "material",
"tab" "tab"
], ],
"version": "5.0.0-alpha.4", "version": "5.0.0-alpha.5",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
@@ -34,7 +34,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/routers": "^5.0.0-alpha.4" "@react-navigation/routers": "^5.0.0-alpha.5"
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.7.0", "@react-native-community/bob": "^0.7.0",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.4...@react-navigation/material-top-tabs@5.0.0-alpha.5) (2019-08-28)
**Note:** Version bump only for package @react-navigation/material-top-tabs
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.3...@react-navigation/material-top-tabs@5.0.0-alpha.4) (2019-08-27) # [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.3...@react-navigation/material-top-tabs@5.0.0-alpha.4) (2019-08-27)

View File

@@ -11,7 +11,7 @@
"material", "material",
"tab" "tab"
], ],
"version": "5.0.0-alpha.4", "version": "5.0.0-alpha.5",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
@@ -34,7 +34,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/routers": "^5.0.0-alpha.4" "@react-navigation/routers": "^5.0.0-alpha.5"
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.7.0", "@react-native-community/bob": "^0.7.0",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.4...@react-navigation/routers@5.0.0-alpha.5) (2019-08-28)
**Note:** Version bump only for package @react-navigation/routers
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.3...@react-navigation/routers@5.0.0-alpha.4) (2019-08-27) # [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.3...@react-navigation/routers@5.0.0-alpha.4) (2019-08-27)
**Note:** Version bump only for package @react-navigation/routers **Note:** Version bump only for package @react-navigation/routers

View File

@@ -1,8 +1,190 @@
import { CommonActions } from '@react-navigation/core'; import { CommonActions } from '@react-navigation/core';
import { DrawerRouter } from '../src'; import { DrawerRouter, DrawerActions } from '../src';
jest.mock('shortid', () => () => 'test'); jest.mock('shortid', () => () => 'test');
it('gets initial state from route names and params with initialRouteName', () => {
const router = DrawerRouter({ initialRouteName: 'baz' });
expect(
router.getInitialState({
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
})
).toEqual({
index: 1,
key: 'drawer-test',
isDrawerOpen: false,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
});
it('gets initial state from route names and params without initialRouteName', () => {
const router = DrawerRouter({});
expect(
router.getInitialState({
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
})
).toEqual({
index: 0,
key: 'drawer-test',
isDrawerOpen: false,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
});
it('gets rehydrated state from partial state', () => {
const router = DrawerRouter({});
const options = {
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
};
expect(
router.getRehydratedState(
{
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'qux-1', name: 'qux' }],
},
options
)
).toEqual({
index: 0,
key: 'drawer-test',
isDrawerOpen: false,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-1', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 2,
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-1', name: 'baz' },
{ key: 'qux-2', name: 'qux' },
],
},
options
)
).toEqual({
index: 2,
key: 'drawer-test',
isDrawerOpen: false,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-1', name: 'baz', params: { answer: 42 } },
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 4,
routes: [],
},
options
)
).toEqual({
index: 0,
key: 'drawer-test',
isDrawerOpen: false,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 1,
isDrawerOpen: true,
routeKeyHistory: ['bar-test', 'qux-test', 'foo-test'],
routes: [],
},
options
)
).toEqual({
index: 1,
key: 'drawer-test',
isDrawerOpen: true,
routeKeyHistory: ['bar-test', 'qux-test'],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
});
it("doesn't rehydrate state if it's not stale", () => {
const router = DrawerRouter({});
const state = {
index: 0,
key: 'drawer-test',
isDrawerOpen: true,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false as const,
};
expect(
router.getRehydratedState(state, {
routeNames: [],
routeParamList: {},
})
).toBe(state);
});
it('handles navigate action', () => { it('handles navigate action', () => {
const router = DrawerRouter({}); const router = DrawerRouter({});
@@ -47,7 +229,7 @@ it('handles open drawer action', () => {
isDrawerOpen: false, isDrawerOpen: false,
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'OPEN_DRAWER' } DrawerActions.openDrawer()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -58,6 +240,20 @@ it('handles open drawer action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}); });
const state = {
stale: false as const,
key: 'root',
index: 1,
routeNames: ['baz', 'bar'],
isDrawerOpen: true,
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
};
expect(router.getStateForAction(state, DrawerActions.openDrawer())).toBe(
state
);
}); });
it('handles close drawer action', () => { it('handles close drawer action', () => {
@@ -74,7 +270,7 @@ it('handles close drawer action', () => {
isDrawerOpen: true, isDrawerOpen: true,
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'CLOSE_DRAWER' } DrawerActions.closeDrawer()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -85,6 +281,20 @@ it('handles close drawer action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}); });
const state = {
stale: false as const,
key: 'root',
index: 1,
routeNames: ['baz', 'bar'],
isDrawerOpen: false,
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
};
expect(router.getStateForAction(state, DrawerActions.closeDrawer())).toBe(
state
);
}); });
it('handles toggle drawer action', () => { it('handles toggle drawer action', () => {
@@ -101,7 +311,7 @@ it('handles toggle drawer action', () => {
isDrawerOpen: true, isDrawerOpen: true,
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'TOGGLE_DRAWER' } DrawerActions.toggleDrawer()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -124,7 +334,7 @@ it('handles toggle drawer action', () => {
isDrawerOpen: false, isDrawerOpen: false,
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'TOGGLE_DRAWER' } DrawerActions.toggleDrawer()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -136,3 +346,95 @@ it('handles toggle drawer action', () => {
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}); });
}); });
it('updates route key history on focus change', () => {
const router = DrawerRouter({ backBehavior: 'history' });
const state = {
index: 0,
key: 'drawer-test',
isDrawerOpen: false,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz', params: { answer: 42 } },
{ key: 'qux-0', name: 'qux', params: { name: 'Jane' } },
],
stale: false as const,
};
expect(router.getStateForRouteFocus(state, 'bar-0').routeKeyHistory).toEqual(
[]
);
expect(router.getStateForRouteFocus(state, 'baz-0').routeKeyHistory).toEqual([
'bar-0',
]);
});
it('closes drawer on focus change', () => {
const router = DrawerRouter({ backBehavior: 'history' });
expect(
router.getStateForRouteFocus(
{
index: 0,
key: 'drawer-test',
isDrawerOpen: false,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz' },
{ key: 'qux-0', name: 'qux' },
],
stale: false,
},
'baz-0'
)
).toEqual({
index: 1,
isDrawerOpen: false,
key: 'drawer-test',
routeKeyHistory: ['bar-0'],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz' },
{ key: 'qux-0', name: 'qux' },
],
stale: false,
});
expect(
router.getStateForRouteFocus(
{
index: 0,
key: 'drawer-test',
isDrawerOpen: true,
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz' },
{ key: 'qux-0', name: 'qux' },
],
stale: false,
},
'baz-0'
)
).toEqual({
index: 1,
isDrawerOpen: false,
key: 'drawer-test',
routeKeyHistory: ['bar-0'],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz' },
{ key: 'qux-0', name: 'qux' },
],
stale: false,
});
});

View File

@@ -1,8 +1,173 @@
import { CommonActions } from '@react-navigation/core'; import { CommonActions } from '@react-navigation/core';
import { StackRouter } from '../src'; import { StackRouter, StackActions } from '../src';
jest.mock('shortid', () => () => 'test'); jest.mock('shortid', () => () => 'test');
it('gets initial state from route names and params with initialRouteName', () => {
const router = StackRouter({ initialRouteName: 'baz' });
expect(
router.getInitialState({
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
})
).toEqual({
index: 0,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [{ key: 'baz-test', name: 'baz', params: { answer: 42 } }],
stale: false,
});
});
it('gets initial state from route names and params without initialRouteName', () => {
const router = StackRouter({});
expect(
router.getInitialState({
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
})
).toEqual({
index: 0,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [{ key: 'bar-test', name: 'bar' }],
stale: false,
});
});
it('gets rehydrated state from partial state', () => {
const router = StackRouter({});
const options = {
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
};
expect(
router.getRehydratedState(
{
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'qux-1', name: 'qux' }],
},
options
)
).toEqual({
index: 1,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'qux-1', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 2,
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-1', name: 'baz' },
{ key: 'qux-2', name: 'qux' },
],
},
options
)
).toEqual({
index: 2,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-1', name: 'baz', params: { answer: 42 } },
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 4,
routes: [],
},
options
)
).toEqual({
index: 0,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [{ key: 'bar-test', name: 'bar' }],
stale: false,
});
});
it("doesn't rehydrate state if it's not stale", () => {
const router = StackRouter({});
const state = {
index: 0,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [{ key: 'bar-test', name: 'bar' }],
stale: false as const,
};
expect(
router.getRehydratedState(state, {
routeNames: [],
routeParamList: {},
})
).toBe(state);
});
it('gets state on route names change', () => {
const router = StackRouter({});
expect(
router.getStateForRouteNamesChange(
{
index: 0,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
},
{
routeNames: ['qux', 'baz', 'foo', 'fiz'],
routeParamList: {
qux: { name: 'John' },
fiz: { fruit: 'apple' },
},
}
)
).toEqual({
index: 0,
key: 'stack-test',
routeNames: ['qux', 'baz', 'foo', 'fiz'],
routes: [
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
});
it('handles navigate action', () => { it('handles navigate action', () => {
const router = StackRouter({}); const router = StackRouter({});
@@ -28,12 +193,80 @@ it('handles navigate action', () => {
{ {
key: 'qux-test', key: 'qux-test',
name: 'qux', name: 'qux',
params: { params: { answer: 42 },
answer: 42,
},
}, },
], ],
}); });
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
},
CommonActions.navigate('baz', { answer: 42 })
)
).toEqual({
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz', params: { answer: 42 } }],
});
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar', 'qux'],
routes: [
{ key: 'baz', name: 'baz' },
{ key: 'bar', name: 'bar', params: { answer: 42 } },
],
},
CommonActions.navigate('bar', { answer: 96 })
)
).toEqual({
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar', 'qux'],
routes: [
{ key: 'baz', name: 'baz' },
{ key: 'bar', name: 'bar', params: { answer: 96 } },
],
});
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
},
CommonActions.navigate('unknown')
)
).toBe(null);
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz-0', name: 'baz' }, { key: 'bar-0', name: 'bar' }],
},
CommonActions.navigate({ key: 'unknown' })
)
).toBe(null);
}); });
it('handles go back action', () => { it('handles go back action', () => {
@@ -48,7 +281,7 @@ it('handles go back action', () => {
routeNames: ['baz', 'bar', 'qux'], routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'GO_BACK' } CommonActions.goBack()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -57,6 +290,19 @@ it('handles go back action', () => {
routeNames: ['baz', 'bar', 'qux'], routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz' }], routes: [{ key: 'baz', name: 'baz' }],
}); });
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz' }],
},
CommonActions.goBack()
)
).toBe(null);
}); });
it('handles pop action', () => { it('handles pop action', () => {
@@ -75,7 +321,30 @@ it('handles pop action', () => {
{ key: 'qux', name: 'qux' }, { key: 'qux', name: 'qux' },
], ],
}, },
{ type: 'POP', payload: { count: 2 } } StackActions.pop()
)
).toEqual({
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
});
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 2,
routeNames: ['baz', 'bar', 'qux'],
routes: [
{ key: 'baz', name: 'baz' },
{ key: 'bar', name: 'bar' },
{ key: 'qux', name: 'qux' },
],
},
StackActions.pop(2)
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -84,6 +353,46 @@ it('handles pop action', () => {
routeNames: ['baz', 'bar', 'qux'], routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz', name: 'baz' }], routes: [{ key: 'baz', name: 'baz' }],
}); });
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 2,
routeNames: ['baz', 'bar', 'qux'],
routes: [
{ key: 'baz-0', name: 'baz' },
{ key: 'bar-0', name: 'bar' },
{ key: 'qux-0', name: 'qux' },
],
},
{
...StackActions.pop(),
target: 'root',
source: 'bar-0',
}
)
).toEqual({
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz-0', name: 'baz' }],
});
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'baz-0', name: 'baz' }],
},
StackActions.pop()
)
).toBe(null);
}); });
it('handles pop to top action', () => { it('handles pop to top action', () => {
@@ -102,7 +411,7 @@ it('handles pop to top action', () => {
{ key: 'qux', name: 'qux' }, { key: 'qux', name: 'qux' },
], ],
}, },
{ type: 'POP_TO_TOP' } StackActions.popToTop()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -125,7 +434,7 @@ it('handles push action', () => {
routeNames: ['baz', 'bar', 'qux'], routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'bar', name: 'bar' }], routes: [{ key: 'bar', name: 'bar' }],
}, },
{ type: 'PUSH', payload: { name: 'baz' } } StackActions.push('baz')
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -134,4 +443,54 @@ it('handles push action', () => {
routeNames: ['baz', 'bar', 'qux'], routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'bar', name: 'bar' }, { key: 'baz-test', name: 'baz' }], routes: [{ key: 'bar', name: 'bar' }, { key: 'baz-test', name: 'baz' }],
}); });
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 2,
routeNames: ['baz', 'bar', 'qux'],
routes: [{ key: 'bar', name: 'bar' }],
},
StackActions.push('unknown')
)
).toBe(null);
});
it('changes index on focus change', () => {
const router = StackRouter({});
expect(
router.getStateForRouteFocus(
{
index: 2,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz' },
{ key: 'qux-0', name: 'qux' },
],
stale: false,
},
'baz-0'
)
).toEqual({
index: 1,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'baz-0', name: 'baz' }],
stale: false,
});
const state = {
index: 0,
key: 'stack-test',
routeNames: ['bar', 'baz', 'qux'],
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'baz-0', name: 'baz' }],
stale: false as const,
};
expect(router.getStateForRouteFocus(state, 'qux-0')).toEqual(state);
}); });

View File

@@ -1,11 +1,249 @@
import { CommonActions } from '@react-navigation/core'; import { CommonActions } from '@react-navigation/core';
import { TabRouter } from '../src'; import { TabRouter, TabActions, TabNavigationState } from '../src';
jest.mock('shortid', () => () => 'test'); jest.mock('shortid', () => () => 'test');
it('gets initial state from route names and params with initialRouteName', () => {
const router = TabRouter({ initialRouteName: 'baz' });
expect(
router.getInitialState({
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
})
).toEqual({
index: 1,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
});
it('gets initial state from route names and params without initialRouteName', () => {
const router = TabRouter({});
expect(
router.getInitialState({
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
})
).toEqual({
index: 0,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
});
it('gets rehydrated state from partial state', () => {
const router = TabRouter({});
const options = {
routeNames: ['bar', 'baz', 'qux'],
routeParamList: {
baz: { answer: 42 },
qux: { name: 'Jane' },
},
};
expect(
router.getRehydratedState(
{
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'qux-1', name: 'qux' }],
},
options
)
).toEqual({
index: 0,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-1', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 2,
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-1', name: 'baz' },
{ key: 'qux-2', name: 'qux' },
],
},
options
)
).toEqual({
index: 2,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-1', name: 'baz', params: { answer: 42 } },
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 4,
routes: [],
},
options
)
).toEqual({
index: 0,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
expect(
router.getRehydratedState(
{
index: 1,
routeKeyHistory: ['bar-test', 'qux-test', 'foo-test'],
routes: [],
},
options
)
).toEqual({
index: 1,
key: 'tab-test',
routeKeyHistory: ['bar-test', 'qux-test'],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
});
});
it("doesn't rehydrate state if it's not stale", () => {
const router = TabRouter({});
const state = {
index: 0,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false as const,
};
expect(
router.getRehydratedState(state, {
routeNames: [],
routeParamList: {},
})
).toBe(state);
});
it('gets state on route names change', () => {
const router = TabRouter({});
expect(
router.getStateForRouteNamesChange(
{
index: 0,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-test', name: 'bar' },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
],
stale: false,
},
{
routeNames: ['qux', 'baz', 'foo', 'fiz'],
routeParamList: {
qux: { name: 'John' },
fiz: { fruit: 'apple' },
},
}
)
).toEqual({
index: 0,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['qux', 'baz', 'foo', 'fiz'],
routes: [
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
{ key: 'foo-test', name: 'foo' },
{ key: 'fiz-test', name: 'fiz', params: { fruit: 'apple' } },
],
stale: false,
});
});
it('handles navigate action', () => { it('handles navigate action', () => {
const router = TabRouter({}); const router = TabRouter({});
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar'],
routeKeyHistory: [],
routes: [{ key: 'baz-1', name: 'baz' }, { key: 'bar-1', name: 'bar' }],
},
CommonActions.navigate({ key: 'bar-1', params: { answer: 42 } })
)
).toEqual({
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar'],
routeKeyHistory: ['bar-1'],
routes: [
{ key: 'baz-1', name: 'baz' },
{ key: 'bar-1', name: 'bar', params: { answer: 42 } },
],
});
expect( expect(
router.getStateForAction( router.getStateForAction(
{ {
@@ -29,6 +267,20 @@ it('handles navigate action', () => {
{ key: 'bar', name: 'bar' }, { key: 'bar', name: 'bar' },
], ],
}); });
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar'],
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
},
CommonActions.navigate('non-existent')
)
).toBe(null);
}); });
it('handles jump to action', () => { it('handles jump to action', () => {
@@ -44,7 +296,7 @@ it('handles jump to action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'JUMP_TO', payload: { name: 'bar' } } TabActions.jumpTo('bar')
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -56,8 +308,8 @@ it('handles jump to action', () => {
}); });
}); });
it('handles history back action', () => { it('handles back action with backBehavior: history', () => {
const router = TabRouter({}); const router = TabRouter({ backBehavior: 'history' });
expect( expect(
router.getStateForAction( router.getStateForAction(
@@ -69,7 +321,7 @@ it('handles history back action', () => {
routeKeyHistory: ['bar'], routeKeyHistory: ['bar'],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'GO_BACK' } CommonActions.goBack()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -79,9 +331,23 @@ it('handles history back action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}); });
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar'],
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
},
CommonActions.goBack()
)
).toBe(null);
}); });
it('handles order back action', () => { it('handles back action with backBehavior: order', () => {
const router = TabRouter({ backBehavior: 'order' }); const router = TabRouter({ backBehavior: 'order' });
expect( expect(
@@ -94,7 +360,7 @@ it('handles order back action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'GO_BACK' } CommonActions.goBack()
) )
).toEqual({ ).toEqual({
stale: false, stale: false,
@@ -104,10 +370,48 @@ it('handles order back action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}); });
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar'],
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
},
CommonActions.goBack()
)
).toBe(null);
}); });
it('handles initialRoute back action', () => { it('handles back action with backBehavior: initialRoute', () => {
const router = TabRouter({ backBehavior: 'initialRoute' }); const router = TabRouter({
backBehavior: 'initialRoute',
initialRouteName: 'bar',
});
expect(
router.getStateForAction(
{
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar'],
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
},
CommonActions.goBack()
)
).toEqual({
stale: false,
key: 'root',
index: 1,
routeNames: ['baz', 'bar'],
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
});
expect( expect(
router.getStateForAction( router.getStateForAction(
@@ -119,19 +423,12 @@ it('handles initialRoute back action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'GO_BACK' } CommonActions.goBack()
) )
).toEqual({ ).toBe(null);
stale: false,
key: 'root',
index: 0,
routeNames: ['baz', 'bar'],
routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
});
}); });
it('handles none back action', () => { it('handles back action with backBehavior: none', () => {
const router = TabRouter({ backBehavior: 'none' }); const router = TabRouter({ backBehavior: 'none' });
expect( expect(
@@ -144,7 +441,86 @@ it('handles none back action', () => {
routeKeyHistory: [], routeKeyHistory: [],
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }], routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
}, },
{ type: 'GO_BACK' } CommonActions.goBack()
) )
).toEqual(null); ).toEqual(null);
}); });
it('updates route key history on navigate and jump to', () => {
const router = TabRouter({ backBehavior: 'history' });
let state: TabNavigationState = {
index: 1,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz', params: { answer: 42 } },
{ key: 'qux-0', name: 'qux', params: { name: 'Jane' } },
],
stale: false as const,
};
expect(state.routeKeyHistory).toEqual([]);
state = router.getStateForAction(
state,
TabActions.jumpTo('qux')
) as TabNavigationState;
expect(state.routeKeyHistory).toEqual(['baz-0']);
state = router.getStateForAction(
state,
CommonActions.navigate('bar')
) as TabNavigationState;
expect(state.routeKeyHistory).toEqual(['baz-0', 'qux-0']);
state = router.getStateForAction(
state,
TabActions.jumpTo('baz')
) as TabNavigationState;
expect(state.routeKeyHistory).toEqual(['qux-0', 'bar-0']);
state = router.getStateForAction(
state,
CommonActions.goBack()
) as TabNavigationState;
expect(state.routeKeyHistory).toEqual(['qux-0']);
state = router.getStateForAction(
state,
CommonActions.goBack()
) as TabNavigationState;
expect(state.routeKeyHistory).toEqual([]);
});
it('updates route key history on focus change', () => {
const router = TabRouter({ backBehavior: 'history' });
const state = {
index: 0,
key: 'tab-test',
routeKeyHistory: [],
routeNames: ['bar', 'baz', 'qux'],
routes: [
{ key: 'bar-0', name: 'bar' },
{ key: 'baz-0', name: 'baz', params: { answer: 42 } },
{ key: 'qux-0', name: 'qux', params: { name: 'Jane' } },
],
stale: false as const,
};
expect(router.getStateForRouteFocus(state, 'bar-0').routeKeyHistory).toEqual(
[]
);
expect(router.getStateForRouteFocus(state, 'baz-0').routeKeyHistory).toEqual([
'bar-0',
]);
});

View File

@@ -6,7 +6,7 @@
"react-native", "react-native",
"react-navigation" "react-navigation"
], ],
"version": "5.0.0-alpha.4", "version": "5.0.0-alpha.5",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.0.0-alpha.6](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.5...@react-navigation/stack@5.0.0-alpha.6) (2019-08-28)
### Features
* disable gesture logic when no gesture stack ([38336b0](https://github.com/react-navigation/navigation-ex/commit/38336b0))
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.4...@react-navigation/stack@5.0.0-alpha.5) (2019-08-27) # [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.4...@react-navigation/stack@5.0.0-alpha.5) (2019-08-27)

View File

@@ -10,7 +10,7 @@
"android", "android",
"stack" "stack"
], ],
"version": "5.0.0-alpha.5", "version": "5.0.0-alpha.6",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
@@ -33,7 +33,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/routers": "^5.0.0-alpha.4", "@react-navigation/routers": "^5.0.0-alpha.5",
"react-native-safe-area-view": "^0.14.6" "react-native-safe-area-view": "^0.14.6"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -366,6 +366,15 @@ export default class Card extends React.Component<Props> {
set(this.nextIsVisible, UNSET), set(this.nextIsVisible, UNSET),
]) ])
), ),
onChange(
this.isVisible,
call([this.isVisible], ([isVisible]) => (this.isVisibleValue = isVisible))
),
]);
private execNoGesture = this.runTransition(this.isVisible);
private execWithGesture = block([
onChange( onChange(
this.isSwiping, this.isSwiping,
call( call(
@@ -454,10 +463,6 @@ export default class Card extends React.Component<Props> {
), ),
] ]
), ),
onChange(
this.isVisible,
call([this.isVisible], ([isVisible]) => (this.isVisibleValue = isVisible))
),
]); ]);
private handleGestureEventHorizontal = Animated.event([ private handleGestureEventHorizontal = Animated.event([
@@ -576,15 +581,21 @@ export default class Card extends React.Component<Props> {
layout layout
); );
const handleGestureEvent = const handleGestureEvent = gestureEnabled
gestureDirection === 'vertical' ? gestureDirection === 'vertical'
? this.handleGestureEventVertical ? this.handleGestureEventVertical
: this.handleGestureEventHorizontal; : this.handleGestureEventHorizontal
: undefined;
return ( return (
<StackGestureContext.Provider value={this.gestureRef}> <StackGestureContext.Provider value={this.gestureRef}>
<View pointerEvents="box-none" {...rest}> <View pointerEvents="box-none" {...rest}>
<Animated.Code exec={this.exec} /> <Animated.Code exec={this.exec} />
{this.props.gestureEnabled ? (
<Animated.Code exec={this.execNoGesture} />
) : (
<Animated.Code exec={this.execWithGesture} />
)}
{overlayEnabled && overlayStyle ? ( {overlayEnabled && overlayStyle ? (
<Animated.View <Animated.View
pointerEvents="none" pointerEvents="none"