Skip to content

Commit 57663f7

Browse files
Refactor ReactHostImpl to simplify logging (#44170)
Summary: Pull Request resolved: #44170 Addressing following logging issues with ReactHostImpl - replacing `ReactSoftExceptionLogger.logSoftException()` directly with private `raiseSoftException()` at all call-sites - `raiseSoftException()` already has a call to `log()`, hence removing that. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D56335797 fbshipit-source-id: 41e094b5dc25f23fa19cd391a85ea101c3ff9058
1 parent 99f3c24 commit 57663f7

File tree

1 file changed

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

1 file changed

+10
-21
lines changed

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -624,27 +624,26 @@ NativeModule getNativeModule(String nativeModuleName) {
624624
/* package */
625625
@Nullable
626626
RuntimeExecutor getRuntimeExecutor() {
627+
final String method = "getRuntimeExecutor()";
628+
627629
final ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
628630
if (reactInstance != null) {
629631
return reactInstance.getBufferedRuntimeExecutor();
630632
}
631-
ReactSoftExceptionLogger.logSoftException(
632-
TAG,
633-
new ReactNoCrashSoftException("Tried to get runtime executor while instance is not ready"));
633+
raiseSoftException(method, "Tried to get runtime executor while instance is not ready");
634634
return null;
635635
}
636636

637637
/* package */
638638
@Nullable
639639
CallInvokerHolder getJSCallInvokerHolder() {
640+
final String method = "getJSCallInvokerHolder()";
641+
640642
final ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
641643
if (reactInstance != null) {
642644
return reactInstance.getJSCallInvokerHolder();
643645
}
644-
ReactSoftExceptionLogger.logSoftException(
645-
TAG,
646-
new ReactNoCrashSoftException(
647-
"Tried to get JSCallInvokerHolder while instance is not ready"));
646+
raiseSoftException(method, "Tried to get JSCallInvokerHolder while instance is not ready");
648647
return null;
649648
}
650649

@@ -667,16 +666,12 @@ public void onActivityResult(
667666
+ "\", data = \""
668667
+ data
669668
+ "\")";
670-
log(method);
671669

672670
ReactContext currentContext = getCurrentReactContext();
673671
if (currentContext != null) {
674672
currentContext.onActivityResult(activity, requestCode, resultCode, data);
675673
} else {
676-
ReactSoftExceptionLogger.logSoftException(
677-
TAG,
678-
new ReactNoCrashSoftException(
679-
"Tried to access onActivityResult while context is not ready"));
674+
raiseSoftException(method, "Tried to access onActivityResult while context is not ready");
680675
}
681676
}
682677

@@ -685,16 +680,12 @@ public void onActivityResult(
685680
@Override
686681
public void onWindowFocusChange(boolean hasFocus) {
687682
final String method = "onWindowFocusChange(hasFocus = \"" + hasFocus + "\")";
688-
log(method);
689683

690684
ReactContext currentContext = getCurrentReactContext();
691685
if (currentContext != null) {
692686
currentContext.onWindowFocusChange(hasFocus);
693687
} else {
694-
ReactSoftExceptionLogger.logSoftException(
695-
TAG,
696-
new ReactNoCrashSoftException(
697-
"Tried to access onWindowFocusChange while context is not ready"));
688+
raiseSoftException(method, "Tried to access onWindowFocusChange while context is not ready");
698689
}
699690
}
700691

@@ -705,7 +696,7 @@ public void onWindowFocusChange(boolean hasFocus) {
705696
@ThreadConfined(UI)
706697
@Override
707698
public void onNewIntent(Intent intent) {
708-
log("onNewIntent()");
699+
final String method = "onNewIntent(intent = \"" + intent + "\")";
709700

710701
ReactContext currentContext = getCurrentReactContext();
711702
if (currentContext != null) {
@@ -723,9 +714,7 @@ public void onNewIntent(Intent intent) {
723714
}
724715
currentContext.onNewIntent(getCurrentActivity(), intent);
725716
} else {
726-
ReactSoftExceptionLogger.logSoftException(
727-
TAG,
728-
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
717+
raiseSoftException(method, "Tried to access onNewIntent while context is not ready");
729718
}
730719
}
731720

0 commit comments

Comments
 (0)