Log a SoftException on SurfaceMountingManager.addRootView (#34785)

Summary:
Follow the same solution (do not throw a crash when view ID is set already) used in `ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java` for `ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java`

## Changelog

[Android] [Changed] - Log a SoftException on SurfaceMountingManager.addRootView

Pull Request resolved: https://github.com/facebook/react-native/pull/34785

Test Plan: None

Reviewed By: cipolleschi

Differential Revision: D40022263

Pulled By: cortinico

fbshipit-source-id: d565d2831e2833ccea55f28ea16083b7bae0ed32
This commit is contained in:
psionic12
2024-06-20 13:16:32 -07:00
committed by Facebook GitHub Bot
parent 3dcf86b802
commit 3429dc1ccf
@@ -211,11 +211,22 @@ public class SurfaceMountingManager {
+ " tag: [%d]",
rootView.getId(),
mSurfaceId);
throw new IllegalViewOperationException(
"Trying to add a root view with an explicit id already set. React Native uses the"
+ " id field to track react tags and will overwrite this field. If that is"
+ " fine, explicitly overwrite the id field to View.NO_ID before calling"
+ " addRootView.");
// This behavior can not be guaranteed in hybrid apps that have a native android layer
// over
// which reactRootViews are added and the native views need to have ids on them in order
// to
// work.
// Hence this can cause unnecessary crashes at runtime for hybrid apps.
// So converting this to a soft exception such that pure react-native devs can still see
// the
// warning while hybrid apps continue to run without crashes
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalViewOperationException(
"Trying to add a root view with an explicit id already set. React Native uses"
+ " the id field to track react tags and will overwrite this field. If that"
+ " is fine, explicitly overwrite the id field to View.NO_ID before calling"
+ " addRootView."));
}
rootView.setId(mSurfaceId);