From be9c7dbbf77b357de3ec98ef8020613202938106 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 13 Feb 2025 15:28:59 -0800 Subject: [PATCH 1/2] Enforce that ViewManagers using codegen override getDelegate() method (#49414) Summary: In this we are enforcing that that ViewManagers using codegen override getDelegate() method. For now we are logging a softException to get signal from production without crashing the app changelog: [internal] internal Reviewed By: javache Differential Revision: D69621301 --- .../com/facebook/react/uimanager/ViewManager.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java index 7b2fe5ad65fc..f52aaf8787de 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java @@ -15,6 +15,8 @@ import com.facebook.react.bridge.BaseJavaModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.ReactNoCrashSoftException; +import com.facebook.react.bridge.ReactSoftExceptionLogger; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.common.annotations.UnstableReactNativeAPI; @@ -113,7 +115,15 @@ public void updateProperties(@NonNull T viewToUpdate, ReactStylesDiffMap props) * view manager should be set via this delegate */ protected ViewManagerDelegate getDelegate() { - return new ViewManagerPropertyUpdater.GenericViewManagerDelegate(this); + if (this instanceof ViewManagerWithGeneratedInterface) { + ReactSoftExceptionLogger.logSoftException( + NAME, + new ReactNoCrashSoftException( + "ViewManager using codegen must override getDelegate method (name: " + + getName() + + ").")); + } + return new ViewManagerPropertyUpdater.GenericViewManagerDelegate<>(this); } private ViewManagerDelegate getOrCreateViewManagerDelegate() { From 47967df7653473e245f94fd01bcbbdbce4833f1c Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 13 Feb 2025 15:28:59 -0800 Subject: [PATCH 2/2] EZ refactor in ViewManager Summary: Refactoring NAME -> TAG for consistency with other classes changelog: [internal] internal Reviewed By: Abbondanzo Differential Revision: D69622546 --- .../java/com/facebook/react/uimanager/ViewManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java index f52aaf8787de..b1d88ae75907 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java @@ -42,7 +42,7 @@ public abstract class ViewManager extends BaseJavaModule { - private static final String NAME = ViewManager.class.getSimpleName(); + private static final String TAG = "ViewManager"; private @Nullable ViewManagerDelegate mDelegate = null; @@ -117,7 +117,7 @@ public void updateProperties(@NonNull T viewToUpdate, ReactStylesDiffMap props) protected ViewManagerDelegate getDelegate() { if (this instanceof ViewManagerWithGeneratedInterface) { ReactSoftExceptionLogger.logSoftException( - NAME, + TAG, new ReactNoCrashSoftException( "ViewManager using codegen must override getDelegate method (name: " + getName() @@ -237,12 +237,12 @@ public void onDropViewInstance(@NonNull T view) { if (viewContext == null) { // Who knows! Anything is possible. Checking instanceof on null is an NPE, // So this is not redundant. - FLog.e(NAME, "onDropViewInstance: view [" + view.getId() + "] has a null context"); + FLog.e(TAG, "onDropViewInstance: view [" + view.getId() + "] has a null context"); return; } if (!(viewContext instanceof ThemedReactContext)) { FLog.e( - NAME, + TAG, "onDropViewInstance: view [" + view.getId() + "] has a context that is not a ThemedReactContext: "