facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.28k stars 24.35k forks source link

Fix generated EventEmitter code for nested objects in arrays. (#47514) #47597

Open elicwhite opened 3 days ago

elicwhite commented 3 days ago

Summary: This PR fixes the code for generating EventEmitter C++ code in case nested objects in arrays are used.

export interface NativeProps extends ViewProps {
  onEvent: DirectEventHandler<
    Readonly<{
      payloadArray: Readonly<
        {
          obj: Readonly<{ str: string }>
        }[]
      >
    }>
  >;
}

export default codegenNativeComponent<NativeProps>('SomeComponent');

In this case the generated EventEmitters.cpp code would contain:

obj.setProperty(runtime, "str", payloadArrayValue,obj.str);

while

obj.setProperty(runtime, "str", payloadArrayValue.obj.str);

is expected.

Changelog:

[GENERAL] [FIXED] - Codegen: Support nested objects in arrays

Test Plan: Tested with the reproduction case above to verify correct output.

Reviewed By: christophpurrer

Differential Revision: D65884936

Pulled By: elicwhite

facebook-github-bot commented 3 days ago

This pull request was exported from Phabricator. Differential Revision: D65884936