1

I'm trying to make sense of an iOS native module whose code is generated by djinni.

According to the React Native doc, you must include the RCT_EXPORT_MODULE() macro in your code. This working sample does not.

Later in the documentation it is said that the exception is Swift, where there is no macro like that.

Unless I'm wrong, this is not the case.

I'm trying to replicate the use of djinni generated code in my own project but when I run it, it fails because React Native is unable to load my native module:

undefined is not an object (evaluating 'HelloWorld.getHelloWorld')

I'm wondering if I could step through the NativeModule request code:

var HelloWorld = NativeModules.HelloWorld;

To understand what is going on.

Thanks for your help.

1 Answers1

0

All right mystery solved.

The secret is located in the AppDelegate implementation:

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:moduleInitialiser launchOptions:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"ExampleProject"
                                            initialProperties:nil];

The RCTRootView pointer is initialized with a call to

initWithBridge

Of course you have to previously allocate the RCTBridge object.

The RCT_Export_Module macro is not required in that use case, you just have to provide the module name:

+ (NSString *)moduleName
{
   return @"HelloWorld";
}

The macro does this for you automatically.

I was still using :

initWithBundleURL

In my own project duplicated from a basic create-react-app application.

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                 moduleName:@"ExampleProject"
                                          initialProperties:nil
                                              launchOptions:launchOptions];

EDIT 1: Ok I may have another problem. It does not work on javascript reload, so only the first time the app run. It also does not work at all when remote JS debugging is enabled. Strange...