Skip to content

Commit

Permalink
Extract SoftException categories (#48289)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #48289

Provide a mechanism to register specific category constants, which can be used by individual  `ReactSoftExceptionListener`s to differentiate behavior, if desired.

Changelog: [Android][Added] SoftException categories

Reviewed By: makovkastar

Differential Revision: D66785403

fbshipit-source-id: cb2c8861bb1dce29a6787d328b814cee09f36464
  • Loading branch information
Thomas Nardone authored and facebook-github-bot committed Dec 17, 2024
1 parent 2516414 commit c832f94
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,12 @@ public final class com/facebook/react/bridge/ReactSoftExceptionLogger {
public static final fun removeListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
}

public final class com/facebook/react/bridge/ReactSoftExceptionLogger$Categories {
public static final field INSTANCE Lcom/facebook/react/bridge/ReactSoftExceptionLogger$Categories;
public static final field RVG_IS_VIEW_CLIPPED Ljava/lang/String;
public static final field RVG_ON_VIEW_REMOVED Ljava/lang/String;
}

public abstract interface class com/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener {
public abstract fun logSoftException (Ljava/lang/String;Ljava/lang/Throwable;)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import kotlin.jvm.JvmStatic

@DoNotStrip
public object ReactSoftExceptionLogger {
/** Constants that listeners can utilize for custom category-based behavior. */
public object Categories {
public const val RVG_IS_VIEW_CLIPPED: String = "ReactViewGroup.isViewClipped"
public const val RVG_ON_VIEW_REMOVED: String = "ReactViewGroup.onViewRemoved"
}

// Use a list instead of a set here because we expect the number of listeners
// to be very small, and we want listeners to be called in a deterministic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ private void checkViewClippingTag(View child, Boolean expectedTag) {
Object tag = child.getTag(R.id.view_clipped);
if (!expectedTag.equals(tag)) {
ReactSoftExceptionLogger.logSoftException(
"ReactViewGroup.onViewRemoved",
ReactSoftExceptionLogger.Categories.RVG_ON_VIEW_REMOVED,
new ReactNoCrashSoftException(
"View clipping tag mismatch: tag=" + tag + " expected=" + expectedTag));
}
Expand Down Expand Up @@ -777,7 +777,7 @@ private boolean isViewClipped(View view, @Nullable Integer index) {
boolean transitioning = isChildRemovedWhileTransitioning(view);
if (index != null) {
ReactSoftExceptionLogger.logSoftException(
"ReactViewGroup.isViewClipped",
ReactSoftExceptionLogger.Categories.RVG_IS_VIEW_CLIPPED,
new ReactNoCrashSoftException(
"View missing clipping tag: index="
+ index
Expand Down

0 comments on commit c832f94

Please sign in to comment.