Skip to content

Commit

Permalink
Dedupe trivial types between modules and components (facebook#46220)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#46220

We'll want to eventually combine the module and component capabilities more, but these are at least the trivially shared ones.

More work is required to merge the more complex object types.

This change also makes it more clear where capabilities are different between native modules and components

Changelog: [Internal]

Reviewed By: makovkastar

Differential Revision: D61740140

fbshipit-source-id: 9e7bf740cf6cd2431be8cad822ec69903dbbc71f
  • Loading branch information
elicwhite authored and facebook-github-bot committed Aug 27, 2024
1 parent 74c9ef8 commit 851037d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 44 deletions.
40 changes: 10 additions & 30 deletions packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,30 +286,10 @@ export type NativeModuleArrayTypeAnnotation<
elementType?: T,
}>;

export type NativeModuleStringTypeAnnotation = $ReadOnly<{
type: 'StringTypeAnnotation',
}>;

export type NativeModuleNumberTypeAnnotation = $ReadOnly<{
type: 'NumberTypeAnnotation',
}>;

export type NativeModuleInt32TypeAnnotation = $ReadOnly<{
type: 'Int32TypeAnnotation',
}>;

export type NativeModuleDoubleTypeAnnotation = $ReadOnly<{
type: 'DoubleTypeAnnotation',
}>;

export type NativeModuleFloatTypeAnnotation = $ReadOnly<{
type: 'FloatTypeAnnotation',
}>;

export type NativeModuleBooleanTypeAnnotation = $ReadOnly<{
type: 'BooleanTypeAnnotation',
}>;

export type NativeModuleEnumMembers = $ReadOnlyArray<
$ReadOnly<{
name: string,
Expand Down Expand Up @@ -367,12 +347,12 @@ export type NativeModuleMixedTypeAnnotation = $ReadOnly<{
}>;

type NativeModuleEventEmitterBaseTypeAnnotation =
| NativeModuleBooleanTypeAnnotation
| NativeModuleDoubleTypeAnnotation
| NativeModuleFloatTypeAnnotation
| NativeModuleInt32TypeAnnotation
| BooleanTypeAnnotation
| DoubleTypeAnnotation
| FloatTypeAnnotation
| Int32TypeAnnotation
| NativeModuleNumberTypeAnnotation
| NativeModuleStringTypeAnnotation
| StringTypeAnnotation
| NativeModuleTypeAliasTypeAnnotation
| NativeModuleGenericObjectTypeAnnotation
| VoidTypeAnnotation;
Expand All @@ -385,12 +365,12 @@ export type NativeModuleEventEmitterTypeAnnotation =
};

export type NativeModuleBaseTypeAnnotation =
| NativeModuleStringTypeAnnotation
| StringTypeAnnotation
| NativeModuleNumberTypeAnnotation
| NativeModuleInt32TypeAnnotation
| NativeModuleDoubleTypeAnnotation
| NativeModuleFloatTypeAnnotation
| NativeModuleBooleanTypeAnnotation
| Int32TypeAnnotation
| DoubleTypeAnnotation
| FloatTypeAnnotation
| BooleanTypeAnnotation
| NativeModuleEnumDeclaration
| NativeModuleGenericObjectTypeAnnotation
| ReservedTypeAnnotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
import type {
NativeModuleArrayTypeAnnotation,
NativeModuleBaseTypeAnnotation,
NativeModuleBooleanTypeAnnotation,
NativeModuleDoubleTypeAnnotation,
BooleanTypeAnnotation,
DoubleTypeAnnotation,
NativeModuleEnumDeclaration,
NativeModuleFloatTypeAnnotation,
FloatTypeAnnotation,
NativeModuleGenericObjectTypeAnnotation,
NativeModuleInt32TypeAnnotation,
Int32TypeAnnotation,
NativeModuleNumberTypeAnnotation,
NativeModuleObjectTypeAnnotation,
NativeModuleStringTypeAnnotation,
StringTypeAnnotation,
NativeModuleTypeAliasTypeAnnotation,
Nullable,
ReservedTypeAnnotation,
Expand Down Expand Up @@ -57,12 +57,12 @@ export type StructProperty = $ReadOnly<{
}>;

export type StructTypeAnnotation =
| NativeModuleStringTypeAnnotation
| StringTypeAnnotation
| NativeModuleNumberTypeAnnotation
| NativeModuleInt32TypeAnnotation
| NativeModuleDoubleTypeAnnotation
| NativeModuleFloatTypeAnnotation
| NativeModuleBooleanTypeAnnotation
| Int32TypeAnnotation
| DoubleTypeAnnotation
| FloatTypeAnnotation
| BooleanTypeAnnotation
| NativeModuleEnumDeclaration
| NativeModuleGenericObjectTypeAnnotation
| ReservedTypeAnnotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
NativeModuleBaseTypeAnnotation,
NativeModuleEnumDeclaration,
NativeModuleEnumMap,
NativeModuleFloatTypeAnnotation,
FloatTypeAnnotation,
NativeModuleFunctionTypeAnnotation,
NativeModuleGenericObjectTypeAnnotation,
NativeModuleMixedTypeAnnotation,
Expand Down Expand Up @@ -368,9 +368,7 @@ function emitObject(
});
}

function emitFloat(
nullable: boolean,
): Nullable<NativeModuleFloatTypeAnnotation> {
function emitFloat(nullable: boolean): Nullable<FloatTypeAnnotation> {
return wrapNullable(nullable, {
type: 'FloatTypeAnnotation',
});
Expand Down

0 comments on commit 851037d

Please sign in to comment.