Skip to content

Commit

Permalink
Support Array parsing in events
Browse files Browse the repository at this point in the history
Summary:
This diff introduce support to parse arrays in events.

We support parsing Arrays of:
- Boolean
- Double
- Float
- Int32
- String Enums
- String
- Objects
- Arrays

## Changelog:
[General][Added] - Add generic support for Arrays in Events parsing

Differential Revision: https://internalfb.com/D45268779

fbshipit-source-id: f6dae6bc89ed4d28bf4c4275a504b7e07a84d20c
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed May 4, 2023
1 parent 1cd0f57 commit 4a47831
Show file tree
Hide file tree
Showing 10 changed files with 20,103 additions and 6,019 deletions.
7 changes: 5 additions & 2 deletions packages/react-native-codegen/src/CodegenSchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ export type EventTypeAnnotation =
| FloatTypeAnnotation
| Int32TypeAnnotation
| StringEnumTypeAnnotation
| ObjectTypeAnnotation<EventTypeAnnotation>;
| ObjectTypeAnnotation<EventTypeAnnotation>
| {
readonly type: 'ArrayTypeAnnotation';
readonly elementType: EventTypeAnnotation
};

export type PropTypeAnnotation =
| {
Expand Down Expand Up @@ -352,4 +356,3 @@ export type NativeModuleReturnOnlyTypeAnnotation =
| NativeModuleFunctionTypeAnnotation
| NativeModulePromiseTypeAnnotation
| VoidTypeAnnotation;

6 changes: 5 additions & 1 deletion packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ export type EventTypeAnnotation =
| Int32TypeAnnotation
| MixedTypeAnnotation
| StringEnumTypeAnnotation
| ObjectTypeAnnotation<EventTypeAnnotation>;
| ObjectTypeAnnotation<EventTypeAnnotation>
| $ReadOnly<{
type: 'ArrayTypeAnnotation',
elementType: EventTypeAnnotation,
}>;

export type PropTypeAnnotation =
| $ReadOnly<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ function generateSetters(
typeAnnotation,
extraIncludes,
);
case 'ArrayTypeAnnotation':
// TODO: implement this in the next diff
break;
default:
(typeAnnotation.type: empty);
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ function getNativeTypeFromAnnotation(
case 'StringEnumTypeAnnotation':
case 'ObjectTypeAnnotation':
return generateEventStructName([...nameParts, eventProperty.name]);
case 'ArrayTypeAnnotation':
// TODO: implement this in the next diff
return '';
default:
(type: empty);
throw new Error(`Received invalid event property type ${type}`);
Expand Down Expand Up @@ -205,6 +208,9 @@ function generateStruct(
case 'StringEnumTypeAnnotation':
generateEnum(structs, typeAnnotation.options, nameParts.concat([name]));
return;
case 'ArrayTypeAnnotation':
//TODO: implement this in the next diff
break;
default:
(typeAnnotation.type: empty);
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,57 @@ const EVENT_DEFINITION = `
object_readonly_optional_both?: ?$ReadOnly<{
int32_optional_both?: ?Int32,
}>,
boolean_array_required: $ReadOnlyArray<boolean>,
boolean_array_optional_key?: boolean[],
boolean_array_optional_value: ?$ReadOnlyArray<boolean>,
boolean_array_optional_both?: ?boolean[],
string_array_required: $ReadOnlyArray<string>,
string_array_optional_key?: string[],
string_array_optional_value: ?$ReadOnlyArray<string>,
string_array_optional_both?: ?string[],
double_array_required: $ReadOnlyArray<Double>,
double_array_optional_key?: Double[],
double_array_optional_value: ?$ReadOnlyArray<Double>,
double_array_optional_both?: ?Double[],
float_array_required: $ReadOnlyArray<Float>,
float_array_optional_key?: Float[],
float_array_optional_value: ?$ReadOnlyArray<Float>,
float_array_optional_both?: ?Float[],
int32_array_required: $ReadOnlyArray<Int32>,
int32_array_optional_key?: Int32[],
int32_array_optional_value: ?$ReadOnlyArray<Int32>,
int32_array_optional_both?: ?Int32[],
enum_array_required: $ReadOnlyArray<('small' | 'large')>,
enum_array_optional_key?: ('small' | 'large')[],
enum_array_optional_value: ?$ReadOnlyArray<('small' | 'large')>,
enum_array_optional_both?: ?('small' | 'large')[],
object_array_required: $ReadOnlyArray<{
boolean_required: boolean,
}>,
object_array_optional_key?: {
string_optional_key?: string,
}[],
object_array_optional_value: ?$ReadOnlyArray<{
float_optional_value: ?Float,
}>,
object_array_optional_both?: ?{
int32_optional_both?: ?Int32,
}[],
int32_array_array_required: $ReadOnlyArray<$ReadOnlyArray<Int32>>,
int32_array_array_optional_key?: Int32[][],
int32_array_array_optional_value: ?$ReadOnlyArray<$ReadOnlyArray<Int32>>,
int32_array_array_optional_both?: ?Int32[][],
`;

const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
Expand Down
Loading

0 comments on commit 4a47831

Please sign in to comment.