Skip to content

Commit 99e990a

Browse files
committed
fix: add missing method for new arch for backward compatible turbo module
closes #386
1 parent 6835400 commit 99e990a

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@ @implementation <%- project.name -%>
44

55
RCT_EXPORT_MODULE()
66

7-
<% if (project.arch === 'new') { -%>
8-
- (NSNumber *)multiply:(double)a b:(double)b {
9-
<% if (project.cpp) { -%>
10-
NSNumber *result = @(<%- project.package_cpp -%>::multiply(a, b));
11-
<% } else { -%>
12-
NSNumber *result = @(a * b);
13-
<% } -%>
14-
15-
return result;
16-
}
17-
<% } else { -%>
7+
<% if (project.arch === 'legacy' || project.arch === 'mixed') { -%>
188
// Example method
199
// See // https://reactnative.dev/docs/native-modules-ios
2010
RCT_REMAP_METHOD(multiply,
@@ -32,13 +22,33 @@ - (NSNumber *)multiply:(double)a b:(double)b {
3222
}
3323
<% } -%>
3424

25+
<% if (project.arch === 'new' || project.arch === 'mixed') { -%>
3526
// Don't compile this code when we build for the old architecture.
3627
#ifdef RCT_NEW_ARCH_ENABLED
28+
<% if (project.arch === 'new') { -%>
29+
- (NSNumber *)multiply:(double)a b:(double)b {
30+
<% } else { -%>
31+
- (void)multiply:(double)a b:(double)b resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
32+
<% } -%>
33+
<% if (project.cpp) { -%>
34+
NSNumber *result = @(<%- project.package_cpp -%>::multiply(a, b));
35+
<% } else { -%>
36+
NSNumber *result = @(a * b);
37+
<% } -%>
38+
39+
<% if (project.arch === 'new') { -%>
40+
return result;
41+
<% } else { -%>
42+
resolve(result);
43+
<% } -%>
44+
}
45+
3746
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
3847
(const facebook::react::ObjCTurboModule::InitParams &)params
3948
{
4049
return std::make_shared<facebook::react::Native<%- project.name -%>SpecJSI>(params);
4150
}
4251
#endif
52+
<% } -%>
4353

4454
@end

0 commit comments

Comments
 (0)