fix: always emit didFocus/didBlur for root navigator

This commit is contained in:
Satyajit Sahoo
2020-03-28 17:20:33 +01:00
parent 14a6538cc8
commit ac98c0a668

View File

@@ -203,9 +203,13 @@ export default class NavigationEventManager extends React.Component {
/**
* @param {ParentPayload} payload
*/
_handleDidFocus = ({ lastState, state, action, context, type }) => {
_handleDidFocus = ({ lastState, action, context, type }) => {
const { navigation } = this.props;
if (this._lastWillFocusKey) {
const route = state.routes.find((r) => r.key === this._lastWillFocusKey);
const route = navigation.state.routes.find(
(r) => r.key === this._lastWillFocusKey
);
if (route) {
this._emitDidFocus(route.key, {
@@ -222,9 +226,13 @@ export default class NavigationEventManager extends React.Component {
/**
* @param {ParentPayload} payload
*/
_handleDidBlur = ({ lastState, state, action, context, type }) => {
_handleDidBlur = ({ lastState, action, context, type }) => {
const { navigation } = this.props;
if (this._lastWillBlurKey) {
const route = state.routes.find((r) => r.key === this._lastWillBlurKey);
const route = navigation.state.routes.find(
(r) => r.key === this._lastWillBlurKey
);
if (route) {
this._emitDidBlur(route.key, {
@@ -258,7 +266,11 @@ export default class NavigationEventManager extends React.Component {
onEvent(target, 'willFocus', payload);
if (typeof navigation.state.isTransitioning !== 'boolean') {
if (
typeof navigation.state.isTransitioning !== 'boolean' ||
(navigation.state.isTransitioning !== true &&
!navigation.dangerouslyGetParent())
) {
this._emitDidFocus(target, payload);
}
};
@@ -283,7 +295,11 @@ export default class NavigationEventManager extends React.Component {
onEvent(target, 'willBlur', payload);
if (typeof navigation.state.isTransitioning !== 'boolean') {
if (
typeof navigation.state.isTransitioning !== 'boolean' ||
(navigation.state.isTransitioning !== true &&
!navigation.dangerouslyGetParent())
) {
this._emitDidBlur(target, payload);
}
};