mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-19 18:38:16 +08:00
Compare commits
13 Commits
react-navi
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7e0c193cd | ||
|
|
ac98c0a668 | ||
|
|
14a6538cc8 | ||
|
|
c9313a1419 | ||
|
|
ec39721a74 | ||
|
|
a54d48b650 | ||
|
|
8a9a9cd7d1 | ||
|
|
cd08338186 | ||
|
|
d2433f0ab8 | ||
|
|
66374db859 | ||
|
|
8dbe0299a8 | ||
|
|
e4bc6dd506 | ||
|
|
4bac3bfc1a |
@@ -33,6 +33,7 @@
|
|||||||
"@babel/runtime": "^7.8.7",
|
"@babel/runtime": "^7.8.7",
|
||||||
"@commitlint/config-conventional": "^8.3.4",
|
"@commitlint/config-conventional": "^8.3.4",
|
||||||
"@types/jest": "^25.1.4",
|
"@types/jest": "^25.1.4",
|
||||||
|
"babel-jest": "^25.2.3",
|
||||||
"commitlint": "^8.3.5",
|
"commitlint": "^8.3.5",
|
||||||
"core-js": "^3.6.4",
|
"core-js": "^3.6.4",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
|
|||||||
@@ -3,6 +3,22 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [0.5.8](https://github.com/react-navigation/react-navigation/compare/react-navigation-animated-switch@0.5.6...react-navigation-animated-switch@0.5.8) (2020-03-28)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-animated-switch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [0.5.7](https://github.com/react-navigation/react-navigation/compare/react-navigation-animated-switch@0.5.6...react-navigation-animated-switch@0.5.7) (2020-03-27)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-animated-switch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [0.5.6](https://github.com/react-navigation/react-navigation/compare/react-navigation-animated-switch@0.5.5...react-navigation-animated-switch@0.5.6) (2020-03-22)
|
## [0.5.6](https://github.com/react-navigation/react-navigation/compare/react-navigation-animated-switch@0.5.5...react-navigation-animated-switch@0.5.6) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package react-navigation-animated-switch
|
**Note:** Version bump only for package react-navigation-animated-switch
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-navigation-animated-switch",
|
"name": "react-navigation-animated-switch",
|
||||||
"version": "0.5.6",
|
"version": "0.5.8",
|
||||||
"description": "Animated switch for React Navigation",
|
"description": "Animated switch for React Navigation",
|
||||||
"main": "lib/commonjs/index.js",
|
"main": "lib/commonjs/index.js",
|
||||||
"react-native": "lib/module/index.js",
|
"react-native": "lib/module/index.js",
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
"react-native": "~0.61.5",
|
"react-native": "~0.61.5",
|
||||||
"react-native-reanimated": "~1.7.0",
|
"react-native-reanimated": "~1.7.0",
|
||||||
"react-navigation": "^4.3.3",
|
"react-navigation": "^4.3.5",
|
||||||
"typescript": "~3.7.5"
|
"typescript": "~3.7.5"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -3,6 +3,32 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [3.7.3](https://github.com/react-navigation/react-navigation-core/compare/@react-navigation/core@3.7.1...@react-navigation/core@3.7.3) (2020-03-28)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* always emit didFocus/didBlur for root navigator ([ac98c0a](https://github.com/react-navigation/react-navigation-core/commit/ac98c0a668fe21200d0c6f62ae3043f92cc5aa7e))
|
||||||
|
* don't handle prune if there's only one route ([d2433f0](https://github.com/react-navigation/react-navigation-core/commit/d2433f0ab8f9791df8169de4ddfdeed9bc699e3e))
|
||||||
|
* emit didFocus and didBlur events based on parent's transition ([14a6538](https://github.com/react-navigation/react-navigation-core/commit/14a6538cc8e12c50d5d10722d75c9395a0a281ec))
|
||||||
|
* rework focus and blur events to make them more reliable ([cd08338](https://github.com/react-navigation/react-navigation-core/commit/cd083381866506a192f1ec842ac169f2b4277ca5)), closes [#4867](https://github.com/react-navigation/react-navigation-core/issues/4867) [#6187](https://github.com/react-navigation/react-navigation-core/issues/6187) [#6451](https://github.com/react-navigation/react-navigation-core/issues/6451) [#7628](https://github.com/react-navigation/react-navigation-core/issues/7628) [#7749](https://github.com/react-navigation/react-navigation-core/issues/7749)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [3.7.2](https://github.com/react-navigation/react-navigation-core/compare/@react-navigation/core@3.7.1...@react-navigation/core@3.7.2) (2020-03-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* don't handle prune if there's only one route ([d2433f0](https://github.com/react-navigation/react-navigation-core/commit/d2433f0ab8f9791df8169de4ddfdeed9bc699e3e))
|
||||||
|
* rework focus and blur events to make them more reliable ([cd08338](https://github.com/react-navigation/react-navigation-core/commit/cd083381866506a192f1ec842ac169f2b4277ca5)), closes [#4867](https://github.com/react-navigation/react-navigation-core/issues/4867) [#6187](https://github.com/react-navigation/react-navigation-core/issues/6187) [#6451](https://github.com/react-navigation/react-navigation-core/issues/6451) [#7628](https://github.com/react-navigation/react-navigation-core/issues/7628) [#7749](https://github.com/react-navigation/react-navigation-core/issues/7749)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [3.7.1](https://github.com/react-navigation/react-navigation-core/compare/@react-navigation/core@3.7.0...@react-navigation/core@3.7.1) (2020-03-22)
|
## [3.7.1](https://github.com/react-navigation/react-navigation-core/compare/@react-navigation/core@3.7.0...@react-navigation/core@3.7.1) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/core
|
**Note:** Version bump only for package @react-navigation/core
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@react-navigation/core",
|
"name": "@react-navigation/core",
|
||||||
"version": "3.7.1",
|
"version": "3.7.3",
|
||||||
"description": "Core utilities for the react-navigation framework",
|
"description": "Core utilities for the react-navigation framework",
|
||||||
"main": "lib/commonjs/index.js",
|
"main": "lib/commonjs/index.js",
|
||||||
"react-native": "lib/module/index.js",
|
"react-native": "lib/module/index.js",
|
||||||
|
|||||||
148
packages/core/src/__fixtures__/createNavigationContainer.js
Normal file
148
packages/core/src/__fixtures__/createNavigationContainer.js
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
/* eslint-disable react/sort-comp */
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import { NavigationActions, getNavigation, NavigationProvider } from '../index';
|
||||||
|
|
||||||
|
export default function createNavigationContainer(Component) {
|
||||||
|
class NavigationContainer extends React.Component {
|
||||||
|
static router = Component.router;
|
||||||
|
static navigationOptions = null;
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this._initialAction = NavigationActions.init();
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
nav: !props.loadNavigationState
|
||||||
|
? Component.router.getStateForAction(this._initialAction)
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
_actionEventSubscribers = new Set();
|
||||||
|
|
||||||
|
_onNavigationStateChange(prevNav, nav, action) {
|
||||||
|
if (typeof this.props.onNavigationStateChange === 'function') {
|
||||||
|
this.props.onNavigationStateChange(prevNav, nav, action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
// Clear cached _navState every tick
|
||||||
|
if (this._navState === this.state.nav) {
|
||||||
|
this._navState = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidMount() {
|
||||||
|
// Initialize state. This must be done *after* any async code
|
||||||
|
// so we don't end up with a different value for this.state.nav
|
||||||
|
// due to changes while async function was resolving
|
||||||
|
let action = this._initialAction;
|
||||||
|
// eslint-disable-next-line react/no-access-state-in-setstate
|
||||||
|
let startupState = this.state.nav;
|
||||||
|
if (!startupState) {
|
||||||
|
startupState = Component.router.getStateForAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dispatchActions = () =>
|
||||||
|
this._actionEventSubscribers.forEach((subscriber) =>
|
||||||
|
subscriber({
|
||||||
|
type: 'action',
|
||||||
|
action,
|
||||||
|
state: this.state.nav,
|
||||||
|
lastState: null,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (startupState === this.state.nav) {
|
||||||
|
dispatchActions();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line react/no-did-mount-set-state
|
||||||
|
this.setState({ nav: startupState }, () => {
|
||||||
|
dispatchActions();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch = (action) => {
|
||||||
|
if (this.props.navigation) {
|
||||||
|
return this.props.navigation.dispatch(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
// navState will have the most up-to-date value, because setState sometimes behaves asyncronously
|
||||||
|
this._navState = this._navState || this.state.nav;
|
||||||
|
const lastNavState = this._navState;
|
||||||
|
|
||||||
|
const reducedState = Component.router.getStateForAction(
|
||||||
|
action,
|
||||||
|
lastNavState
|
||||||
|
);
|
||||||
|
const navState = reducedState === null ? lastNavState : reducedState;
|
||||||
|
|
||||||
|
const dispatchActionEvents = () => {
|
||||||
|
this._actionEventSubscribers.forEach((subscriber) =>
|
||||||
|
subscriber({
|
||||||
|
type: 'action',
|
||||||
|
action,
|
||||||
|
state: navState,
|
||||||
|
lastState: lastNavState,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (reducedState === null) {
|
||||||
|
// The router will return null when action has been handled and the state hasn't changed.
|
||||||
|
// dispatch returns true when something has been handled.
|
||||||
|
dispatchActionEvents();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navState !== lastNavState) {
|
||||||
|
// Cache updates to state.nav during the tick to ensure that subsequent calls will not discard this change
|
||||||
|
this._navState = navState;
|
||||||
|
this.setState({ nav: navState }, () => {
|
||||||
|
this._onNavigationStateChange(lastNavState, navState, action);
|
||||||
|
dispatchActionEvents();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchActionEvents();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let navigation = this.props.navigation;
|
||||||
|
|
||||||
|
const navState = this.state.nav;
|
||||||
|
|
||||||
|
if (!navState) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._navigation || this._navigation.state !== navState) {
|
||||||
|
this._navigation = getNavigation(
|
||||||
|
Component.router,
|
||||||
|
navState,
|
||||||
|
this.dispatch,
|
||||||
|
this._actionEventSubscribers,
|
||||||
|
this._getScreenProps,
|
||||||
|
() => this._navigation
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
navigation = this._navigation;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NavigationProvider value={navigation}>
|
||||||
|
<Component {...this.props} navigation={navigation} />
|
||||||
|
</NavigationProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NavigationContainer;
|
||||||
|
}
|
||||||
241
packages/core/src/__tests__/NavigationFocusEvents.test.js
Normal file
241
packages/core/src/__tests__/NavigationFocusEvents.test.js
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { render, act } from 'react-native-testing-library';
|
||||||
|
import { navigate } from '../NavigationActions';
|
||||||
|
import TabRouter from '../routers/TabRouter';
|
||||||
|
import createNavigator from '../navigators/createNavigator';
|
||||||
|
import createNavigationContainer from '../__fixtures__/createNavigationContainer';
|
||||||
|
|
||||||
|
it('fires focus and blur events in root navigator', async () => {
|
||||||
|
function createTestNavigator(routeConfigMap, config = {}) {
|
||||||
|
const router = TabRouter(routeConfigMap, config);
|
||||||
|
|
||||||
|
return createNavigator(
|
||||||
|
({ descriptors, navigation }) =>
|
||||||
|
navigation.state.routes.map((route) => {
|
||||||
|
const Comp = descriptors[route.key].getComponent();
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
key={route.key}
|
||||||
|
navigation={descriptors[route.key].navigation}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
router,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstFocusCallback = jest.fn();
|
||||||
|
const firstBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const secondFocusCallback = jest.fn();
|
||||||
|
const secondBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const thirdFocusCallback = jest.fn();
|
||||||
|
const thirdBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const fourthFocusCallback = jest.fn();
|
||||||
|
const fourthBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const createComponent = (focusCallback, blurCallback) =>
|
||||||
|
class TestComponent extends React.Component {
|
||||||
|
componentDidMount() {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
this.focusSub = navigation.addListener('willFocus', focusCallback);
|
||||||
|
this.blurSub = navigation.addListener('willBlur', blurCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.focusSub?.remove();
|
||||||
|
this.blurSub?.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const navigation = React.createRef();
|
||||||
|
|
||||||
|
const Navigator = createNavigationContainer(
|
||||||
|
createTestNavigator({
|
||||||
|
first: createComponent(firstFocusCallback, firstBlurCallback),
|
||||||
|
second: createComponent(secondFocusCallback, secondBlurCallback),
|
||||||
|
third: createComponent(thirdFocusCallback, thirdBlurCallback),
|
||||||
|
fourth: createComponent(fourthFocusCallback, fourthBlurCallback),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const element = <Navigator ref={navigation} />;
|
||||||
|
|
||||||
|
render(element);
|
||||||
|
|
||||||
|
expect(firstFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(firstBlurCallback).toBeCalledTimes(0);
|
||||||
|
expect(secondFocusCallback).toBeCalledTimes(0);
|
||||||
|
expect(secondBlurCallback).toBeCalledTimes(0);
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(0);
|
||||||
|
expect(thirdBlurCallback).toBeCalledTimes(0);
|
||||||
|
expect(fourthFocusCallback).toBeCalledTimes(0);
|
||||||
|
expect(fourthBlurCallback).toBeCalledTimes(0);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'second' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(firstBlurCallback).toBeCalledTimes(1);
|
||||||
|
expect(secondFocusCallback).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'fourth' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(firstFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(firstBlurCallback).toBeCalledTimes(1);
|
||||||
|
expect(secondFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(secondBlurCallback).toBeCalledTimes(1);
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(0);
|
||||||
|
expect(thirdBlurCallback).toBeCalledTimes(0);
|
||||||
|
expect(fourthFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(fourthBlurCallback).toBeCalledTimes(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fires focus and blur events in nested navigator', () => {
|
||||||
|
function createTestNavigator(routeConfigMap, config = {}) {
|
||||||
|
const router = TabRouter(routeConfigMap, config);
|
||||||
|
|
||||||
|
return createNavigator(
|
||||||
|
({ descriptors, navigation }) =>
|
||||||
|
navigation.state.routes.map((route) => {
|
||||||
|
const Comp = descriptors[route.key].getComponent();
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
key={route.key}
|
||||||
|
navigation={descriptors[route.key].navigation}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
router,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstFocusCallback = jest.fn();
|
||||||
|
const firstBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const secondFocusCallback = jest.fn();
|
||||||
|
const secondBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const thirdFocusCallback = jest.fn();
|
||||||
|
const thirdBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const fourthFocusCallback = jest.fn();
|
||||||
|
const fourthBlurCallback = jest.fn();
|
||||||
|
|
||||||
|
const createComponent = (focusCallback, blurCallback) =>
|
||||||
|
class TestComponent extends React.Component {
|
||||||
|
componentDidMount() {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
this.focusSub = navigation.addListener('willFocus', focusCallback);
|
||||||
|
this.blurSub = navigation.addListener('willBlur', blurCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.focusSub?.remove();
|
||||||
|
this.blurSub?.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Navigator = createNavigationContainer(
|
||||||
|
createTestNavigator({
|
||||||
|
first: createComponent(firstFocusCallback, firstBlurCallback),
|
||||||
|
second: createComponent(secondFocusCallback, secondBlurCallback),
|
||||||
|
nested: createTestNavigator({
|
||||||
|
third: createComponent(thirdFocusCallback, thirdBlurCallback),
|
||||||
|
fourth: createComponent(fourthFocusCallback, fourthBlurCallback),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const navigation = React.createRef();
|
||||||
|
|
||||||
|
const element = <Navigator ref={navigation} />;
|
||||||
|
|
||||||
|
render(element);
|
||||||
|
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(0);
|
||||||
|
expect(firstFocusCallback).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'nested' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(firstFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(fourthFocusCallback).toBeCalledTimes(0);
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'second' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(secondFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(fourthBlurCallback).toBeCalledTimes(0);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'nested' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(firstBlurCallback).toBeCalledTimes(1);
|
||||||
|
expect(secondBlurCallback).toBeCalledTimes(1);
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(2);
|
||||||
|
expect(fourthFocusCallback).toBeCalledTimes(0);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'third' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fourthBlurCallback).toBeCalledTimes(0);
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(2);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'first' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(firstFocusCallback).toBeCalledTimes(2);
|
||||||
|
expect(thirdBlurCallback).toBeCalledTimes(2);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'fourth' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fourthFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(thirdBlurCallback).toBeCalledTimes(2);
|
||||||
|
expect(firstBlurCallback).toBeCalledTimes(2);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
navigation.current.dispatch(navigate({ routeName: 'third' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(3);
|
||||||
|
expect(fourthBlurCallback).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
// Make sure nothing else has changed
|
||||||
|
expect(firstFocusCallback).toBeCalledTimes(2);
|
||||||
|
expect(firstBlurCallback).toBeCalledTimes(2);
|
||||||
|
|
||||||
|
expect(secondFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(secondBlurCallback).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
expect(thirdFocusCallback).toBeCalledTimes(3);
|
||||||
|
expect(thirdBlurCallback).toBeCalledTimes(2);
|
||||||
|
|
||||||
|
expect(fourthFocusCallback).toBeCalledTimes(1);
|
||||||
|
expect(fourthBlurCallback).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
@@ -1,543 +0,0 @@
|
|||||||
import getChildEventSubscriber from '../getChildEventSubscriber';
|
|
||||||
|
|
||||||
it('child action events only flow when focused', () => {
|
|
||||||
const parentSubscriber = jest.fn();
|
|
||||||
const emitParentAction = (payload) => {
|
|
||||||
parentSubscriber.mock.calls.forEach((subs) => {
|
|
||||||
if (subs[0] === payload.type) {
|
|
||||||
subs[1](payload);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const subscriptionRemove = () => {};
|
|
||||||
parentSubscriber.mockReturnValueOnce({ remove: subscriptionRemove });
|
|
||||||
const childEventSubscriber = getChildEventSubscriber(parentSubscriber, 'key1')
|
|
||||||
.addListener;
|
|
||||||
const testState = {
|
|
||||||
key: 'foo',
|
|
||||||
routeName: 'FooRoute',
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }],
|
|
||||||
index: 0,
|
|
||||||
isTransitioning: false,
|
|
||||||
};
|
|
||||||
const focusedTestState = {
|
|
||||||
...testState,
|
|
||||||
index: 1,
|
|
||||||
};
|
|
||||||
const childActionHandler = jest.fn();
|
|
||||||
const childWillFocusHandler = jest.fn();
|
|
||||||
const childDidFocusHandler = jest.fn();
|
|
||||||
childEventSubscriber('action', childActionHandler);
|
|
||||||
childEventSubscriber('willFocus', childWillFocusHandler);
|
|
||||||
childEventSubscriber('didFocus', childDidFocusHandler);
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: focusedTestState,
|
|
||||||
lastState: testState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: focusedTestState,
|
|
||||||
lastState: focusedTestState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grandchildren subscription', () => {
|
|
||||||
const grandParentSubscriber = jest.fn();
|
|
||||||
const emitGrandParentAction = (payload) => {
|
|
||||||
grandParentSubscriber.mock.calls.forEach((subs) => {
|
|
||||||
if (subs[0] === payload.type) {
|
|
||||||
subs[1](payload);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const subscriptionRemove = () => {};
|
|
||||||
grandParentSubscriber.mockReturnValueOnce({ remove: subscriptionRemove });
|
|
||||||
const parentSubscriber = getChildEventSubscriber(
|
|
||||||
grandParentSubscriber,
|
|
||||||
'parent'
|
|
||||||
).addListener;
|
|
||||||
const childEventSubscriber = getChildEventSubscriber(parentSubscriber, 'key1')
|
|
||||||
.addListener;
|
|
||||||
const parentBlurState = {
|
|
||||||
key: 'foo',
|
|
||||||
routeName: 'FooRoute',
|
|
||||||
routes: [
|
|
||||||
{ key: 'aunt' },
|
|
||||||
{
|
|
||||||
key: 'parent',
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }],
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
index: 0,
|
|
||||||
isTransitioning: false,
|
|
||||||
};
|
|
||||||
const parentTransitionState = {
|
|
||||||
...parentBlurState,
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: true,
|
|
||||||
};
|
|
||||||
const parentFocusState = {
|
|
||||||
...parentTransitionState,
|
|
||||||
isTransitioning: false,
|
|
||||||
};
|
|
||||||
const childActionHandler = jest.fn();
|
|
||||||
const childWillFocusHandler = jest.fn();
|
|
||||||
const childDidFocusHandler = jest.fn();
|
|
||||||
childEventSubscriber('action', childActionHandler);
|
|
||||||
childEventSubscriber('willFocus', childWillFocusHandler);
|
|
||||||
childEventSubscriber('didFocus', childDidFocusHandler);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: parentTransitionState,
|
|
||||||
lastState: parentBlurState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(0);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: parentFocusState,
|
|
||||||
lastState: parentTransitionState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grandchildren transitions', () => {
|
|
||||||
const grandParentSubscriber = jest.fn();
|
|
||||||
const emitGrandParentAction = (payload) => {
|
|
||||||
grandParentSubscriber.mock.calls.forEach((subs) => {
|
|
||||||
if (subs[0] === payload.type) {
|
|
||||||
subs[1](payload);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const subscriptionRemove = () => {};
|
|
||||||
grandParentSubscriber.mockReturnValueOnce({ remove: subscriptionRemove });
|
|
||||||
const parentSubscriber = getChildEventSubscriber(
|
|
||||||
grandParentSubscriber,
|
|
||||||
'parent'
|
|
||||||
).addListener;
|
|
||||||
const childEventSubscriber = getChildEventSubscriber(parentSubscriber, 'key1')
|
|
||||||
.addListener;
|
|
||||||
const makeFakeState = (childIndex, childIsTransitioning) => ({
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: false,
|
|
||||||
routes: [
|
|
||||||
{ key: 'nothing' },
|
|
||||||
{
|
|
||||||
key: 'parent',
|
|
||||||
index: childIndex,
|
|
||||||
isTransitioning: childIsTransitioning,
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }, { key: 'key2' }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const blurredState = makeFakeState(0, false);
|
|
||||||
const transitionState = makeFakeState(1, true);
|
|
||||||
const focusState = makeFakeState(1, false);
|
|
||||||
const transition2State = makeFakeState(2, true);
|
|
||||||
const blurred2State = makeFakeState(2, false);
|
|
||||||
|
|
||||||
const childActionHandler = jest.fn();
|
|
||||||
const childWillFocusHandler = jest.fn();
|
|
||||||
const childDidFocusHandler = jest.fn();
|
|
||||||
const childWillBlurHandler = jest.fn();
|
|
||||||
const childDidBlurHandler = jest.fn();
|
|
||||||
childEventSubscriber('action', childActionHandler);
|
|
||||||
childEventSubscriber('willFocus', childWillFocusHandler);
|
|
||||||
childEventSubscriber('didFocus', childDidFocusHandler);
|
|
||||||
childEventSubscriber('willBlur', childWillBlurHandler);
|
|
||||||
childEventSubscriber('didBlur', childDidBlurHandler);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: transitionState,
|
|
||||||
lastState: blurredState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(0);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: focusState,
|
|
||||||
lastState: transitionState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: focusState,
|
|
||||||
lastState: focusState,
|
|
||||||
action: { type: 'TestAction' },
|
|
||||||
});
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(1);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: transition2State,
|
|
||||||
lastState: focusState,
|
|
||||||
action: { type: 'CauseWillBlurAction' },
|
|
||||||
});
|
|
||||||
expect(childWillBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidBlurHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(1);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: blurred2State,
|
|
||||||
lastState: transition2State,
|
|
||||||
action: { type: 'CauseDidBlurAction' },
|
|
||||||
});
|
|
||||||
expect(childWillBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grandchildren pass through transitions', () => {
|
|
||||||
const grandParentSubscriber = jest.fn();
|
|
||||||
const emitGrandParentAction = (payload) => {
|
|
||||||
grandParentSubscriber.mock.calls.forEach((subs) => {
|
|
||||||
if (subs[0] === payload.type) {
|
|
||||||
subs[1](payload);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const subscriptionRemove = () => {};
|
|
||||||
grandParentSubscriber.mockReturnValueOnce({ remove: subscriptionRemove });
|
|
||||||
const parentSubscriber = getChildEventSubscriber(
|
|
||||||
grandParentSubscriber,
|
|
||||||
'parent'
|
|
||||||
).addListener;
|
|
||||||
const childEventSubscriber = getChildEventSubscriber(parentSubscriber, 'key1')
|
|
||||||
.addListener;
|
|
||||||
const makeFakeState = (childIndex, childIsTransitioning) => ({
|
|
||||||
index: childIndex,
|
|
||||||
isTransitioning: childIsTransitioning,
|
|
||||||
routes: [
|
|
||||||
{ key: 'nothing' },
|
|
||||||
{
|
|
||||||
key: 'parent',
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: false,
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }, { key: 'key2' }],
|
|
||||||
},
|
|
||||||
].slice(0, childIndex + 1),
|
|
||||||
});
|
|
||||||
const blurredState = makeFakeState(0, false);
|
|
||||||
const transitionState = makeFakeState(1, true);
|
|
||||||
const focusState = makeFakeState(1, false);
|
|
||||||
const transition2State = makeFakeState(0, true);
|
|
||||||
const blurred2State = makeFakeState(0, false);
|
|
||||||
|
|
||||||
const childActionHandler = jest.fn();
|
|
||||||
const childWillFocusHandler = jest.fn();
|
|
||||||
const childDidFocusHandler = jest.fn();
|
|
||||||
const childWillBlurHandler = jest.fn();
|
|
||||||
const childDidBlurHandler = jest.fn();
|
|
||||||
childEventSubscriber('action', childActionHandler);
|
|
||||||
childEventSubscriber('willFocus', childWillFocusHandler);
|
|
||||||
childEventSubscriber('didFocus', childDidFocusHandler);
|
|
||||||
childEventSubscriber('willBlur', childWillBlurHandler);
|
|
||||||
childEventSubscriber('didBlur', childDidBlurHandler);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: transitionState,
|
|
||||||
lastState: blurredState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(0);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: focusState,
|
|
||||||
lastState: transitionState,
|
|
||||||
action: { type: 'FooAction' },
|
|
||||||
});
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: focusState,
|
|
||||||
lastState: focusState,
|
|
||||||
action: { type: 'TestAction' },
|
|
||||||
});
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(1);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: transition2State,
|
|
||||||
lastState: focusState,
|
|
||||||
action: { type: 'CauseWillBlurAction' },
|
|
||||||
});
|
|
||||||
expect(childWillBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidBlurHandler.mock.calls.length).toBe(0);
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(1);
|
|
||||||
emitGrandParentAction({
|
|
||||||
type: 'action',
|
|
||||||
state: blurred2State,
|
|
||||||
lastState: transition2State,
|
|
||||||
action: { type: 'CauseDidBlurAction' },
|
|
||||||
});
|
|
||||||
expect(childWillBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childActionHandler.mock.calls.length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('child focus with transition', () => {
|
|
||||||
const parentSubscriber = jest.fn();
|
|
||||||
const emitParentAction = (payload) => {
|
|
||||||
parentSubscriber.mock.calls.forEach((subs) => {
|
|
||||||
if (subs[0] === payload.type) {
|
|
||||||
subs[1](payload);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const subscriptionRemove = () => {};
|
|
||||||
parentSubscriber.mockReturnValueOnce({ remove: subscriptionRemove });
|
|
||||||
const childEventSubscriber = getChildEventSubscriber(parentSubscriber, 'key1')
|
|
||||||
.addListener;
|
|
||||||
const randomAction = { type: 'FooAction' };
|
|
||||||
const testState = {
|
|
||||||
key: 'foo',
|
|
||||||
routeName: 'FooRoute',
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }],
|
|
||||||
index: 0,
|
|
||||||
isTransitioning: false,
|
|
||||||
};
|
|
||||||
const childWillFocusHandler = jest.fn();
|
|
||||||
const childDidFocusHandler = jest.fn();
|
|
||||||
const childWillBlurHandler = jest.fn();
|
|
||||||
const childDidBlurHandler = jest.fn();
|
|
||||||
childEventSubscriber('willFocus', childWillFocusHandler);
|
|
||||||
childEventSubscriber('didFocus', childDidFocusHandler);
|
|
||||||
childEventSubscriber('willBlur', childWillBlurHandler);
|
|
||||||
childEventSubscriber('didBlur', childDidBlurHandler);
|
|
||||||
emitParentAction({
|
|
||||||
type: 'didFocus',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: testState,
|
|
||||||
state: testState,
|
|
||||||
});
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: testState,
|
|
||||||
state: {
|
|
||||||
...testState,
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: {
|
|
||||||
...testState,
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
state: {
|
|
||||||
...testState,
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: {
|
|
||||||
...testState,
|
|
||||||
index: 1,
|
|
||||||
isTransitioning: false,
|
|
||||||
},
|
|
||||||
state: {
|
|
||||||
...testState,
|
|
||||||
index: 0,
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(childWillBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: {
|
|
||||||
...testState,
|
|
||||||
index: 0,
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
state: {
|
|
||||||
...testState,
|
|
||||||
index: 0,
|
|
||||||
isTransitioning: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(childDidBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('child focus with immediate transition', () => {
|
|
||||||
const parentSubscriber = jest.fn();
|
|
||||||
const emitParentAction = (payload) => {
|
|
||||||
parentSubscriber.mock.calls.forEach((subs) => {
|
|
||||||
if (subs[0] === payload.type) {
|
|
||||||
subs[1](payload);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const subscriptionRemove = () => {};
|
|
||||||
parentSubscriber.mockReturnValueOnce({ remove: subscriptionRemove });
|
|
||||||
const childEventSubscriber = getChildEventSubscriber(parentSubscriber, 'key1')
|
|
||||||
.addListener;
|
|
||||||
const randomAction = { type: 'FooAction' };
|
|
||||||
const testState = {
|
|
||||||
key: 'foo',
|
|
||||||
routeName: 'FooRoute',
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }],
|
|
||||||
index: 0,
|
|
||||||
isTransitioning: false,
|
|
||||||
};
|
|
||||||
const childWillFocusHandler = jest.fn();
|
|
||||||
const childDidFocusHandler = jest.fn();
|
|
||||||
const childWillBlurHandler = jest.fn();
|
|
||||||
const childDidBlurHandler = jest.fn();
|
|
||||||
childEventSubscriber('willFocus', childWillFocusHandler);
|
|
||||||
childEventSubscriber('didFocus', childDidFocusHandler);
|
|
||||||
childEventSubscriber('willBlur', childWillBlurHandler);
|
|
||||||
childEventSubscriber('didBlur', childDidBlurHandler);
|
|
||||||
emitParentAction({
|
|
||||||
type: 'didFocus',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: testState,
|
|
||||||
state: testState,
|
|
||||||
});
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: testState,
|
|
||||||
state: {
|
|
||||||
...testState,
|
|
||||||
index: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(childWillFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidFocusHandler.mock.calls.length).toBe(1);
|
|
||||||
|
|
||||||
emitParentAction({
|
|
||||||
type: 'action',
|
|
||||||
action: randomAction,
|
|
||||||
lastState: {
|
|
||||||
...testState,
|
|
||||||
index: 1,
|
|
||||||
},
|
|
||||||
state: {
|
|
||||||
...testState,
|
|
||||||
index: 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(childWillBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
expect(childDidBlurHandler.mock.calls.length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
const setupEventTest = (subscriptionKey, initialLastFocusEvent) => {
|
|
||||||
const parentSubscriber = jest.fn();
|
|
||||||
const emitEvent = (payload) => {
|
|
||||||
parentSubscriber.mock.calls.forEach((subs) => {
|
|
||||||
if (subs[0] === payload.type) {
|
|
||||||
subs[1](payload);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const subscriptionRemove = () => {};
|
|
||||||
parentSubscriber.mockReturnValueOnce({ remove: subscriptionRemove });
|
|
||||||
const evtProvider = getChildEventSubscriber(
|
|
||||||
parentSubscriber,
|
|
||||||
subscriptionKey,
|
|
||||||
initialLastFocusEvent
|
|
||||||
);
|
|
||||||
const handlers = {};
|
|
||||||
evtProvider.addListener('action', (handlers.action = jest.fn()));
|
|
||||||
evtProvider.addListener('willFocus', (handlers.willFocus = jest.fn()));
|
|
||||||
evtProvider.addListener('didFocus', (handlers.didFocus = jest.fn()));
|
|
||||||
evtProvider.addListener('willBlur', (handlers.willBlur = jest.fn()));
|
|
||||||
evtProvider.addListener('didBlur', (handlers.didBlur = jest.fn()));
|
|
||||||
return { emitEvent, handlers, evtProvider };
|
|
||||||
};
|
|
||||||
|
|
||||||
it('immediate back with uncompleted transition will focus first screen again', () => {
|
|
||||||
const { handlers, emitEvent } = setupEventTest('key0', 'didFocus');
|
|
||||||
emitEvent({
|
|
||||||
type: 'action',
|
|
||||||
state: {
|
|
||||||
index: 1,
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }],
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
lastState: {
|
|
||||||
index: 0,
|
|
||||||
routes: [{ key: 'key0' }],
|
|
||||||
isTransitioning: false,
|
|
||||||
},
|
|
||||||
action: { type: 'Any action, does not matter here' },
|
|
||||||
});
|
|
||||||
expect(handlers.willFocus.mock.calls.length).toBe(0);
|
|
||||||
expect(handlers.didFocus.mock.calls.length).toBe(0);
|
|
||||||
expect(handlers.willBlur.mock.calls.length).toBe(1);
|
|
||||||
expect(handlers.didBlur.mock.calls.length).toBe(0);
|
|
||||||
emitEvent({
|
|
||||||
type: 'action',
|
|
||||||
state: {
|
|
||||||
index: 0,
|
|
||||||
routes: [{ key: 'key0' }],
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
lastState: {
|
|
||||||
index: 1,
|
|
||||||
routes: [{ key: 'key0' }, { key: 'key1' }],
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
action: { type: 'Any action, does not matter here' },
|
|
||||||
});
|
|
||||||
expect(handlers.willFocus.mock.calls.length).toBe(1);
|
|
||||||
expect(handlers.didFocus.mock.calls.length).toBe(0);
|
|
||||||
expect(handlers.willBlur.mock.calls.length).toBe(1);
|
|
||||||
expect(handlers.didBlur.mock.calls.length).toBe(0);
|
|
||||||
emitEvent({
|
|
||||||
type: 'action',
|
|
||||||
state: {
|
|
||||||
index: 0,
|
|
||||||
routes: [{ key: 'key0' }],
|
|
||||||
isTransitioning: false,
|
|
||||||
},
|
|
||||||
lastState: {
|
|
||||||
index: 0,
|
|
||||||
routes: [{ key: 'key0' }],
|
|
||||||
isTransitioning: true,
|
|
||||||
},
|
|
||||||
action: { type: 'Any action, does not matter here' },
|
|
||||||
});
|
|
||||||
expect(handlers.willFocus.mock.calls.length).toBe(1);
|
|
||||||
expect(handlers.didFocus.mock.calls.length).toBe(1);
|
|
||||||
expect(handlers.willBlur.mock.calls.length).toBe(1);
|
|
||||||
expect(handlers.didBlur.mock.calls.length).toBe(0);
|
|
||||||
});
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
/*
|
|
||||||
* This is used to extract one children's worth of events from a stream of navigation action events
|
|
||||||
*
|
|
||||||
* Based on the 'action' events that get fired for this navigation state, this utility will fire
|
|
||||||
* focus and blur events for this child
|
|
||||||
*/
|
|
||||||
export default function getChildEventSubscriber(
|
|
||||||
addListener,
|
|
||||||
key,
|
|
||||||
initialLastFocusEvent = 'didBlur'
|
|
||||||
) {
|
|
||||||
const actionSubscribers = new Set();
|
|
||||||
const willFocusSubscribers = new Set();
|
|
||||||
const didFocusSubscribers = new Set();
|
|
||||||
const willBlurSubscribers = new Set();
|
|
||||||
const didBlurSubscribers = new Set();
|
|
||||||
const refocusSubscribers = new Set();
|
|
||||||
|
|
||||||
const removeAll = () => {
|
|
||||||
[
|
|
||||||
actionSubscribers,
|
|
||||||
willFocusSubscribers,
|
|
||||||
didFocusSubscribers,
|
|
||||||
willBlurSubscribers,
|
|
||||||
didBlurSubscribers,
|
|
||||||
refocusSubscribers,
|
|
||||||
].forEach((set) => set.clear());
|
|
||||||
|
|
||||||
upstreamSubscribers.forEach((subs) => subs && subs.remove());
|
|
||||||
};
|
|
||||||
|
|
||||||
const getChildSubscribers = (evtName) => {
|
|
||||||
switch (evtName) {
|
|
||||||
case 'action':
|
|
||||||
return actionSubscribers;
|
|
||||||
case 'willFocus':
|
|
||||||
return willFocusSubscribers;
|
|
||||||
case 'didFocus':
|
|
||||||
return didFocusSubscribers;
|
|
||||||
case 'willBlur':
|
|
||||||
return willBlurSubscribers;
|
|
||||||
case 'didBlur':
|
|
||||||
return didBlurSubscribers;
|
|
||||||
case 'refocus':
|
|
||||||
return refocusSubscribers;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const emit = (type, payload) => {
|
|
||||||
const payloadWithType = { ...payload, type };
|
|
||||||
const subscribers = getChildSubscribers(type);
|
|
||||||
subscribers &&
|
|
||||||
subscribers.forEach((subs) => {
|
|
||||||
subs(payloadWithType);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// lastFocusEvent keeps track of focus state for one route. First we assume
|
|
||||||
// we are blurred. If we are focused on initialization, the first 'action'
|
|
||||||
// event will cause onFocus+willFocus events because we had previously been
|
|
||||||
// considered blurred
|
|
||||||
let lastFocusEvent = initialLastFocusEvent;
|
|
||||||
|
|
||||||
const upstreamEvents = [
|
|
||||||
'willFocus',
|
|
||||||
'didFocus',
|
|
||||||
'willBlur',
|
|
||||||
'didBlur',
|
|
||||||
'refocus',
|
|
||||||
'action',
|
|
||||||
];
|
|
||||||
|
|
||||||
const upstreamSubscribers = upstreamEvents.map((eventName) =>
|
|
||||||
addListener(eventName, (payload) => {
|
|
||||||
if (eventName === 'refocus') {
|
|
||||||
emit(eventName, payload);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { state, lastState, action } = payload;
|
|
||||||
const lastRoutes = lastState && lastState.routes;
|
|
||||||
const routes = state && state.routes;
|
|
||||||
|
|
||||||
// const lastFocusKey =
|
|
||||||
// lastState && lastState.routes && lastState.routes[lastState.index].key;
|
|
||||||
const focusKey = routes && routes[state.index].key;
|
|
||||||
|
|
||||||
const isChildFocused = focusKey === key;
|
|
||||||
const lastRoute =
|
|
||||||
lastRoutes && lastRoutes.find((route) => route.key === key);
|
|
||||||
const newRoute = routes && routes.find((route) => route.key === key);
|
|
||||||
const childPayload = {
|
|
||||||
context: `${key}:${action.type}_${payload.context || 'Root'}`,
|
|
||||||
state: newRoute,
|
|
||||||
lastState: lastRoute,
|
|
||||||
action,
|
|
||||||
type: eventName,
|
|
||||||
};
|
|
||||||
const isTransitioning = !!state && state.isTransitioning;
|
|
||||||
|
|
||||||
const previouslylastFocusEvent = lastFocusEvent;
|
|
||||||
|
|
||||||
if (lastFocusEvent === 'didBlur') {
|
|
||||||
// The child is currently blurred. Look for willFocus conditions
|
|
||||||
if (eventName === 'willFocus' && isChildFocused) {
|
|
||||||
emit((lastFocusEvent = 'willFocus'), childPayload);
|
|
||||||
} else if (eventName === 'action' && isChildFocused) {
|
|
||||||
emit((lastFocusEvent = 'willFocus'), childPayload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lastFocusEvent === 'willFocus') {
|
|
||||||
// We are currently mid-focus. Look for didFocus conditions.
|
|
||||||
// If state.isTransitioning is false, this child event happens immediately after willFocus
|
|
||||||
if (eventName === 'didFocus' && isChildFocused && !isTransitioning) {
|
|
||||||
emit((lastFocusEvent = 'didFocus'), childPayload);
|
|
||||||
} else if (
|
|
||||||
eventName === 'action' &&
|
|
||||||
isChildFocused &&
|
|
||||||
!isTransitioning
|
|
||||||
) {
|
|
||||||
emit((lastFocusEvent = 'didFocus'), childPayload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastFocusEvent === 'didFocus') {
|
|
||||||
// The child is currently focused. Look for blurring events
|
|
||||||
if (!isChildFocused) {
|
|
||||||
// The child is no longer focused within this navigation state
|
|
||||||
emit((lastFocusEvent = 'willBlur'), childPayload);
|
|
||||||
} else if (eventName === 'willBlur') {
|
|
||||||
// The parent is getting a willBlur event
|
|
||||||
emit((lastFocusEvent = 'willBlur'), childPayload);
|
|
||||||
} else if (
|
|
||||||
eventName === 'action' &&
|
|
||||||
previouslylastFocusEvent === 'didFocus'
|
|
||||||
) {
|
|
||||||
// While focused, pass action events to children for grandchildren focus
|
|
||||||
emit('action', childPayload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastFocusEvent === 'willBlur') {
|
|
||||||
// The child is mid-blur. Wait for transition to end
|
|
||||||
if (eventName === 'action' && !isChildFocused && !isTransitioning) {
|
|
||||||
// The child is done blurring because transitioning is over, or isTransitioning
|
|
||||||
// never began and didBlur fires immediately after willBlur
|
|
||||||
emit((lastFocusEvent = 'didBlur'), childPayload);
|
|
||||||
} else if (eventName === 'didBlur') {
|
|
||||||
// Pass through the parent didBlur event if it happens
|
|
||||||
emit((lastFocusEvent = 'didBlur'), childPayload);
|
|
||||||
} else if (
|
|
||||||
eventName === 'action' &&
|
|
||||||
isChildFocused &&
|
|
||||||
!isTransitioning
|
|
||||||
) {
|
|
||||||
emit((lastFocusEvent = 'didFocus'), childPayload);
|
|
||||||
} else if (
|
|
||||||
eventName === 'action' &&
|
|
||||||
isChildFocused &&
|
|
||||||
isTransitioning
|
|
||||||
) {
|
|
||||||
emit((lastFocusEvent = 'willFocus'), childPayload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastFocusEvent === 'didBlur' && !newRoute) {
|
|
||||||
removeAll();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
addListener(eventName, eventHandler) {
|
|
||||||
const subscribers = getChildSubscribers(eventName);
|
|
||||||
if (!subscribers) {
|
|
||||||
throw new Error(`Invalid event name "${eventName}"`);
|
|
||||||
}
|
|
||||||
subscribers.add(eventHandler);
|
|
||||||
const remove = () => {
|
|
||||||
subscribers.delete(eventHandler);
|
|
||||||
};
|
|
||||||
return { remove };
|
|
||||||
},
|
|
||||||
emit(eventName, payload) {
|
|
||||||
if (eventName !== 'refocus') {
|
|
||||||
console.error(
|
|
||||||
`navigation.emit only supports the 'refocus' event currently.`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emit(eventName, payload);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import getChildEventSubscriber from './getChildEventSubscriber';
|
|
||||||
import getChildRouter from './getChildRouter';
|
import getChildRouter from './getChildRouter';
|
||||||
import getNavigationActionCreators from './routers/getNavigationActionCreators';
|
import getNavigationActionCreators from './routers/getNavigationActionCreators';
|
||||||
import getChildrenNavigationCache from './getChildrenNavigationCache';
|
import getChildrenNavigationCache from './getChildrenNavigationCache';
|
||||||
|
import getEventManager from './getEventManager';
|
||||||
|
|
||||||
const createParamGetter = (route) => (paramName, defaultValue) => {
|
const createParamGetter = (route) => (paramName, defaultValue) => {
|
||||||
const params = route.params;
|
const params = route.params;
|
||||||
@@ -78,10 +78,7 @@ function getChildNavigation(navigation, childKey, getCurrentParentNavigation) {
|
|||||||
};
|
};
|
||||||
return children[childKey];
|
return children[childKey];
|
||||||
} else {
|
} else {
|
||||||
const childSubscriber = getChildEventSubscriber(
|
const { addListener, emit } = getEventManager(childKey);
|
||||||
navigation.addListener,
|
|
||||||
childKey
|
|
||||||
);
|
|
||||||
|
|
||||||
children[childKey] = {
|
children[childKey] = {
|
||||||
...actionHelpers,
|
...actionHelpers,
|
||||||
@@ -115,9 +112,10 @@ function getChildNavigation(navigation, childKey, getCurrentParentNavigation) {
|
|||||||
dispatch: navigation.dispatch,
|
dispatch: navigation.dispatch,
|
||||||
getScreenProps: navigation.getScreenProps,
|
getScreenProps: navigation.getScreenProps,
|
||||||
dangerouslyGetParent: getCurrentParentNavigation,
|
dangerouslyGetParent: getCurrentParentNavigation,
|
||||||
addListener: childSubscriber.addListener,
|
addListener,
|
||||||
emit: childSubscriber.emit,
|
emit,
|
||||||
};
|
};
|
||||||
|
|
||||||
return children[childKey];
|
return children[childKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
61
packages/core/src/getEventManager.js
Normal file
61
packages/core/src/getEventManager.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} target
|
||||||
|
*/
|
||||||
|
export default function getEventManager(target) {
|
||||||
|
/**
|
||||||
|
* @type {Record<string, Record<string, ((e: any) => void)[]>>}
|
||||||
|
*/
|
||||||
|
const listeners = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} type
|
||||||
|
* @param {() => void} callback
|
||||||
|
*/
|
||||||
|
const removeListener = (type, callback) => {
|
||||||
|
const callbacks = listeners[type] ? listeners[type][target] : undefined;
|
||||||
|
|
||||||
|
if (!callbacks) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = callbacks.indexOf(callback);
|
||||||
|
|
||||||
|
callbacks.splice(index, 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} type
|
||||||
|
* @param {() => void} callback
|
||||||
|
*/
|
||||||
|
const addListener = (type, callback) => {
|
||||||
|
listeners[type] = listeners[type] || {};
|
||||||
|
listeners[type][target] = listeners[type][target] || [];
|
||||||
|
listeners[type][target].push(callback);
|
||||||
|
|
||||||
|
return {
|
||||||
|
remove: () => removeListener(type, callback),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
addListener,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} type
|
||||||
|
* @param {any} [data]
|
||||||
|
*/
|
||||||
|
emit: (type, data) => {
|
||||||
|
const items = listeners[type] || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the current list of callbacks in case they are mutated during execution
|
||||||
|
* @type {((data: any) => void)[] | undefined}
|
||||||
|
*/
|
||||||
|
const callbacks = items[target] && items[target].slice();
|
||||||
|
|
||||||
|
callbacks?.forEach((cb) => cb(data));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import * as React from 'react';
|
||||||
import invariant from '../utils/invariant';
|
import invariant from '../utils/invariant';
|
||||||
import ThemeContext from '../views/ThemeContext';
|
import ThemeContext from '../views/ThemeContext';
|
||||||
|
import NavigationFocusEvents from '../views/NavigationFocusEvents';
|
||||||
|
|
||||||
function createNavigator(NavigatorView, router, navigationConfig) {
|
function createNavigator(NavigatorView, router, navigationConfig) {
|
||||||
class Navigator extends React.Component {
|
class Navigator extends React.Component {
|
||||||
@@ -78,13 +79,21 @@ function createNavigator(NavigatorView, router, navigationConfig) {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<NavigatorView
|
<React.Fragment>
|
||||||
{...this.props}
|
<NavigationFocusEvents
|
||||||
screenProps={this.state.screenProps}
|
navigation={this.props.navigation}
|
||||||
navigation={this.props.navigation}
|
onEvent={(target, type, data) => {
|
||||||
navigationConfig={navigationConfig}
|
this.state.descriptors[target]?.navigation.emit(type, data);
|
||||||
descriptors={this.state.descriptors}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<NavigatorView
|
||||||
|
{...this.props}
|
||||||
|
screenProps={this.state.screenProps}
|
||||||
|
navigation={this.props.navigation}
|
||||||
|
navigationConfig={navigationConfig}
|
||||||
|
descriptors={this.state.descriptors}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -536,18 +536,21 @@ export default (routeConfigs, stackConfig = {}) => {
|
|||||||
|
|
||||||
if (action.type === StackActions.POP && prune === false && key) {
|
if (action.type === StackActions.POP && prune === false && key) {
|
||||||
const index = state.routes.findIndex((r) => r.key === key);
|
const index = state.routes.findIndex((r) => r.key === key);
|
||||||
const count = Math.max(index - (n == null ? 1 : n) + 1, 1);
|
|
||||||
const routes = state.routes
|
|
||||||
.slice(0, count)
|
|
||||||
.concat(state.routes.slice(index + 1));
|
|
||||||
|
|
||||||
if (routes.length) {
|
if (index > 0) {
|
||||||
return {
|
const count = Math.max(index - (n ?? 1) + 1, 1);
|
||||||
...state,
|
const routes = state.routes
|
||||||
routes,
|
.slice(0, count)
|
||||||
index: routes.length - 1,
|
.concat(state.routes.slice(index + 1));
|
||||||
isTransitioning: immediate !== true,
|
|
||||||
};
|
if (routes.length) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
routes,
|
||||||
|
index: routes.length - 1,
|
||||||
|
isTransitioning: immediate !== true,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let backRouteIndex = state.index;
|
let backRouteIndex = state.index;
|
||||||
|
|||||||
342
packages/core/src/views/NavigationFocusEvents.js
Normal file
342
packages/core/src/views/NavigationFocusEvents.js
Normal file
@@ -0,0 +1,342 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} State
|
||||||
|
* @prop {number} index
|
||||||
|
* @prop {({ key: string } & (State | {}))[]} routes
|
||||||
|
* @prop {boolean} [isTransitioning]
|
||||||
|
*
|
||||||
|
* @typedef {object} ParentPayload
|
||||||
|
* @prop {string} type
|
||||||
|
* @prop {object} action
|
||||||
|
* @prop {State} state
|
||||||
|
* @prop {State | {key: string, routes?: undefined, index?: undefined, isTransitioning?: undefined} | undefined | null} lastState
|
||||||
|
* @prop {string} [context]
|
||||||
|
*
|
||||||
|
* @typedef {object} Payload
|
||||||
|
* @prop {string} type
|
||||||
|
* @prop {object} action
|
||||||
|
* @prop {State | {key: string}} state
|
||||||
|
* @prop {State | {key: string} | undefined | null} lastState
|
||||||
|
* @prop {string} [context]
|
||||||
|
*
|
||||||
|
* @typedef {object} Props
|
||||||
|
* @prop {object} navigation
|
||||||
|
* @prop {Function} navigation.addListener
|
||||||
|
* @prop {Function} navigation.removeListener
|
||||||
|
* @prop {() => boolean} navigation.isFocused
|
||||||
|
* @prop {() => object | undefined} navigation.dangerouslyGetParent
|
||||||
|
* @prop {State} navigation.state
|
||||||
|
* @prop {(target: string, type: string, data: any) => void} onEvent
|
||||||
|
*
|
||||||
|
* @extends {React.Component<Props>}
|
||||||
|
*/
|
||||||
|
export default class NavigationEventManager extends React.Component {
|
||||||
|
componentDidMount() {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
this._actionSubscription = navigation.addListener(
|
||||||
|
'action',
|
||||||
|
this._handleAction
|
||||||
|
);
|
||||||
|
|
||||||
|
this._willFocusSubscription = navigation.addListener(
|
||||||
|
'willFocus',
|
||||||
|
this._handleWillFocus
|
||||||
|
);
|
||||||
|
|
||||||
|
this._willBlurSubscription = navigation.addListener(
|
||||||
|
'willBlur',
|
||||||
|
this._handleWillBlur
|
||||||
|
);
|
||||||
|
|
||||||
|
this._didFocusSubscription = navigation.addListener(
|
||||||
|
'didFocus',
|
||||||
|
this._handleDidFocus
|
||||||
|
);
|
||||||
|
|
||||||
|
this._didBlurSubscription = navigation.addListener(
|
||||||
|
'didBlur',
|
||||||
|
this._handleDidBlur
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this._actionSubscription?.remove();
|
||||||
|
this._willFocusSubscription?.remove();
|
||||||
|
this._willBlurSubscription?.remove();
|
||||||
|
this._didFocusSubscription?.remove();
|
||||||
|
this._didBlurSubscription?.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {{ remove(): void } | undefined}
|
||||||
|
*/
|
||||||
|
_actionSubscription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {{ remove(): void } | undefined}
|
||||||
|
*/
|
||||||
|
_willFocusSubscription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {{ remove(): void } | undefined}
|
||||||
|
*/
|
||||||
|
_willBlurSubscription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {{ remove(): void } | undefined}
|
||||||
|
*/
|
||||||
|
_didFocusSubscription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {{ remove(): void } | undefined}
|
||||||
|
*/
|
||||||
|
_didBlurSubscription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string | undefined}
|
||||||
|
*/
|
||||||
|
_lastWillBlurKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string | undefined}
|
||||||
|
*/
|
||||||
|
_lastWillFocusKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string | undefined}
|
||||||
|
*/
|
||||||
|
_lastDidBlurKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string | undefined}
|
||||||
|
*/
|
||||||
|
_lastDidFocusKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The 'action' event will fire when navigation state changes.
|
||||||
|
* Detect if the focused route changed here and emit appropriate events.
|
||||||
|
*
|
||||||
|
* @param {ParentPayload} payload
|
||||||
|
*/
|
||||||
|
_handleAction = ({ state, lastState, action, type, context }) => {
|
||||||
|
const { navigation, onEvent } = this.props;
|
||||||
|
|
||||||
|
// We should only emit events when the navigator is focused
|
||||||
|
// When navigator is not focused, screens inside shouldn't receive focused status either
|
||||||
|
if (!navigation.isFocused()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const previous = lastState
|
||||||
|
? lastState.routes?.[lastState.index]
|
||||||
|
: undefined;
|
||||||
|
const current = state.routes[state.index];
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
context: `${current.key}:${action.type}_${context || 'Root'}`,
|
||||||
|
state: current,
|
||||||
|
lastState: previous,
|
||||||
|
action,
|
||||||
|
type,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (previous?.key !== current.key) {
|
||||||
|
this._emitWillFocus(current.key, payload);
|
||||||
|
|
||||||
|
if (previous?.key) {
|
||||||
|
this._emitWillBlur(previous.key, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
lastState?.isTransitioning !== state.isTransitioning &&
|
||||||
|
state.isTransitioning === false
|
||||||
|
) {
|
||||||
|
if (this._lastWillBlurKey) {
|
||||||
|
this._emitDidBlur(this._lastWillBlurKey, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._lastWillFocusKey) {
|
||||||
|
this._emitDidFocus(this._lastWillFocusKey, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onEvent(current.key, 'action', payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ParentPayload} payload
|
||||||
|
*/
|
||||||
|
_handleWillFocus = ({ lastState, action, context, type }) => {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
const route = navigation.state.routes[navigation.state.index];
|
||||||
|
|
||||||
|
this._emitWillFocus(route.key, {
|
||||||
|
context: `${route.key}:${action.type}_${context || 'Root'}`,
|
||||||
|
state: route,
|
||||||
|
lastState: lastState?.routes?.find((r) => r.key === route.key),
|
||||||
|
action,
|
||||||
|
type,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ParentPayload} payload
|
||||||
|
*/
|
||||||
|
_handleWillBlur = ({ lastState, action, context, type }) => {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
const route = navigation.state.routes[navigation.state.index];
|
||||||
|
|
||||||
|
this._emitWillBlur(route.key, {
|
||||||
|
context: `${route.key}:${action.type}_${context || 'Root'}`,
|
||||||
|
state: route,
|
||||||
|
lastState: lastState?.routes?.find((r) => r.key === route.key),
|
||||||
|
action,
|
||||||
|
type,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ParentPayload} payload
|
||||||
|
*/
|
||||||
|
_handleDidFocus = ({ lastState, action, context, type }) => {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
if (this._lastWillFocusKey) {
|
||||||
|
const route = navigation.state.routes.find(
|
||||||
|
(r) => r.key === this._lastWillFocusKey
|
||||||
|
);
|
||||||
|
|
||||||
|
if (route) {
|
||||||
|
this._emitDidFocus(route.key, {
|
||||||
|
context: `${route.key}:${action.type}_${context || 'Root'}`,
|
||||||
|
state: route,
|
||||||
|
lastState: lastState?.routes?.find((r) => r.key === route.key),
|
||||||
|
action,
|
||||||
|
type,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ParentPayload} payload
|
||||||
|
*/
|
||||||
|
_handleDidBlur = ({ lastState, action, context, type }) => {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
if (this._lastWillBlurKey) {
|
||||||
|
const route = navigation.state.routes.find(
|
||||||
|
(r) => r.key === this._lastWillBlurKey
|
||||||
|
);
|
||||||
|
|
||||||
|
if (route) {
|
||||||
|
this._emitDidBlur(route.key, {
|
||||||
|
context: `${route.key}:${action.type}_${context || 'Root'}`,
|
||||||
|
state: route,
|
||||||
|
lastState: lastState?.routes?.find((r) => r.key === route.key),
|
||||||
|
action,
|
||||||
|
type,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} target
|
||||||
|
* @param {Payload} payload
|
||||||
|
*/
|
||||||
|
_emitWillFocus = (target, payload) => {
|
||||||
|
if (this._lastWillBlurKey === target) {
|
||||||
|
this._lastWillBlurKey = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._lastWillFocusKey === target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._lastDidFocusKey = undefined;
|
||||||
|
this._lastWillFocusKey = target;
|
||||||
|
|
||||||
|
const { navigation, onEvent } = this.props;
|
||||||
|
|
||||||
|
onEvent(target, 'willFocus', payload);
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof navigation.state.isTransitioning !== 'boolean' ||
|
||||||
|
(navigation.state.isTransitioning !== true &&
|
||||||
|
!navigation.dangerouslyGetParent())
|
||||||
|
) {
|
||||||
|
this._emitDidFocus(target, payload);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} target
|
||||||
|
* @param {Payload} payload
|
||||||
|
*/
|
||||||
|
_emitWillBlur = (target, payload) => {
|
||||||
|
if (this._lastWillFocusKey === target) {
|
||||||
|
this._lastWillFocusKey = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._lastWillBlurKey === target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._lastDidBlurKey = undefined;
|
||||||
|
this._lastWillBlurKey = target;
|
||||||
|
|
||||||
|
const { navigation, onEvent } = this.props;
|
||||||
|
|
||||||
|
onEvent(target, 'willBlur', payload);
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof navigation.state.isTransitioning !== 'boolean' ||
|
||||||
|
(navigation.state.isTransitioning !== true &&
|
||||||
|
!navigation.dangerouslyGetParent())
|
||||||
|
) {
|
||||||
|
this._emitDidBlur(target, payload);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} target
|
||||||
|
* @param {Payload} payload
|
||||||
|
*/
|
||||||
|
_emitDidFocus = (target, payload) => {
|
||||||
|
if (this._lastWillFocusKey !== target || this._lastDidFocusKey === target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._lastDidFocusKey = target;
|
||||||
|
|
||||||
|
const { onEvent } = this.props;
|
||||||
|
|
||||||
|
onEvent(target, 'didFocus', payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} target
|
||||||
|
* @param {Payload} payload
|
||||||
|
*/
|
||||||
|
_emitDidBlur = (target, payload) => {
|
||||||
|
if (this._lastWillBlurKey !== target || this._lastDidBlurKey === target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._lastDidBlurKey = target;
|
||||||
|
|
||||||
|
const { onEvent } = this.props;
|
||||||
|
|
||||||
|
onEvent(target, 'didBlur', payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,25 +8,25 @@ export default function withNavigationFocus(Component) {
|
|||||||
Component.displayName || Component.name
|
Component.displayName || Component.name
|
||||||
})`;
|
})`;
|
||||||
|
|
||||||
constructor(props) {
|
state = {
|
||||||
super(props);
|
isFocused: this.props.navigation.isFocused(),
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
|
||||||
this.subscriptions = [
|
this.subscriptions = [
|
||||||
props.navigation.addListener('didFocus', () =>
|
navigation.addListener('willFocus', () =>
|
||||||
this.setState({ isFocused: true })
|
this.setState({ isFocused: true })
|
||||||
),
|
),
|
||||||
props.navigation.addListener('willBlur', () =>
|
navigation.addListener('willBlur', () =>
|
||||||
this.setState({ isFocused: false })
|
this.setState({ isFocused: false })
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
this.state = {
|
|
||||||
isFocused: props.navigation ? props.navigation.isFocused() : false,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.subscriptions.forEach((sub) => sub.remove());
|
this.subscriptions?.forEach((sub) => sub.remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
6
packages/core/tsconfig.json
Normal file
6
packages/core/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"allowJs": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,22 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [2.4.9](https://github.com/react-navigation/drawer/compare/react-navigation-drawer@2.4.7...react-navigation-drawer@2.4.9) (2020-03-28)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.4.8](https://github.com/react-navigation/drawer/compare/react-navigation-drawer@2.4.7...react-navigation-drawer@2.4.8) (2020-03-27)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [2.4.7](https://github.com/react-navigation/drawer/compare/react-navigation-drawer@2.4.6...react-navigation-drawer@2.4.7) (2020-03-22)
|
## [2.4.7](https://github.com/react-navigation/drawer/compare/react-navigation-drawer@2.4.6...react-navigation-drawer@2.4.7) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package react-navigation-drawer
|
**Note:** Version bump only for package react-navigation-drawer
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-navigation-drawer",
|
"name": "react-navigation-drawer",
|
||||||
"version": "2.4.7",
|
"version": "2.4.9",
|
||||||
"description": "Drawer navigator component for React Navigation",
|
"description": "Drawer navigator component for React Navigation",
|
||||||
"main": "lib/commonjs/index.js",
|
"main": "lib/commonjs/index.js",
|
||||||
"react-native": "lib/module/index.js",
|
"react-native": "lib/module/index.js",
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
"react-native-reanimated": "^1.2.0",
|
"react-native-reanimated": "^1.2.0",
|
||||||
"react-native-screens": "^2.3.0",
|
"react-native-screens": "^2.3.0",
|
||||||
"react-native-testing-library": "^1.12.0",
|
"react-native-testing-library": "^1.12.0",
|
||||||
"react-navigation": "^4.3.3",
|
"react-navigation": "^4.3.5",
|
||||||
"typescript": "~3.7.5"
|
"typescript": "~3.7.5"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -3,6 +3,22 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [2.2.8](https://github.com/react-navigation/react-navigation-material-bottom-tabs/compare/react-navigation-material-bottom-tabs@2.2.6...react-navigation-material-bottom-tabs@2.2.8) (2020-03-28)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.2.7](https://github.com/react-navigation/react-navigation-material-bottom-tabs/compare/react-navigation-material-bottom-tabs@2.2.6...react-navigation-material-bottom-tabs@2.2.7) (2020-03-27)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [2.2.6](https://github.com/react-navigation/react-navigation-material-bottom-tabs/compare/react-navigation-material-bottom-tabs@2.2.5...react-navigation-material-bottom-tabs@2.2.6) (2020-03-22)
|
## [2.2.6](https://github.com/react-navigation/react-navigation-material-bottom-tabs/compare/react-navigation-material-bottom-tabs@2.2.5...react-navigation-material-bottom-tabs@2.2.6) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package react-navigation-material-bottom-tabs
|
**Note:** Version bump only for package react-navigation-material-bottom-tabs
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-navigation-material-bottom-tabs",
|
"name": "react-navigation-material-bottom-tabs",
|
||||||
"version": "2.2.6",
|
"version": "2.2.8",
|
||||||
"description": "Material Bottom Tab Navigation component for React Navigation",
|
"description": "Material Bottom Tab Navigation component for React Navigation",
|
||||||
"main": "lib/commonjs/index.js",
|
"main": "lib/commonjs/index.js",
|
||||||
"module": "lib/module/index.js",
|
"module": "lib/module/index.js",
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
"react-native-gesture-handler": "^1.6.0",
|
"react-native-gesture-handler": "^1.6.0",
|
||||||
"react-native-paper": "^3.1.1",
|
"react-native-paper": "^3.1.1",
|
||||||
"react-native-reanimated": "^1.2.0",
|
"react-native-reanimated": "^1.2.0",
|
||||||
"react-navigation": "^4.3.3",
|
"react-navigation": "^4.3.5",
|
||||||
"typescript": "~3.7.5"
|
"typescript": "~3.7.5"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -3,6 +3,28 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [3.7.9](https://github.com/react-navigation/react-navigation-native/compare/@react-navigation/native@3.7.7...@react-navigation/native@3.7.9) (2020-03-28)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* rework focus and blur events to make them more reliable ([cd08338](https://github.com/react-navigation/react-navigation-native/commit/cd083381866506a192f1ec842ac169f2b4277ca5)), closes [#4867](https://github.com/react-navigation/react-navigation-native/issues/4867) [#6187](https://github.com/react-navigation/react-navigation-native/issues/6187) [#6451](https://github.com/react-navigation/react-navigation-native/issues/6451) [#7628](https://github.com/react-navigation/react-navigation-native/issues/7628) [#7749](https://github.com/react-navigation/react-navigation-native/issues/7749)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [3.7.8](https://github.com/react-navigation/react-navigation-native/compare/@react-navigation/native@3.7.7...@react-navigation/native@3.7.8) (2020-03-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* rework focus and blur events to make them more reliable ([cd08338](https://github.com/react-navigation/react-navigation-native/commit/cd083381866506a192f1ec842ac169f2b4277ca5)), closes [#4867](https://github.com/react-navigation/react-navigation-native/issues/4867) [#6187](https://github.com/react-navigation/react-navigation-native/issues/6187) [#6451](https://github.com/react-navigation/react-navigation-native/issues/6451) [#7628](https://github.com/react-navigation/react-navigation-native/issues/7628) [#7749](https://github.com/react-navigation/react-navigation-native/issues/7749)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [3.7.7](https://github.com/react-navigation/react-navigation-native/compare/@react-navigation/native@3.7.6...@react-navigation/native@3.7.7) (2020-03-22)
|
## [3.7.7](https://github.com/react-navigation/react-navigation-native/compare/@react-navigation/native@3.7.6...@react-navigation/native@3.7.7) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/native
|
**Note:** Version bump only for package @react-navigation/native
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@react-navigation/native",
|
"name": "@react-navigation/native",
|
||||||
"version": "3.7.7",
|
"version": "3.7.9",
|
||||||
"description": "React Native support for React Navigation",
|
"description": "React Native support for React Navigation",
|
||||||
"main": "lib/commonjs/index.js",
|
"main": "lib/commonjs/index.js",
|
||||||
"react-native": "lib/module/index.js",
|
"react-native": "lib/module/index.js",
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.10.0",
|
"@react-native-community/bob": "^0.10.0",
|
||||||
"@react-navigation/core": "^3.7.1",
|
"@react-navigation/core": "^3.7.3",
|
||||||
"@types/react-test-renderer": "^16.9.2",
|
"@types/react-test-renderer": "^16.9.2",
|
||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { withNavigation } from '@react-navigation/core';
|
|||||||
|
|
||||||
export default function createNavigationAwareScrollable(Component) {
|
export default function createNavigationAwareScrollable(Component) {
|
||||||
const ComponentWithNavigationScrolling = withNavigation(
|
const ComponentWithNavigationScrolling = withNavigation(
|
||||||
class extends React.PureComponent<any> {
|
class extends React.PureComponent {
|
||||||
static displayName = `withNavigationScrolling(${
|
static displayName = `withNavigationScrolling(${
|
||||||
Component.displayName || Component.name
|
Component.displayName || Component.name
|
||||||
})`;
|
})`;
|
||||||
@@ -60,7 +60,7 @@ export default function createNavigationAwareScrollable(Component) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
class NavigationAwareScrollable extends React.PureComponent<any> {
|
class NavigationAwareScrollable extends React.PureComponent {
|
||||||
static displayName = `NavigationAwareScrollable(${
|
static displayName = `NavigationAwareScrollable(${
|
||||||
Component.displayName || Component.name
|
Component.displayName || Component.name
|
||||||
})`;
|
})`;
|
||||||
|
|||||||
@@ -3,6 +3,22 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [4.3.5](https://github.com/react-navigation/react-navigation/compare/react-navigation@4.3.3...react-navigation@4.3.5) (2020-03-28)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [4.3.4](https://github.com/react-navigation/react-navigation/compare/react-navigation@4.3.3...react-navigation@4.3.4) (2020-03-27)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [4.3.3](https://github.com/react-navigation/react-navigation/compare/react-navigation@4.3.2...react-navigation@4.3.3) (2020-03-22)
|
## [4.3.3](https://github.com/react-navigation/react-navigation/compare/react-navigation@4.3.2...react-navigation@4.3.3) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package react-navigation
|
**Note:** Version bump only for package react-navigation
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-navigation",
|
"name": "react-navigation",
|
||||||
"version": "4.3.3",
|
"version": "4.3.5",
|
||||||
"description": "Routing and navigation for your React Native apps",
|
"description": "Routing and navigation for your React Native apps",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"types": "typescript/react-navigation.d.ts",
|
"types": "typescript/react-navigation.d.ts",
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
"react-native": "*"
|
"react-native": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/core": "^3.7.1",
|
"@react-navigation/core": "^3.7.3",
|
||||||
"@react-navigation/native": "^3.7.7"
|
"@react-navigation/native": "^3.7.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^16.9.23",
|
"@types/react": "^16.9.23",
|
||||||
|
|||||||
@@ -3,6 +3,45 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [2.3.9](https://github.com/react-navigation/react-navigation-stack/compare/react-navigation-stack@2.3.7...react-navigation-stack@2.3.9) (2020-03-28)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* emit didFocus and didBlur events based on parent's transition ([14a6538](https://github.com/react-navigation/react-navigation-stack/commit/14a6538cc8e12c50d5d10722d75c9395a0a281ec))
|
||||||
|
* rework focus and blur events to make them more reliable ([cd08338](https://github.com/react-navigation/react-navigation-stack/commit/cd083381866506a192f1ec842ac169f2b4277ca5)), closes [#4867](https://github.com/react-navigation/react-navigation-stack/issues/4867) [#6187](https://github.com/react-navigation/react-navigation-stack/issues/6187) [#6451](https://github.com/react-navigation/react-navigation-stack/issues/6451) [#7628](https://github.com/react-navigation/react-navigation-stack/issues/7628) [#7749](https://github.com/react-navigation/react-navigation-stack/issues/7749)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.3.8](https://github.com/react-navigation/react-navigation-stack/compare/react-navigation-stack@2.3.7...react-navigation-stack@2.3.8) (2020-03-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* rework focus and blur events to make them more reliable ([cd08338](https://github.com/react-navigation/react-navigation-stack/commit/cd083381866506a192f1ec842ac169f2b4277ca5)), closes [#4867](https://github.com/react-navigation/react-navigation-stack/issues/4867) [#6187](https://github.com/react-navigation/react-navigation-stack/issues/6187) [#6451](https://github.com/react-navigation/react-navigation-stack/issues/6451) [#7628](https://github.com/react-navigation/react-navigation-stack/issues/7628) [#7749](https://github.com/react-navigation/react-navigation-stack/issues/7749)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.3.7](https://github.com/react-navigation/react-navigation-stack/compare/react-navigation-stack@2.3.6...react-navigation-stack@2.3.7) (2020-03-27)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.3.6](https://github.com/react-navigation/react-navigation-stack/compare/react-navigation-stack@2.3.5...react-navigation-stack@2.3.6) (2020-03-23)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [2.3.5](https://github.com/react-navigation/react-navigation-stack/compare/react-navigation-stack@2.3.4...react-navigation-stack@2.3.5) (2020-03-22)
|
## [2.3.5](https://github.com/react-navigation/react-navigation-stack/compare/react-navigation-stack@2.3.4...react-navigation-stack@2.3.5) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package react-navigation-stack
|
**Note:** Version bump only for package react-navigation-stack
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-navigation-stack",
|
"name": "react-navigation-stack",
|
||||||
"version": "2.3.5",
|
"version": "2.3.9",
|
||||||
"description": "Stack navigator component for React Navigation",
|
"description": "Stack navigator component for React Navigation",
|
||||||
"main": "lib/commonjs/index.js",
|
"main": "lib/commonjs/index.js",
|
||||||
"module": "lib/module/index.js",
|
"module": "lib/module/index.js",
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.10.0",
|
"@react-native-community/bob": "^0.10.0",
|
||||||
"@react-native-community/masked-view": "^0.1.7",
|
"@react-native-community/masked-view": "^0.1.7",
|
||||||
"@react-navigation/stack": "^5.2.4",
|
"@react-navigation/stack": "^5.2.8",
|
||||||
"@types/color": "^3.0.1",
|
"@types/color": "^3.0.1",
|
||||||
"@types/react": "^16.9.23",
|
"@types/react": "^16.9.23",
|
||||||
"@types/react-native": "^0.61.22",
|
"@types/react-native": "^0.61.22",
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"react-native-gesture-handler": "^1.6.0",
|
"react-native-gesture-handler": "^1.6.0",
|
||||||
"react-native-safe-area-context": "^0.7.3",
|
"react-native-safe-area-context": "^0.7.3",
|
||||||
"react-native-screens": "^2.3.0",
|
"react-native-screens": "^2.3.0",
|
||||||
"react-navigation": "^4.3.3",
|
"react-navigation": "^4.3.5",
|
||||||
"react-test-renderer": "~16.9.0",
|
"react-test-renderer": "~16.9.0",
|
||||||
"typescript": "~3.7.5"
|
"typescript": "~3.7.5"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/index.tsx src/vendor/index.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/index.tsx src/vendor/index.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/index.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/index.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/index.tsx 2020-03-23 00:04:37.000000000 +0100
|
+++ src/vendor/index.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -3,11 +3,6 @@
|
@@ -3,11 +3,6 @@
|
||||||
import * as TransitionSpecs from './TransitionConfigs/TransitionSpecs';
|
import * as TransitionSpecs from './TransitionConfigs/TransitionSpecs';
|
||||||
import * as TransitionPresets from './TransitionConfigs/TransitionPresets';
|
import * as TransitionPresets from './TransitionConfigs/TransitionPresets';
|
||||||
@@ -28,7 +28,7 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/index.tsx src/vendor/i
|
|||||||
StackHeaderTitleProps,
|
StackHeaderTitleProps,
|
||||||
StackCardInterpolatedStyle,
|
StackCardInterpolatedStyle,
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/navigators/createStackNavigator.tsx src/vendor/navigators/createStackNavigator.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/navigators/createStackNavigator.tsx src/vendor/navigators/createStackNavigator.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/navigators/createStackNavigator.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/navigators/createStackNavigator.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/navigators/createStackNavigator.tsx 1970-01-01 01:00:00.000000000 +0100
|
+++ src/vendor/navigators/createStackNavigator.tsx 1970-01-01 01:00:00.000000000 +0100
|
||||||
@@ -1,81 +0,0 @@
|
@@ -1,81 +0,0 @@
|
||||||
-import * as React from 'react';
|
-import * as React from 'react';
|
||||||
@@ -113,8 +113,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/navigators/createStack
|
|||||||
- typeof StackNavigator
|
- typeof StackNavigator
|
||||||
->(StackNavigator);
|
->(StackNavigator);
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/types.tsx src/vendor/types.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/types.tsx src/vendor/types.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/types.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/types.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/types.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/types.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -8,14 +8,28 @@
|
@@ -8,14 +8,28 @@
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||||
@@ -240,8 +240,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/types.tsx src/vendor/t
|
|||||||
|
|
||||||
export type StackNavigationConfig = {
|
export type StackNavigationConfig = {
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/Header.tsx src/vendor/views/Header/Header.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/Header.tsx src/vendor/views/Header/Header.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Header/Header.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Header/Header.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Header/Header.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Header/Header.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -1,12 +1,14 @@
|
@@ -1,12 +1,14 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
-import { StackActions } from '@react-navigation/native';
|
-import { StackActions } from '@react-navigation/native';
|
||||||
@@ -321,8 +321,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/Header.ts
|
|||||||
+
|
+
|
||||||
+export default Header;
|
+export default Header;
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackButton.tsx src/vendor/views/Header/HeaderBackButton.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackButton.tsx src/vendor/views/Header/HeaderBackButton.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackButton.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackButton.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Header/HeaderBackButton.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Header/HeaderBackButton.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -8,9 +8,9 @@
|
@@ -8,9 +8,9 @@
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
LayoutChangeEvent,
|
LayoutChangeEvent,
|
||||||
@@ -335,8 +335,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBac
|
|||||||
|
|
||||||
type Props = StackHeaderLeftButtonProps;
|
type Props = StackHeaderLeftButtonProps;
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackground.tsx src/vendor/views/Header/HeaderBackground.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackground.tsx src/vendor/views/Header/HeaderBackground.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackground.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBackground.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Header/HeaderBackground.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Header/HeaderBackground.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -1,6 +1,6 @@
|
@@ -1,6 +1,6 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Animated, StyleSheet, Platform, ViewProps } from 'react-native';
|
import { Animated, StyleSheet, Platform, ViewProps } from 'react-native';
|
||||||
@@ -346,8 +346,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderBac
|
|||||||
type Props = ViewProps & {
|
type Props = ViewProps & {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderContainer.tsx src/vendor/views/Header/HeaderContainer.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderContainer.tsx src/vendor/views/Header/HeaderContainer.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderContainer.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderContainer.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Header/HeaderContainer.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Header/HeaderContainer.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -1,11 +1,6 @@
|
@@ -1,11 +1,6 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
||||||
@@ -399,8 +399,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderCon
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderSegment.tsx src/vendor/views/Header/HeaderSegment.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderSegment.tsx src/vendor/views/Header/HeaderSegment.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderSegment.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderSegment.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Header/HeaderSegment.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Header/HeaderSegment.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -8,7 +8,7 @@
|
@@ -8,7 +8,7 @@
|
||||||
ViewStyle,
|
ViewStyle,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
@@ -420,8 +420,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderSeg
|
|||||||
};
|
};
|
||||||
|
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderTitle.tsx src/vendor/views/Header/HeaderTitle.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderTitle.tsx src/vendor/views/Header/HeaderTitle.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderTitle.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Header/HeaderTitle.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Header/HeaderTitle.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Header/HeaderTitle.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -1,6 +1,6 @@
|
@@ -1,6 +1,6 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Animated, StyleSheet, Platform } from 'react-native';
|
import { Animated, StyleSheet, Platform } from 'react-native';
|
||||||
@@ -431,8 +431,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Header/HeaderTit
|
|||||||
type Props = React.ComponentProps<typeof Animated.Text> & {
|
type Props = React.ComponentProps<typeof Animated.Text> & {
|
||||||
tintColor?: string;
|
tintColor?: string;
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/Card.tsx src/vendor/views/Stack/Card.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/Card.tsx src/vendor/views/Stack/Card.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Stack/Card.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Stack/Card.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Stack/Card.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Stack/Card.tsx 2020-03-23 11:43:59.000000000 +0100
|
||||||
@@ -138,7 +138,7 @@
|
@@ -138,7 +138,7 @@
|
||||||
|
|
||||||
private interactionHandle: number | undefined;
|
private interactionHandle: number | undefined;
|
||||||
@@ -443,8 +443,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/Card.tsx s
|
|||||||
private animate = ({
|
private animate = ({
|
||||||
closing,
|
closing,
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/CardContainer.tsx src/vendor/views/Stack/CardContainer.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/CardContainer.tsx src/vendor/views/Stack/CardContainer.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Stack/CardContainer.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Stack/CardContainer.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Stack/CardContainer.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Stack/CardContainer.tsx 2020-03-27 14:41:20.000000000 +0100
|
||||||
@@ -1,10 +1,16 @@
|
@@ -1,10 +1,16 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Animated, View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
import { Animated, View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
||||||
@@ -464,33 +464,7 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/CardContai
|
|||||||
|
|
||||||
type Props = TransitionPreset & {
|
type Props = TransitionPreset & {
|
||||||
index: number;
|
index: number;
|
||||||
@@ -36,6 +42,7 @@
|
@@ -183,7 +189,7 @@
|
||||||
closing: boolean
|
|
||||||
) => void;
|
|
||||||
onTransitionEnd?: (props: { route: Route<string> }, closing: boolean) => void;
|
|
||||||
+ onTransitionComplete: (props: { route: Route<string> }) => void;
|
|
||||||
onPageChangeStart?: () => void;
|
|
||||||
onPageChangeConfirm?: () => void;
|
|
||||||
onPageChangeCancel?: () => void;
|
|
||||||
@@ -83,6 +90,7 @@
|
|
||||||
layout,
|
|
||||||
onCloseRoute,
|
|
||||||
onOpenRoute,
|
|
||||||
+ onTransitionComplete,
|
|
||||||
onPageChangeCancel,
|
|
||||||
onPageChangeConfirm,
|
|
||||||
onPageChangeStart,
|
|
||||||
@@ -152,6 +160,9 @@
|
|
||||||
};
|
|
||||||
}, [pointerEvents, scene.progress.next]);
|
|
||||||
|
|
||||||
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
+ React.useEffect(() => onTransitionComplete({ route: scene.route }), []);
|
|
||||||
+
|
|
||||||
return (
|
|
||||||
<Card
|
|
||||||
index={index}
|
|
||||||
@@ -183,7 +194,7 @@
|
|
||||||
? { marginTop: headerHeight }
|
? { marginTop: headerHeight }
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
@@ -500,8 +474,8 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/CardContai
|
|||||||
>
|
>
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/CardStack.tsx src/vendor/views/Stack/CardStack.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/CardStack.tsx src/vendor/views/Stack/CardStack.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Stack/CardStack.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Stack/CardStack.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Stack/CardStack.tsx 2020-03-23 00:04:40.000000000 +0100
|
+++ src/vendor/views/Stack/CardStack.tsx 2020-03-27 14:41:20.000000000 +0100
|
||||||
@@ -9,9 +9,8 @@
|
@@ -9,9 +9,8 @@
|
||||||
ViewProps,
|
ViewProps,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
@@ -521,33 +495,9 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/CardStack.
|
|||||||
Layout,
|
Layout,
|
||||||
StackHeaderMode,
|
StackHeaderMode,
|
||||||
StackCardMode,
|
StackCardMode,
|
||||||
@@ -54,6 +54,7 @@
|
|
||||||
renderHeader: (props: HeaderContainerProps) => React.ReactNode;
|
|
||||||
renderScene: (props: { route: Route<string> }) => React.ReactNode;
|
|
||||||
headerMode: StackHeaderMode;
|
|
||||||
+ onTransitionComplete: (props: { route: Route<string> }) => void;
|
|
||||||
onTransitionStart: (
|
|
||||||
props: { route: Route<string> },
|
|
||||||
closing: boolean
|
|
||||||
@@ -383,6 +384,7 @@
|
|
||||||
renderHeader,
|
|
||||||
renderScene,
|
|
||||||
headerMode,
|
|
||||||
+ onTransitionComplete,
|
|
||||||
onTransitionStart,
|
|
||||||
onTransitionEnd,
|
|
||||||
onPageChangeStart,
|
|
||||||
@@ -560,6 +562,7 @@
|
|
||||||
renderScene={renderScene}
|
|
||||||
onOpenRoute={onOpenRoute}
|
|
||||||
onCloseRoute={onCloseRoute}
|
|
||||||
+ onTransitionComplete={onTransitionComplete}
|
|
||||||
onTransitionStart={onTransitionStart}
|
|
||||||
onTransitionEnd={onTransitionEnd}
|
|
||||||
gestureEnabled={index !== 0 && getGesturesEnabled({ route })}
|
|
||||||
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/StackView.tsx src/vendor/views/Stack/StackView.tsx
|
diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/StackView.tsx src/vendor/views/Stack/StackView.tsx
|
||||||
--- ../../node_modules/@react-navigation/stack/src/views/Stack/StackView.tsx 2020-03-23 00:04:17.000000000 +0100
|
--- ../../node_modules/@react-navigation/stack/src/views/Stack/StackView.tsx 2020-03-23 11:43:17.000000000 +0100
|
||||||
+++ src/vendor/views/Stack/StackView.tsx 2020-03-23 00:07:11.000000000 +0100
|
+++ src/vendor/views/Stack/StackView.tsx 2020-03-27 14:41:20.000000000 +0100
|
||||||
@@ -4,9 +4,9 @@
|
@@ -4,9 +4,9 @@
|
||||||
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
||||||
import {
|
import {
|
||||||
@@ -676,11 +626,3 @@ diff -Naur ../../node_modules/@react-navigation/stack/src/views/Stack/StackView.
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
@@ -395,6 +427,7 @@
|
|
||||||
closingRouteKeys={closingRouteKeys}
|
|
||||||
onOpenRoute={this.handleOpenRoute}
|
|
||||||
onCloseRoute={this.handleCloseRoute}
|
|
||||||
+ onTransitionComplete={this.handleTransitionComplete}
|
|
||||||
onTransitionStart={this.handleTransitionStart}
|
|
||||||
onTransitionEnd={this.handleTransitionEnd}
|
|
||||||
renderHeader={this.renderHeader}
|
|
||||||
|
|||||||
@@ -272,8 +272,7 @@ export default class Card extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const closing =
|
const closing =
|
||||||
(translation + velocity) *
|
(translation + velocity * gestureVelocityImpact) *
|
||||||
gestureVelocityImpact *
|
|
||||||
getInvertedMultiplier(gestureDirection) >
|
getInvertedMultiplier(gestureDirection) >
|
||||||
distance / 2
|
distance / 2
|
||||||
? velocity !== 0 || translation !== 0
|
? velocity !== 0 || translation !== 0
|
||||||
@@ -481,7 +480,7 @@ export default class Card extends React.Component<Props> {
|
|||||||
<CardAnimationContext.Provider value={animationContext}>
|
<CardAnimationContext.Provider value={animationContext}>
|
||||||
<View pointerEvents="box-none" {...rest}>
|
<View pointerEvents="box-none" {...rest}>
|
||||||
{overlayEnabled ? (
|
{overlayEnabled ? (
|
||||||
<View style={StyleSheet.absoluteFill}>
|
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
|
||||||
{overlay({ style: overlayStyle })}
|
{overlay({ style: overlayStyle })}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ type Props = TransitionPreset & {
|
|||||||
closing: boolean
|
closing: boolean
|
||||||
) => void;
|
) => void;
|
||||||
onTransitionEnd?: (props: { route: Route<string> }, closing: boolean) => void;
|
onTransitionEnd?: (props: { route: Route<string> }, closing: boolean) => void;
|
||||||
onTransitionComplete: (props: { route: Route<string> }) => void;
|
|
||||||
onPageChangeStart?: () => void;
|
onPageChangeStart?: () => void;
|
||||||
onPageChangeConfirm?: () => void;
|
onPageChangeConfirm?: () => void;
|
||||||
onPageChangeCancel?: () => void;
|
onPageChangeCancel?: () => void;
|
||||||
@@ -90,7 +89,6 @@ function CardContainer({
|
|||||||
layout,
|
layout,
|
||||||
onCloseRoute,
|
onCloseRoute,
|
||||||
onOpenRoute,
|
onOpenRoute,
|
||||||
onTransitionComplete,
|
|
||||||
onPageChangeCancel,
|
onPageChangeCancel,
|
||||||
onPageChangeConfirm,
|
onPageChangeConfirm,
|
||||||
onPageChangeStart,
|
onPageChangeStart,
|
||||||
@@ -160,9 +158,6 @@ function CardContainer({
|
|||||||
};
|
};
|
||||||
}, [pointerEvents, scene.progress.next]);
|
}, [pointerEvents, scene.progress.next]);
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
React.useEffect(() => onTransitionComplete({ route: scene.route }), []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
index={index}
|
index={index}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ type Props = {
|
|||||||
renderHeader: (props: HeaderContainerProps) => React.ReactNode;
|
renderHeader: (props: HeaderContainerProps) => React.ReactNode;
|
||||||
renderScene: (props: { route: Route<string> }) => React.ReactNode;
|
renderScene: (props: { route: Route<string> }) => React.ReactNode;
|
||||||
headerMode: StackHeaderMode;
|
headerMode: StackHeaderMode;
|
||||||
onTransitionComplete: (props: { route: Route<string> }) => void;
|
|
||||||
onTransitionStart: (
|
onTransitionStart: (
|
||||||
props: { route: Route<string> },
|
props: { route: Route<string> },
|
||||||
closing: boolean
|
closing: boolean
|
||||||
@@ -384,7 +383,6 @@ export default class CardStack extends React.Component<Props, State> {
|
|||||||
renderHeader,
|
renderHeader,
|
||||||
renderScene,
|
renderScene,
|
||||||
headerMode,
|
headerMode,
|
||||||
onTransitionComplete,
|
|
||||||
onTransitionStart,
|
onTransitionStart,
|
||||||
onTransitionEnd,
|
onTransitionEnd,
|
||||||
onPageChangeStart,
|
onPageChangeStart,
|
||||||
@@ -562,7 +560,6 @@ export default class CardStack extends React.Component<Props, State> {
|
|||||||
renderScene={renderScene}
|
renderScene={renderScene}
|
||||||
onOpenRoute={onOpenRoute}
|
onOpenRoute={onOpenRoute}
|
||||||
onCloseRoute={onCloseRoute}
|
onCloseRoute={onCloseRoute}
|
||||||
onTransitionComplete={onTransitionComplete}
|
|
||||||
onTransitionStart={onTransitionStart}
|
onTransitionStart={onTransitionStart}
|
||||||
onTransitionEnd={onTransitionEnd}
|
onTransitionEnd={onTransitionEnd}
|
||||||
gestureEnabled={index !== 0 && getGesturesEnabled({ route })}
|
gestureEnabled={index !== 0 && getGesturesEnabled({ route })}
|
||||||
|
|||||||
@@ -308,21 +308,21 @@ export default class StackView extends React.Component<Props, State> {
|
|||||||
return <HeaderContainer {...props} />;
|
return <HeaderContainer {...props} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleTransitionComplete = ({ route }: { route: Route<string> }) => {
|
private handleTransitionComplete = () => {
|
||||||
const { state, navigation } = this.props;
|
const { state, navigation } = this.props;
|
||||||
|
|
||||||
if (state.isTransitioning) {
|
if (state.isTransitioning) {
|
||||||
navigation.dispatch(
|
navigation.dispatch(
|
||||||
StackActions.completeTransition({
|
StackActions.completeTransition({
|
||||||
key: navigation.state.key,
|
key: navigation.state.key,
|
||||||
toChildKey: route.key,
|
toChildKey: state.routes[state.index].key,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleOpenRoute = ({ route }: { route: Route<string> }) => {
|
private handleOpenRoute = ({ route }: { route: Route<string> }) => {
|
||||||
this.handleTransitionComplete({ route });
|
this.handleTransitionComplete();
|
||||||
this.setState((state) => ({
|
this.setState((state) => ({
|
||||||
routes: state.replacingRouteKeys.length
|
routes: state.replacingRouteKeys.length
|
||||||
? state.routes.filter((r) => !state.replacingRouteKeys.includes(r.key))
|
? state.routes.filter((r) => !state.replacingRouteKeys.includes(r.key))
|
||||||
@@ -347,13 +347,7 @@ export default class StackView extends React.Component<Props, State> {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
navigation.dispatch(StackActions.pop({ key: route.key, prune: false }));
|
navigation.dispatch(StackActions.pop({ key: route.key, prune: false }));
|
||||||
} else {
|
} else {
|
||||||
// While closing route we need to point to the previous one assuming that
|
this.handleTransitionComplete();
|
||||||
// this previous one in routes array
|
|
||||||
const index = this.state.routes.findIndex((r) => r.key === route.key);
|
|
||||||
|
|
||||||
this.handleTransitionComplete({
|
|
||||||
route: this.state.routes[Math.max(index - 1, 0)],
|
|
||||||
});
|
|
||||||
|
|
||||||
// We need to clean up any state tracking the route and pop it immediately
|
// We need to clean up any state tracking the route and pop it immediately
|
||||||
this.setState((state) => ({
|
this.setState((state) => ({
|
||||||
@@ -427,7 +421,6 @@ export default class StackView extends React.Component<Props, State> {
|
|||||||
closingRouteKeys={closingRouteKeys}
|
closingRouteKeys={closingRouteKeys}
|
||||||
onOpenRoute={this.handleOpenRoute}
|
onOpenRoute={this.handleOpenRoute}
|
||||||
onCloseRoute={this.handleCloseRoute}
|
onCloseRoute={this.handleCloseRoute}
|
||||||
onTransitionComplete={this.handleTransitionComplete}
|
|
||||||
onTransitionStart={this.handleTransitionStart}
|
onTransitionStart={this.handleTransitionStart}
|
||||||
onTransitionEnd={this.handleTransitionEnd}
|
onTransitionEnd={this.handleTransitionEnd}
|
||||||
renderHeader={this.renderHeader}
|
renderHeader={this.renderHeader}
|
||||||
|
|||||||
@@ -3,6 +3,22 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
## [2.8.9](https://github.com/react-navigation/tabs/compare/react-navigation-tabs@2.8.7...react-navigation-tabs@2.8.9) (2020-03-28)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.8.8](https://github.com/react-navigation/tabs/compare/react-navigation-tabs@2.8.7...react-navigation-tabs@2.8.8) (2020-03-27)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package react-navigation-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [2.8.7](https://github.com/react-navigation/tabs/compare/react-navigation-tabs@2.8.6...react-navigation-tabs@2.8.7) (2020-03-22)
|
## [2.8.7](https://github.com/react-navigation/tabs/compare/react-navigation-tabs@2.8.6...react-navigation-tabs@2.8.7) (2020-03-22)
|
||||||
|
|
||||||
**Note:** Version bump only for package react-navigation-tabs
|
**Note:** Version bump only for package react-navigation-tabs
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-navigation-tabs",
|
"name": "react-navigation-tabs",
|
||||||
"version": "2.8.7",
|
"version": "2.8.9",
|
||||||
"description": "Tab Navigation components for React Navigation",
|
"description": "Tab Navigation components for React Navigation",
|
||||||
"main": "lib/commonjs/index.js",
|
"main": "lib/commonjs/index.js",
|
||||||
"module": "lib/module/index.js",
|
"module": "lib/module/index.js",
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"react-native-gesture-handler": "^1.6.0",
|
"react-native-gesture-handler": "^1.6.0",
|
||||||
"react-native-reanimated": "^1.2.0",
|
"react-native-reanimated": "^1.2.0",
|
||||||
"react-native-tab-view": "^2.13.0",
|
"react-native-tab-view": "^2.13.0",
|
||||||
"react-navigation": "^4.3.3",
|
"react-navigation": "^4.3.5",
|
||||||
"typescript": "~3.7.5"
|
"typescript": "~3.7.5"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user