react-native-builder-bob
react-native-builder-bob copied to clipboard
[iOS] Update the module interface import location generated by CodeGen.
Ask your Question
Shouldn't we update the {%- project.name %}.h
from this :
#import <React/RCTBridgeModule.h>
@interface <%- project.name -%> : NSObject <RCTBridgeModule>
@end
to this :
#ifdef RCT_NEW_ARCH_ENABLED
#import "RN<%- project.name -%>Spec.h"
#else
#import <React/RCTBridgeModule.h>
#endif
#ifdef RCT_NEW_ARCH_ENABLED
@interface <%- project.name -%> : NSObject <Native<%- project.name -%>Spec>
#else
@interface <%- project.name -%> : NSObject <RCTBridgeModule>
#endif
@end
And also delete these lines from {%- project.name %}.mm
:
#ifdef RCT_NEW_ARCH_ENABLED
#import "RN<%- project.name -%>Spec.h"
#endif
Find my argument here ⬇️
Today If I define a new method (on JS side) in my turbo module interface Native{%- project.name %}.ts
, codegen generate new files. But I do not have in xCode any warning or error that tell me to implement this new method.
With my proposal, we now have a warning message inside xCode to generate automatically the function that is missing.
What to you think about it ? Am I missing something ?
Hello, thank you for opening this question.
I've tested your proposition and it seems to work for old architecture. However, for the new architecture, Xcode seems to ignore used macros(RCT_REMAP_METHOD) and still complaining about not conform protocol.
I'm not an expert on Objective-C if you have an idea how to workaround this please let us know. We are open to all suggestions :)
@MateWW Good point !
I'm also not an expert but this is the workaround I found ⬇️
Inside {%- project.name %}.mm
:
@implementation MyModule
RCT_EXPORT_MODULE()
/*
* With my proposal Xcode tells you that you do not have implemented this method.
* It generates it for you with correct typing etc ...
*/
- (void)myMethod:(NSNumber)param {
/*
* You create your implementation here.
* This method will be called for the new architecture.
*/
}
/*
* You do not have code generation here but you define "by hand" the RCT_REMAP_METHOD
*/
RCT_REMAP_METHOD(myMethod, param:(NSNumber)param)
{
/*
* Call here the method previously defined ⬆️
*/
[self myMethod:param]; // <= It will be called if new architecture is off.
}
// ...
@end
What do you think ? 😁
It looks promising, give me a few more days to consult that with someone from the team. I will get back to you as soon as possible.
Hi @MateWW 👋
Do you have any feedback ?
Hi @taboulot, I have discussed that with @satya164 and @BartoszKlonowski. It seems to be very useful and we would like to have it. Would you like to open PR with this change?
Hi @MateWW,
Thank you for the feedback.
Yes sure no problem. I will do it before the end of this WE.