Allow map type objects in Java/ObjC TM EventEmitter (#45271)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45271

Changelog: [Internal] Allow map type objects in Java/ObjC TM EventEmitter

Reviewed By: rshest

Differential Revision: D59360044

fbshipit-source-id: 6fce094586ed2ad55a0d83a8a83ff554e2ba000e
This commit is contained in:
Christoph Purrer
2024-07-05 12:37:47 -07:00
committed by Facebook GitHub Bot
parent 504240caad
commit 85dc2e393f
8 changed files with 36 additions and 0 deletions
+1
View File
@@ -368,6 +368,7 @@ export type NativeModuleEventEmitterBaseTypeAnnotation =
| NativeModuleNumberTypeAnnotation
| NativeModuleStringTypeAnnotation
| NativeModuleTypeAliasTypeAnnotation
| NativeModuleGenericObjectTypeAnnotation
| VoidTypeAnnotation;
export type NativeModuleEventEmitterTypeAnnotation =
+1
View File
@@ -374,6 +374,7 @@ type NativeModuleEventEmitterBaseTypeAnnotation =
| NativeModuleNumberTypeAnnotation
| NativeModuleStringTypeAnnotation
| NativeModuleTypeAliasTypeAnnotation
| NativeModuleGenericObjectTypeAnnotation
| VoidTypeAnnotation;
export type NativeModuleEventEmitterTypeAnnotation =
@@ -137,6 +137,7 @@ function translateEventEmitterTypeToJavaType(
return 'double';
case 'BooleanTypeAnnotation':
return 'boolean';
case 'GenericObjectTypeAnnotation':
case 'ObjectTypeAnnotation':
case 'TypeAliasTypeAnnotation':
imports.add('com.facebook.react.bridge.ReadableMap');
@@ -22,6 +22,7 @@ function getEventEmitterTypeObjCType(
return 'NSNumber *_Nonnull';
case 'BooleanTypeAnnotation':
return 'BOOL';
case 'GenericObjectTypeAnnotation':
case 'ObjectTypeAnnotation':
case 'TypeAliasTypeAnnotation':
return 'NSDictionary *';
@@ -643,6 +643,8 @@ export type ObjectStruct = {
c?: ?string,
};
export type MappedObject = {[string]: string};
export interface Spec extends TurboModule {
+onEvent1: EventEmitter<void>;
+onEvent2: EventEmitter<string>;
@@ -650,6 +652,7 @@ export interface Spec extends TurboModule {
+onEvent4: EventEmitter<boolean>;
+onEvent5: EventEmitter<ObjectStruct>;
+onEvent6: EventEmitter<ObjectStruct[]>;
+onEvent7: EventEmitter<MappedObject>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
@@ -1527,6 +1527,19 @@ exports[`RN Codegen Flow Parser can generate fixture NATIVE_MODULE_WITH_EVENT_EM
}
}
}
},
{
'name': 'onEvent7',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'GenericObjectTypeAnnotation',
'dictionaryValueType': {
'type': 'StringTypeAnnotation'
}
}
}
}
],
'methods': []
@@ -742,6 +742,8 @@ export type ObjectStruct = {
c?: string | null;
};
export type MappedObject = {[key: string]: string};
export interface Spec extends TurboModule {
readonly onEvent1: EventEmitter<void>;
readonly onEvent2: EventEmitter<string>;
@@ -749,6 +751,7 @@ export interface Spec extends TurboModule {
readonly onEvent4: EventEmitter<boolean>;
readonly onEvent5: EventEmitter<ObjectStruct>;
readonly onEvent6: EventEmitter<ObjectStruct[]>;
readonly onEvent7: EventEmitter<MappedObject>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
@@ -1727,6 +1727,19 @@ exports[`RN Codegen TypeScript Parser can generate fixture NATIVE_MODULE_WITH_EV
}
}
}
},
{
'name': 'onEvent7',
'optional': false,
'typeAnnotation': {
'type': 'EventEmitterTypeAnnotation',
'typeAnnotation': {
'type': 'GenericObjectTypeAnnotation',
'dictionaryValueType': {
'type': 'StringTypeAnnotation'
}
}
}
}
],
'methods': []