Skip to content

Commit

Permalink
Separate component array types and command array types (#48474)
Browse files Browse the repository at this point in the history
Summary:

The previous definition said that you could put prop types into commands, which definitely isn't allowed.

For example, the schema would have allowed `WithDefault` types.

```
interface NativeCommands {
  +methodInt: (viewRef: React.ElementRef<NativeType>, a: WithDefault<string, 'hi'>) => void;
}
```

This change separates out the things that are allowed in commands from what's allowed in props.

Commands should be very similar to what's allowed in native modules, but it isn't exact enough to be able to merge those.

Differential Revision: D67806818
  • Loading branch information
elicwhite authored and facebook-github-bot committed Jan 3, 2025
1 parent 5c269f5 commit 8b2f4e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion packages/react-native-codegen/src/CodegenSchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ export type ComponentArrayTypeAnnotation = ArrayTypeAnnotation<
| ArrayTypeAnnotation<ObjectTypeAnnotation<PropTypeAnnotation>>
>;

export type ComponentCommandArrayTypeAnnotation = ArrayTypeAnnotation<
| BooleanTypeAnnotation
| StringTypeAnnotation
| DoubleTypeAnnotation
| FloatTypeAnnotation
| Int32TypeAnnotation
| ObjectTypeAnnotation<ComponentCommandArrayTypeAnnotation>
| ArrayTypeAnnotation<
ObjectTypeAnnotation<ComponentCommandArrayTypeAnnotation>
>
>;

export interface ArrayTypeAnnotation<T> {
readonly type: 'ArrayTypeAnnotation';
readonly elementType: T;
Expand Down Expand Up @@ -206,7 +218,7 @@ export type CommandParamTypeAnnotation =
| DoubleTypeAnnotation
| FloatTypeAnnotation
| StringTypeAnnotation
| ComponentArrayTypeAnnotation;
| ComponentCommandArrayTypeAnnotation;

export interface ReservedTypeAnnotation {
readonly type: 'ReservedTypeAnnotation';
Expand Down
14 changes: 13 additions & 1 deletion packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ export type ComponentArrayTypeAnnotation = ArrayTypeAnnotation<
| ArrayTypeAnnotation<ObjectTypeAnnotation<PropTypeAnnotation>>,
>;

export type ComponentCommandArrayTypeAnnotation = ArrayTypeAnnotation<
| BooleanTypeAnnotation
| StringTypeAnnotation
| DoubleTypeAnnotation
| FloatTypeAnnotation
| Int32TypeAnnotation
| ObjectTypeAnnotation<ComponentCommandArrayTypeAnnotation>
| ArrayTypeAnnotation<
ObjectTypeAnnotation<ComponentCommandArrayTypeAnnotation>,
>,
>;

export type ArrayTypeAnnotation<+T> = $ReadOnly<{
type: 'ArrayTypeAnnotation',
elementType: T,
Expand Down Expand Up @@ -222,7 +234,7 @@ export type CommandParamTypeAnnotation =
| DoubleTypeAnnotation
| FloatTypeAnnotation
| StringTypeAnnotation
| ComponentArrayTypeAnnotation;
| ComponentCommandArrayTypeAnnotation;

export type ReservedTypeAnnotation = $ReadOnly<{
type: 'ReservedTypeAnnotation',
Expand Down

0 comments on commit 8b2f4e3

Please sign in to comment.