Skip to content

Commit

Permalink
Fix generated EventEmitter code for nested objects in arrays. (#47514)
Browse files Browse the repository at this point in the history
Summary:
This PR fixes the code for generating EventEmitter C++ code in case nested objects in arrays are used.

```typescript
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:

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

while

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

is expected.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

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

Pull Request resolved: #47514

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

Reviewed By: christophpurrer

Differential Revision: D65884936

Pulled By: elicwhite
  • Loading branch information
tvanlaerhoven authored and facebook-github-bot committed Nov 13, 2024
1 parent 022ce1f commit 3edf6ba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void EventNestedObjectPropsNativeComponentViewEventEmitter::onChange(OnChange $e
auto arrayOfObjectsObject = jsi::Object(runtime);
{
auto value = jsi::Object(runtime);
value.setProperty(runtime, \\"str\\", arrayOfObjectsValue,value.str);
value.setProperty(runtime, \\"str\\", arrayOfObjectsValue.value.str);
arrayOfObjectsObject.setProperty(runtime, \\"value\\", value);
}
arrayOfObjects.setValueAtIndex(runtime, arrayOfObjectsIndex++, arrayOfObjectsObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function generateSetter(
) {
const eventChain = usingEvent
? `$event.${[...propertyParts, propertyName].join('.')}`
: [propertyParts, propertyName].join('.');
: [...propertyParts, propertyName].join('.');
return `${variableName}.setProperty(runtime, "${propertyName}", ${valueMapper(
eventChain,
)});`;
Expand Down Expand Up @@ -157,7 +157,7 @@ function generateArraySetter(
): string {
const eventChain = usingEvent
? `$event.${[...propertyParts, propertyName].join('.')}`
: [propertyParts, propertyName].join('.');
: [...propertyParts, propertyName].join('.');
const indexVar = `${propertyName}Index`;
const innerLoopVar = `${propertyName}Value`;
return `
Expand Down

0 comments on commit 3edf6ba

Please sign in to comment.