Skip to content

Commit b152ccf

Browse files
feat(ios): enable function generation by Xcode with CodeGen interface (#267)
When I use Turbo module, today If I define a new method (on JS side) in my turbo module interface Native{%- project.name %}.ts, codegen generates new files. But I do not have in Xcode any warning or error that tells me to implement this new method. Closes #261 Co-authored-by: Bartosz Klonowski <[email protected]> Co-authored-by: Bartosz Klonowski <[email protected]>
1 parent 7a0c0e9 commit b152ccf

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
#ifdef RCT_NEW_ARCH_ENABLED
2+
#import "RN<%- project.name -%>Spec.h"
3+
4+
@interface <%- project.name -%> : NSObject <Native<%- project.name -%>Spec>
5+
#else
16
#import <React/RCTBridgeModule.h>
27

38
@interface <%- project.name -%> : NSObject <RCTBridgeModule>
9+
#endif
410

511
@end

packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
#import "<%- project.name -%>.h"
22

3-
#ifdef RCT_NEW_ARCH_ENABLED
4-
#import "RN<%- project.name -%>Spec.h"
5-
#endif
6-
73
@implementation <%- project.name -%>
84

95
RCT_EXPORT_MODULE()
106

7+
<% if (project.architecture == 'turbo') { -%>
8+
- (NSNumber *)multiply:(double)a b:(double)b {
9+
NSNumber *result = @(a * b);
10+
11+
return result;
12+
}
13+
<% } else if (project.architecture == 'mixed') { -%>
1114
// Example method
1215
// See // https://reactnative.dev/docs/native-modules-ios
13-
<% if (project.architecture == 'turbo') { -%>
14-
RCT_REMAP_BLOCKING_SYNCHRONOUS_METHOD(multiply,
15-
NSNumber *,
16-
multiplyWithA:(double)a withB:(double)b)
16+
RCT_REMAP_METHOD(multiply,
17+
multiplyWithA:(double)a withB:(double)b
18+
withResolver:(RCTPromiseResolveBlock)resolve
19+
withRejecter:(RCTPromiseRejectBlock)reject)
1720
{
21+
[self multiply:a b:b resolve:resolve reject:reject];
22+
}
23+
24+
- (void)multiply:(double)a b:(double)b resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1825
NSNumber *result = @(a * b);
1926

20-
return result;
27+
resolve(result);
2128
}
2229
<% } else { -%>
30+
// Example method
31+
// See // https://reactnative.dev/docs/native-modules-ios
2332
RCT_REMAP_METHOD(multiply,
2433
multiplyWithA:(double)a withB:(double)b
2534
withResolver:(RCTPromiseResolveBlock)resolve

0 commit comments

Comments
 (0)