react-native-builder-bob icon indicating copy to clipboard operation
react-native-builder-bob copied to clipboard

[iOS] Update the module interface import location generated by CodeGen.

Open taboulot opened this issue 2 years ago • 3 comments

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 ?

taboulot avatar Aug 12 '22 12:08 taboulot

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 avatar Aug 12 '22 16:08 MateWW

@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 ? 😁

taboulot avatar Aug 13 '22 09:08 taboulot

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.

MateWW avatar Aug 16 '22 18:08 MateWW

Hi @MateWW 👋

Do you have any feedback ?

taboulot avatar Aug 23 '22 06:08 taboulot

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?

MateWW avatar Aug 23 '22 12:08 MateWW

Hi @MateWW,

Thank you for the feedback.

Yes sure no problem. I will do it before the end of this WE.

taboulot avatar Aug 24 '22 07:08 taboulot