File tree Expand file tree Collapse file tree 6 files changed +55
-45
lines changed Expand file tree Collapse file tree 6 files changed +55
-45
lines changed Original file line number Diff line number Diff line change 1
1
buildscript {
2
- // The Android Gradle plugin is only required when opening the android folder stand-alone.
3
- // This avoids unnecessary downloads and potential conflicts when the library is included as a
4
- // module dependency in an application project.
5
2
if (project == rootProject) {
6
3
repositories {
7
4
mavenCentral()
8
5
google()
9
6
}
7
+
10
8
def buildGradleVersion = ext. has(' buildGradlePluginVersion' ) ? ext. get(' buildGradlePluginVersion' ) : ' 4.2.2'
11
9
12
10
dependencies {
@@ -23,28 +21,39 @@ def safeExtGet(prop, fallback) {
23
21
24
22
android {
25
23
compileSdkVersion safeExtGet(' compileSdkVersion' , 30 )
26
- buildToolsVersion safeExtGet(' buildToolsVersion' , ' 30.0.3' )
27
-
28
24
defaultConfig {
29
25
minSdkVersion safeExtGet(' minSdkVersion' , 16 )
30
26
targetSdkVersion safeExtGet(' targetSdkVersion' , 30 )
31
27
versionCode 1
32
28
versionName " 1.0"
29
+
30
+ }
31
+
32
+ buildTypes {
33
+ release {
34
+ minifyEnabled false
35
+ }
33
36
}
34
37
lintOptions {
35
- abortOnError false
38
+ disable ' GradleCompatible'
39
+ }
40
+ compileOptions {
41
+ sourceCompatibility JavaVersion . VERSION_1_8
42
+ targetCompatibility JavaVersion . VERSION_1_8
36
43
}
37
44
}
38
45
39
46
repositories {
40
- mavenCentral()
41
- google()
47
+ mavenLocal()
42
48
maven {
43
49
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
44
- url " $rootDir /../node_modules/react-native/android"
50
+ url( " $rootDir /../node_modules/react-native/android" )
45
51
}
52
+ google()
53
+ mavenCentral()
46
54
}
47
55
48
56
dependencies {
49
- implementation ' com.facebook.react:react-native:+'
57
+ // noinspection GradleDynamicVersion
58
+ implementation " com.facebook.react:react-native:+" // From node_modules
50
59
}
Original file line number Diff line number Diff line change 1
1
package org .linusu ;
2
2
3
- import java .security .NoSuchAlgorithmException ;
4
- import java .security .SecureRandom ;
5
-
6
3
import android .util .Base64 ;
7
4
5
+ import androidx .annotation .NonNull ;
6
+
8
7
import com .facebook .react .bridge .ReactApplicationContext ;
9
8
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
10
9
import com .facebook .react .bridge .ReactMethod ;
11
- import com .facebook .react .bridge .Callback ;
12
10
13
- public class RNGetRandomValuesModule extends ReactContextBaseJavaModule {
11
+ import java .security .NoSuchAlgorithmException ;
12
+ import java .security .SecureRandom ;
14
13
15
- private final ReactApplicationContext reactContext ;
14
+ public class RNGetRandomValuesModule extends ReactContextBaseJavaModule {
15
+ public static final String NAME = "RNGetRandomValues" ;
16
16
17
17
public RNGetRandomValuesModule (ReactApplicationContext reactContext ) {
18
18
super (reactContext );
19
- this .reactContext = reactContext ;
20
19
}
21
20
22
21
@ Override
22
+ @ NonNull
23
23
public String getName () {
24
- return "RNGetRandomValues" ;
24
+ return NAME ;
25
25
}
26
26
27
27
@ ReactMethod (isBlockingSynchronousMethod = true )
28
+ @ NonNull
28
29
public String getRandomBase64 (int byteLength ) throws NoSuchAlgorithmException {
29
30
byte [] data = new byte [byteLength ];
30
31
SecureRandom random = new SecureRandom ();
Original file line number Diff line number Diff line change 1
1
package org .linusu ;
2
2
3
- import java .util .Arrays ;
4
- import java .util .Collections ;
5
- import java .util .List ;
3
+ import androidx .annotation .NonNull ;
6
4
7
5
import com .facebook .react .ReactPackage ;
8
6
import com .facebook .react .bridge .NativeModule ;
9
7
import com .facebook .react .bridge .ReactApplicationContext ;
10
8
import com .facebook .react .uimanager .ViewManager ;
11
- import com .facebook .react .bridge .JavaScriptModule ;
12
9
13
- public class RNGetRandomValuesPackage implements ReactPackage {
14
- @ Override
15
- public List <NativeModule > createNativeModules (ReactApplicationContext reactContext ) {
16
- return Arrays .<NativeModule >asList (new RNGetRandomValuesModule (reactContext ));
17
- }
10
+ import java .util .ArrayList ;
11
+ import java .util .Collections ;
12
+ import java .util .List ;
18
13
19
- // Deprecated from RN 0.47
20
- public List <Class <? extends JavaScriptModule >> createJSModules () {
21
- return Collections .emptyList ();
22
- }
14
+ public class RNGetRandomValuesPackage implements ReactPackage {
15
+ @ NonNull
16
+ @ Override
17
+ public List <NativeModule > createNativeModules (@ NonNull ReactApplicationContext reactContext ) {
18
+ List <NativeModule > modules = new ArrayList <>();
19
+ modules .add (new RNGetRandomValuesModule (reactContext ));
20
+ return modules ;
21
+ }
23
22
24
- @ Override
25
- public List <ViewManager > createViewManagers (ReactApplicationContext reactContext ) {
26
- return Collections .emptyList ();
27
- }
23
+ @ NonNull
24
+ @ Override
25
+ public List <ViewManager > createViewManagers (@ NonNull ReactApplicationContext reactContext ) {
26
+ return Collections .emptyList ();
27
+ }
28
28
}
Original file line number Diff line number Diff line change 1
1
const base64Decode = require ( 'fast-base64-decode' )
2
- const { NativeModules } = require ( 'react-native' )
2
+ const { NativeModules, Platform } = require ( 'react-native' )
3
+
4
+ const LINKING_ERROR =
5
+ "The package 'react-native-get-random-values' doesn't seem to be linked. Make sure: \n\n" +
6
+ Platform . select ( { ios : "- You have run 'pod install'\n" , default : '' } ) +
7
+ '- You rebuilt the app after installing the package\n'
3
8
4
9
class TypeMismatchError extends Error { }
5
10
class QuotaExceededError extends Error { }
@@ -29,7 +34,7 @@ function getRandomBase64 (byteLength) {
29
34
} else if ( NativeModules . ExpoRandom ) {
30
35
return NativeModules . ExpoRandom . getRandomBase64String ( byteLength )
31
36
} else {
32
- throw new Error ( 'Native module not found' )
37
+ throw new Error ( LINKING_ERROR )
33
38
}
34
39
}
35
40
Original file line number Diff line number Diff line change 2
2
3
3
@implementation RNGetRandomValues
4
4
5
- - (dispatch_queue_t )methodQueue
6
- {
7
- return dispatch_get_main_queue ();
8
- }
9
5
RCT_EXPORT_MODULE ()
10
6
11
- RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD( NSString *, getRandomBase64:(NSUInteger )byteLength) {
7
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD( getRandomBase64:(NSUInteger )byteLength) {
12
8
NSMutableData *data = [NSMutableData dataWithLength: byteLength];
13
9
int result = SecRandomCopyBytes (kSecRandomDefault , byteLength, data.mutableBytes );
14
10
if (result != errSecSuccess) {
Original file line number Diff line number Diff line change @@ -6,15 +6,14 @@ Pod::Spec.new do |s|
6
6
s . name = "react-native-get-random-values"
7
7
s . version = package [ "version" ]
8
8
s . summary = "getRandomValues for React Native"
9
- s . description = "A small implementation of `getRandomValues` for React Native."
10
9
s . homepage = "https://github.com/LinusU/react-native-get-random-values"
11
10
s . license = "MIT"
12
11
s . authors = { "Linus Unnebäck" => "linus@folkdatorn.se" }
12
+
13
13
s . platforms = { :ios => "9.0" , :tvos => "9.0" , :osx => "10.14" }
14
14
s . source = { :git => "https://github.com/LinusU/react-native-get-random-values.git" , :tag => "v#{ s . version } " }
15
15
16
- s . source_files = "ios/**/*.{h,m,swift}"
17
- s . requires_arc = true
16
+ s . source_files = "ios/**/*.{h,m,mm}"
18
17
19
18
s . dependency "React-Core"
20
19
end
You can’t perform that action at this time.
0 commit comments