I’ve a problem about expokit. After detached 2 different library I tried to link. But NativeModules always empty. Here is my first code;
package host.exp.exponent;
import com.facebook.react.ReactPackage;
import java.util.Arrays;
import java.util.List;
// Needed for `react-native link`
// import com.facebook.react.ReactApplication;
import com.wix.reactnativenotifications.RNNotificationsPackage;
import com.reactlibrary.RNIapPackage;
import com.facebook.react.shell.MainReactPackage;
public class MainApplication extends ExpoApplication {
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
// Needed for `react-native link`
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// Add your own packages here!
// TODO: add native modules!
// Needed for `react-native link`
//new MainReactPackage(),
new RNNotificationsPackage(MainApplication.this),
new RNIapPackage()
);
}
@Override
public String gcmSenderId() {
return getString(R.string.gcm_defaultSenderId);
}
@Override
public boolean shouldUseInternetKernel() {
return BuildVariantConstants.USE_INTERNET_KERNEL;
}
}
Then I tried like this;
package host.exp.exponent;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import java.util.Arrays;
import java.util.List;
// Needed for `react-native link`
import com.facebook.react.ReactApplication;
import com.wix.reactnativenotifications.RNNotificationsPackage;
import com.reactlibrary.RNIapPackage;
import com.facebook.react.shell.MainReactPackage;
public class MainApplication extends ExpoApplication implements ReactApplication {
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
// Needed for `react-native link`
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// Add your own packages here!
// TODO: add native modules!
// Needed for `react-native link`
new MainReactPackage(),
new RNNotificationsPackage(MainApplication.this),
new RNIapPackage()
);
}
@Override
public String gcmSenderId() {
return getString(R.string.gcm_defaultSenderId);
}
@Override
public boolean shouldUseInternetKernel() {
return BuildVariantConstants.USE_INTERNET_KERNEL;
}
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return MainApplication.this.getPackages();
}
};
}
Testing in js;
import React, { Component } from 'react';
import {
StyleSheet, View, Text, Button, NativeModules
} from 'react-native'
import { NavigationActions } from 'react-navigation'
import BaseComponent from '../base/BaseComponent'
console.log('NativeModules', NativeModules.RNIapModule, NativeModules.WixRNNotifications)
That prints
NativeModules undefined undefined
By the way I created a new project with ‘react-native init’. That works very well. What am I missing?
My package.json;
{
"name": "Test1",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.8.1",
"jest-expo": "24.0.0",
"react-test-renderer": "16.0.0"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^24.0.0",
"react": "16.0.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-24.0.0.tar.gz",
"react-native-easy-toast": "^1.0.9",
"react-native-iap": "^0.1.10",
"react-native-notifications": "^1.1.17",
"react-native-scrollable-tab-view": "^0.8.0",
"react-native-tab-navigator": "^0.3.4",
"react-navigation": "^1.0.0-beta.21"
}
}