Skip to content

Commit ac3261f

Browse files
Add ReactSoftException in ReactHostImpl only when onActivityResult, onNewIntent and onWindowFocusChange do not have the context (#44155)
Summary: Pull Request resolved: #44155 Add ReactSoftException in ReactHostImpl only when `onActivityResult`, `onNewIntent`and `onWindowFocusChange` do not have the context Changelog: [Android][Fixed] ReactSoftExceptions in ReactHostImpl only when Context is null Reviewed By: cortinico Differential Revision: D56325407 fbshipit-source-id: a9f8fd5772fc05d39e72236fb8edfe5f8a9d6a43
1 parent efb073f commit ac3261f

File tree

1 file changed

+14
-11
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime

1 file changed

+14
-11
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,12 @@ public void onActivityResult(
672672
ReactContext currentContext = getCurrentReactContext();
673673
if (currentContext != null) {
674674
currentContext.onActivityResult(activity, requestCode, resultCode, data);
675+
} else {
676+
ReactSoftExceptionLogger.logSoftException(
677+
TAG,
678+
new ReactNoCrashSoftException(
679+
"Tried to access onActivityResult while context is not ready"));
675680
}
676-
ReactSoftExceptionLogger.logSoftException(
677-
TAG,
678-
new ReactNoCrashSoftException(
679-
"Tried to access onActivityResult while context is not ready"));
680681
}
681682

682683
/* To be called when focus has changed for the hosting window. */
@@ -689,11 +690,12 @@ public void onWindowFocusChange(boolean hasFocus) {
689690
ReactContext currentContext = getCurrentReactContext();
690691
if (currentContext != null) {
691692
currentContext.onWindowFocusChange(hasFocus);
693+
} else {
694+
ReactSoftExceptionLogger.logSoftException(
695+
TAG,
696+
new ReactNoCrashSoftException(
697+
"Tried to access onWindowFocusChange while context is not ready"));
692698
}
693-
ReactSoftExceptionLogger.logSoftException(
694-
TAG,
695-
new ReactNoCrashSoftException(
696-
"Tried to access onWindowFocusChange while context is not ready"));
697699
}
698700

699701
/* This method will give JS the opportunity to receive intents via Linking.
@@ -720,10 +722,11 @@ public void onNewIntent(Intent intent) {
720722
}
721723
}
722724
currentContext.onNewIntent(getCurrentActivity(), intent);
725+
} else {
726+
ReactSoftExceptionLogger.logSoftException(
727+
TAG,
728+
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
723729
}
724-
ReactSoftExceptionLogger.logSoftException(
725-
TAG,
726-
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
727730
}
728731

729732
@ThreadConfined(UI)

0 commit comments

Comments
 (0)