Native code method returns undefined instead of string

Viewed 208

I have a simple test react-native project running where I want to run some native code. I followed the dev guide and I have a module and a package class in my android project and I linked it in MainApplication file. They look something like this:

Package:

public class ModulePackage implements ReactPackage {
    @NonNull
    @Override
    public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
        List<NativeModule> modules = new ArrayList<>();
        modules.add(new ModuleModule(reactContext));
        return modules;
    }

    @NonNull
    @Override
    public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
        return Collections.emptyList();
    }
}

And the Module:

@ReactModule(name = ModuleModule.NAME)
public class ModuleModule extends ReactContextBaseJavaModule {
    public static final String NAME = "ModuleModule";

    @ReactMethod
    public String getData() {
        return "AAAAAAAAAAAAAAAAA";
    }
}

Now I import the module as follows in javascript:

const { ModuleModule} = NativeModules;

And I've put a breakpoint on the line, after breaking and stepping over once so the Module is loaded in I went into the console to check if the function exists so I checked ModuleModule and it returned Object {getData: Function, getConstants: Function} So the function is clearly there, I just never get my expected return value. Anyone ever encountered something like this before?

1 Answers
Related