Skip to content

Commit 9189852

Browse files
authored
refactor: use RCT_EXPORT_METHOD instead of RCT_REMAP_METHOD (#417)
### Summary Closes #414 We were using `RCT_REMAP_METHOD` to register methods in the current architecture. This macro generates a new method from the given method and changes its signature. I've changed it to `RCT_EXPORT_METHOD` and with this change, we are able to remove the duplicate implementation for mixed libraries. ### Test plan These changes can potentially change these libraries: `current arch objc`, `new arch objc`, `new arch cpp`, `mixed arch objc`, `mixed arch cpp`. We need to make sure all of those libraries are generated properly and work well.
1 parent 7fa4a76 commit 9189852

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

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

+6-12
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ @implementation <%- project.name -%>
77
<% if (project.arch === 'legacy' || project.arch === 'mixed') { -%>
88
// Example method
99
// See // https://reactnative.dev/docs/native-modules-ios
10-
RCT_REMAP_METHOD(multiply,
11-
multiplyWithA:(double)a withB:(double)b
12-
withResolver:(RCTPromiseResolveBlock)resolve
13-
withRejecter:(RCTPromiseRejectBlock)reject)
10+
RCT_EXPORT_METHOD(multiply:(double)a
11+
b:(double)b
12+
resolve:(RCTPromiseResolveBlock)resolve
13+
reject:(RCTPromiseRejectBlock)reject)
1414
{
1515
<% if (project.cpp) { -%>
1616
NSNumber *result = @(<%- project.package_cpp -%>::multiply(a, b));
@@ -20,29 +20,23 @@ @implementation <%- project.name -%>
2020

2121
resolve(result);
2222
}
23-
<% } -%>
2423

24+
<% } -%>
2525
<% if (project.arch === 'new' || project.arch === 'mixed') { -%>
2626
// Don't compile this code when we build for the old architecture.
2727
#ifdef RCT_NEW_ARCH_ENABLED
2828
<% if (project.arch === 'new') { -%>
2929
- (NSNumber *)multiply:(double)a b:(double)b {
30-
<% } else { -%>
31-
- (void)multiply:(double)a b:(double)b resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
32-
<% } -%>
3330
<% if (project.cpp) { -%>
3431
NSNumber *result = @(<%- project.package_cpp -%>::multiply(a, b));
3532
<% } else { -%>
3633
NSNumber *result = @(a * b);
3734
<% } -%>
3835

39-
<% if (project.arch === 'new') { -%>
4036
return result;
41-
<% } else { -%>
42-
resolve(result);
43-
<% } -%>
4437
}
4538

39+
<% } -%>
4640
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
4741
(const facebook::react::ObjCTurboModule::InitParams &)params
4842
{

0 commit comments

Comments
 (0)