mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
13780126d3
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: https://github.com/facebook/react-native/pull/47514
Test Plan: Tested with the reproduction case above to verify correct output.
Reviewed By: javache
Differential Revision: D65848670
Pulled By: elicwhite
fbshipit-source-id: 0021e87bc7213fff615465cab8554cc1a2159522
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
|
|
import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';
|
|
import type {
|
|
BubblingEventHandler,
|
|
Int32,
|
|
WithDefault,
|
|
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
|
|
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
|
|
type OnChangeEvent = $ReadOnly<{|
|
|
location: {
|
|
source: {url: string, ...},
|
|
x: Int32,
|
|
y: Int32,
|
|
arrayOfObjects: $ReadOnlyArray<{value: $ReadOnly<{str: string}>}>,
|
|
...
|
|
},
|
|
|}>;
|
|
|
|
type NativeProps = $ReadOnly<{|
|
|
...ViewProps,
|
|
|
|
// Props
|
|
disabled?: WithDefault<boolean, false>,
|
|
|
|
// Events
|
|
onChange?: ?BubblingEventHandler<OnChangeEvent>,
|
|
|}>;
|
|
|
|
export default (codegenNativeComponent<NativeProps>(
|
|
'EventNestedObjectPropsNativeComponentView',
|
|
): HostComponent<NativeProps>);
|