mirror of
https://github.com/status-im/react-native-randombytes.git
synced 2026-08-31 11:01:08 +00:00
moved android implementation from /app to /android, rnpm link did not find the android implementation from app -directory.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.bitgo.randombytes;
|
||||
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
class RandomBytesModule extends ReactContextBaseJavaModule {
|
||||
|
||||
public RandomBytesModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RNRandomBytes";
|
||||
}
|
||||
@ReactMethod
|
||||
public void randomBytes(int size, Callback success) {
|
||||
SecureRandom sr = new SecureRandom();
|
||||
byte[] output = new byte[size];
|
||||
sr.nextBytes(output);
|
||||
String string = Base64.encodeToString(output, Base64.DEFAULT);
|
||||
success.invoke(null, string);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.bitgo.randombytes;
|
||||
|
||||
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 RandomBytesPackage implements ReactPackage {
|
||||
|
||||
@Override
|
||||
public List<NativeModule> createNativeModules(
|
||||
ReactApplicationContext reactContext) {
|
||||
List<NativeModule> modules = new ArrayList<>();
|
||||
|
||||
modules.add(new RandomBytesModule(reactContext));
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user