Skip to content

Commit 71153f6

Browse files
arushikesarwani94cipolleschi
authored andcommitted
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 2636eb1 commit 71153f6

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

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

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
@@ -653,11 +653,12 @@ public void onActivityResult(
653653
ReactContext currentContext = getCurrentReactContext();
654654
if (currentContext != null) {
655655
currentContext.onActivityResult(activity, requestCode, resultCode, data);
656+
} else {
657+
ReactSoftExceptionLogger.logSoftException(
658+
TAG,
659+
new ReactNoCrashSoftException(
660+
"Tried to access onActivityResult while context is not ready"));
656661
}
657-
ReactSoftExceptionLogger.logSoftException(
658-
TAG,
659-
new ReactNoCrashSoftException(
660-
"Tried to access onActivityResult while context is not ready"));
661662
}
662663

663664
/* To be called when focus has changed for the hosting window. */
@@ -670,11 +671,12 @@ public void onWindowFocusChange(boolean hasFocus) {
670671
ReactContext currentContext = getCurrentReactContext();
671672
if (currentContext != null) {
672673
currentContext.onWindowFocusChange(hasFocus);
674+
} else {
675+
ReactSoftExceptionLogger.logSoftException(
676+
TAG,
677+
new ReactNoCrashSoftException(
678+
"Tried to access onWindowFocusChange while context is not ready"));
673679
}
674-
ReactSoftExceptionLogger.logSoftException(
675-
TAG,
676-
new ReactNoCrashSoftException(
677-
"Tried to access onWindowFocusChange while context is not ready"));
678680
}
679681

680682
/* This method will give JS the opportunity to receive intents via Linking.
@@ -701,10 +703,11 @@ public void onNewIntent(Intent intent) {
701703
}
702704
}
703705
currentContext.onNewIntent(getCurrentActivity(), intent);
706+
} else {
707+
ReactSoftExceptionLogger.logSoftException(
708+
TAG,
709+
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
704710
}
705-
ReactSoftExceptionLogger.logSoftException(
706-
TAG,
707-
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
708711
}
709712

710713
@ThreadConfined(UI)

0 commit comments

Comments
 (0)