Fix rendering of RN Tester New Architecture examples in Android

Summary:
When bridgeless is enabled, RN Tester New Architecture examples crashed with a StackOverflow Exception
The root cause of this issue is that MyLegacyViewManager is sending an event to JS during the execution of MyLegacyViewManager.createViewInstance() method.

This is a problem because the delivery of events depend on the "id" of the view, but the "id" of the view is set after MyLegacyViewManager.createViewInstance() finishes executing.

The documentations "implicitly" mentions to not set props during the execution of the ViewManager.createViewInstance() method:

https://reactnative.dev/docs/native-components-android#2-implement-method-createviewinstance

To fix this issue I'm removing the execution of the method that triggers the event.

bypass-github-export-checks

changelog: [Android][Fix] Fix rendering of 'RN Tester New Architecture examples' when bridgeless is enabled

Reviewed By: fkgozali

Differential Revision: D51047007

fbshipit-source-id: 17be493f79114fa402029063e79fabc1d90efc17
This commit is contained in:
David Vacca
2024-01-02 17:56:10 +00:00
committed by Alex Hunt
parent 5b382a8fa7
commit ddf0079ec5
@@ -27,7 +27,7 @@ internal class MyLegacyViewManager(reactContext: ReactApplicationContext) :
override fun getName(): String = REACT_CLASS
override fun createViewInstance(themedReactContext: ThemedReactContext): MyNativeView =
MyNativeView(themedReactContext).apply { setBackgroundColor(Color.RED) }
MyNativeView(themedReactContext)
@ReactProp(name = ViewProps.OPACITY, defaultFloat = 1f)
override fun setOpacity(view: MyNativeView, opacity: Float) {