I'd like to import my module written natively (java, Android) into my React Native sources, in JS.
I have my dependencies loaded into: android/app/libs/dependencies.jar
I have created my module into android/app/src/main/java/com/rctcognito/:
Beside some source files, I have the module and the package.
The module is implementing the following class:
public class Cognito extends ReactContextBaseJavaModule
And here is the package class:
package com.rctcognito;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class RCTCognitoPackage implements ReactPackage {
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<NativeModule> createNativeModules( ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new Cognito(reactContext));
return modules;
}
}
I, then, updated MainApplication.java by adding the new package:
import com.rctcognito.RCTCognitoPackage;
And adding it in the List:
new RCTCognitoPackage(),
Considering to the official doc of React-Native, I should be able to load it like this:
import { NativeModules } from 'react-native';
module.exports = NativeModules.Cognito;
import Cognito from './Cognito';
But my app is not able to load ./Cognito. Would you have any idea what I might be doing wrong please?
Thanks a lot!