-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EventEmitter Code-gen support for Java and ObjC Turbo Modules (#4…
…5119) Summary: Pull Request resolved: #45119 ## Changelog: [iOS][Added] - Add EventEmitter Code-gen support for Java and ObjC Turbo Modules Reviewed By: RSNara Differential Revision: D58929417 fbshipit-source-id: 5208ba5ecb5882d47c3827c2aa8e3a54a3d7f2b6
- Loading branch information
1 parent
9d30523
commit ad3df84
Showing
14 changed files
with
1,305 additions
and
47 deletions.
There are no files selected for viewing
352 changes: 320 additions & 32 deletions
352
...eact-native-codegen/e2e/__tests__/modules/__snapshots__/GenerateModuleObjCpp-test.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeEventEmitter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* 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. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
import type {NativeModuleEventEmitterShape} from '../../../CodegenSchema'; | ||
|
||
const {toPascalCase} = require('../../Utils'); | ||
|
||
function getEventEmitterTypeObjCType( | ||
eventEmitter: NativeModuleEventEmitterShape, | ||
): string { | ||
switch (eventEmitter.typeAnnotation.typeAnnotation.type) { | ||
case 'StringTypeAnnotation': | ||
return 'NSString *_Nonnull'; | ||
case 'NumberTypeAnnotation': | ||
return 'NSNumber *_Nonnull'; | ||
case 'BooleanTypeAnnotation': | ||
return 'BOOL'; | ||
case 'ObjectTypeAnnotation': | ||
case 'TypeAliasTypeAnnotation': | ||
return 'NSDictionary *'; | ||
case 'ArrayTypeAnnotation': | ||
return 'NSArray<id<NSObject>> *'; | ||
default: | ||
throw new Error( | ||
`Unsupported eventType for ${eventEmitter.name}. Found: ${eventEmitter.typeAnnotation.typeAnnotation.type}`, | ||
); | ||
} | ||
} | ||
|
||
function EventEmitterHeaderTemplate( | ||
eventEmitter: NativeModuleEventEmitterShape, | ||
): string { | ||
return `- (void)emit${toPascalCase(eventEmitter.name)}${ | ||
eventEmitter.typeAnnotation.typeAnnotation.type !== 'VoidTypeAnnotation' | ||
? `:(${getEventEmitterTypeObjCType(eventEmitter)})value` | ||
: '' | ||
};`; | ||
} | ||
|
||
function EventEmitterImplementationTemplate( | ||
eventEmitter: NativeModuleEventEmitterShape, | ||
): string { | ||
return `- (void)emit${toPascalCase(eventEmitter.name)}${ | ||
eventEmitter.typeAnnotation.typeAnnotation.type !== 'VoidTypeAnnotation' | ||
? `:(${getEventEmitterTypeObjCType(eventEmitter)})value` | ||
: '' | ||
} | ||
{ | ||
_eventEmitterCallback("${eventEmitter.name}", ${ | ||
eventEmitter.typeAnnotation.typeAnnotation.type !== 'VoidTypeAnnotation' | ||
? eventEmitter.typeAnnotation.typeAnnotation.type !== | ||
'BooleanTypeAnnotation' | ||
? 'value' | ||
: '[NSNumber numberWithBool:value]' | ||
: 'nil' | ||
}); | ||
}`; | ||
} | ||
|
||
module.exports = { | ||
EventEmitterHeaderTemplate, | ||
EventEmitterImplementationTemplate, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.