GoldenJS can be installed easily through npm
npm install --save react-native-goldenjs
Create new React Native project:
react-native init MyProject
Install rn-nodeify to be able to use NodeJS libs:
sudo npm i rn-nodeify -g
Add this postinstall script
to isntall and hack NodeJS libs for the usage in React Native:
"postinstall": "rn-nodeify --install stream,buffer,events,assert,crypto,vm --hack",
Then install GoldenJS lib:
npm i --save react-native-goldenjs
Run postinstall script
, it will be create a shim.js file with you need import to your index file (check Usage to more infomation):
npm run postinstall
After that, here are few steps to link react-native-randombytes
to your project manually:
-
Drag RNRandomBytes.xcodeproj from node_modules/react-native-randombytes into your XCode project.
-
Click on the project in XCode, go to Build Phases, then Link Binary With Libraries and add
libRNRandomBytes.a
- Update Gradle Settings
// file: android/settings.gradle
...
include ':randombytes', ':app'
project(':randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android')
- Update Gradle Build
// file: android/app/build.gradle
...
dependencies {
...
compile project(':randombytes')
}
- Register React Package
...
import com.bitgo.randombytes.RandomBytesPackage // import
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
private ReactInstanceManager mReactInstanceManager;
private ReactRootView mReactRootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new RandomBytesPackage()) // register package here
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);
setContentView(mReactRootView);
}
...
Now you can run your app:
react-native run-ios
or
react-native run-android
Make sure that you're using ES6 to use import
(nor require()
)
import './shim'
You can create an instance of the object manager by importing GoldenJS
import GoldenJS from 'react-native-goldenjs'
MIT License
Copyright (C) 2018 Skylab Technology Cooperation