Skip to content

Commit

Permalink
Add ReactSoftException in ReactHostImpl only when onActivityResult, o…
Browse files Browse the repository at this point in the history
…nNewIntent 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
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Apr 19, 2024
1 parent efb073f commit ac3261f
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,12 @@ public void onActivityResult(
ReactContext currentContext = getCurrentReactContext();
if (currentContext != null) {
currentContext.onActivityResult(activity, requestCode, resultCode, data);
} else {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Tried to access onActivityResult while context is not ready"));
}
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Tried to access onActivityResult while context is not ready"));
}

/* To be called when focus has changed for the hosting window. */
Expand All @@ -689,11 +690,12 @@ public void onWindowFocusChange(boolean hasFocus) {
ReactContext currentContext = getCurrentReactContext();
if (currentContext != null) {
currentContext.onWindowFocusChange(hasFocus);
} else {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Tried to access onWindowFocusChange while context is not ready"));
}
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Tried to access onWindowFocusChange while context is not ready"));
}

/* This method will give JS the opportunity to receive intents via Linking.
Expand All @@ -720,10 +722,11 @@ public void onNewIntent(Intent intent) {
}
}
currentContext.onNewIntent(getCurrentActivity(), intent);
} else {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
}
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
}

@ThreadConfined(UI)
Expand Down

1 comment on commit ac3261f

@C2418M31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please merge this?

Please sign in to comment.