Skip to content

Commit 76d067d

Browse files
committed
🎉 Update boilerplate to match newer React Native
1 parent 455f9db commit 76d067d

File tree

6 files changed

+55
-45
lines changed

6 files changed

+55
-45
lines changed

android/build.gradle

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
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.
52
if (project == rootProject) {
63
repositories {
74
mavenCentral()
85
google()
96
}
7+
108
def buildGradleVersion = ext.has('buildGradlePluginVersion') ? ext.get('buildGradlePluginVersion') : '4.2.2'
119

1210
dependencies {
@@ -23,28 +21,39 @@ def safeExtGet(prop, fallback) {
2321

2422
android {
2523
compileSdkVersion safeExtGet('compileSdkVersion', 30)
26-
buildToolsVersion safeExtGet('buildToolsVersion', '30.0.3')
27-
2824
defaultConfig {
2925
minSdkVersion safeExtGet('minSdkVersion', 16)
3026
targetSdkVersion safeExtGet('targetSdkVersion', 30)
3127
versionCode 1
3228
versionName "1.0"
29+
30+
}
31+
32+
buildTypes {
33+
release {
34+
minifyEnabled false
35+
}
3336
}
3437
lintOptions {
35-
abortOnError false
38+
disable 'GradleCompatible'
39+
}
40+
compileOptions {
41+
sourceCompatibility JavaVersion.VERSION_1_8
42+
targetCompatibility JavaVersion.VERSION_1_8
3643
}
3744
}
3845

3946
repositories {
40-
mavenCentral()
41-
google()
47+
mavenLocal()
4248
maven {
4349
// 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")
4551
}
52+
google()
53+
mavenCentral()
4654
}
4755

4856
dependencies {
49-
implementation 'com.facebook.react:react-native:+'
57+
//noinspection GradleDynamicVersion
58+
implementation "com.facebook.react:react-native:+" // From node_modules
5059
}

android/src/main/java/org/linusu/RNGetRandomValuesModule.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
package org.linusu;
22

3-
import java.security.NoSuchAlgorithmException;
4-
import java.security.SecureRandom;
5-
63
import android.util.Base64;
74

5+
import androidx.annotation.NonNull;
6+
87
import com.facebook.react.bridge.ReactApplicationContext;
98
import com.facebook.react.bridge.ReactContextBaseJavaModule;
109
import com.facebook.react.bridge.ReactMethod;
11-
import com.facebook.react.bridge.Callback;
1210

13-
public class RNGetRandomValuesModule extends ReactContextBaseJavaModule {
11+
import java.security.NoSuchAlgorithmException;
12+
import java.security.SecureRandom;
1413

15-
private final ReactApplicationContext reactContext;
14+
public class RNGetRandomValuesModule extends ReactContextBaseJavaModule {
15+
public static final String NAME = "RNGetRandomValues";
1616

1717
public RNGetRandomValuesModule(ReactApplicationContext reactContext) {
1818
super(reactContext);
19-
this.reactContext = reactContext;
2019
}
2120

2221
@Override
22+
@NonNull
2323
public String getName() {
24-
return "RNGetRandomValues";
24+
return NAME;
2525
}
2626

2727
@ReactMethod(isBlockingSynchronousMethod = true)
28+
@NonNull
2829
public String getRandomBase64(int byteLength) throws NoSuchAlgorithmException {
2930
byte[] data = new byte[byteLength];
3031
SecureRandom random = new SecureRandom();
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
package org.linusu;
22

3-
import java.util.Arrays;
4-
import java.util.Collections;
5-
import java.util.List;
3+
import androidx.annotation.NonNull;
64

75
import com.facebook.react.ReactPackage;
86
import com.facebook.react.bridge.NativeModule;
97
import com.facebook.react.bridge.ReactApplicationContext;
108
import com.facebook.react.uimanager.ViewManager;
11-
import com.facebook.react.bridge.JavaScriptModule;
129

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;
1813

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+
}
2322

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+
}
2828
}

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
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'
38

49
class TypeMismatchError extends Error {}
510
class QuotaExceededError extends Error {}
@@ -29,7 +34,7 @@ function getRandomBase64 (byteLength) {
2934
} else if (NativeModules.ExpoRandom) {
3035
return NativeModules.ExpoRandom.getRandomBase64String(byteLength)
3136
} else {
32-
throw new Error('Native module not found')
37+
throw new Error(LINKING_ERROR)
3338
}
3439
}
3540

ios/RNGetRandomValues.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
@implementation RNGetRandomValues
44

5-
- (dispatch_queue_t)methodQueue
6-
{
7-
return dispatch_get_main_queue();
8-
}
95
RCT_EXPORT_MODULE()
106

11-
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString*, getRandomBase64:(NSUInteger)byteLength) {
7+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getRandomBase64:(NSUInteger)byteLength) {
128
NSMutableData *data = [NSMutableData dataWithLength:byteLength];
139
int result = SecRandomCopyBytes(kSecRandomDefault, byteLength, data.mutableBytes);
1410
if (result != errSecSuccess) {

react-native-get-random-values.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ Pod::Spec.new do |s|
66
s.name = "react-native-get-random-values"
77
s.version = package["version"]
88
s.summary = "getRandomValues for React Native"
9-
s.description = "A small implementation of `getRandomValues` for React Native."
109
s.homepage = "https://github.com/LinusU/react-native-get-random-values"
1110
s.license = "MIT"
1211
s.authors = { "Linus Unnebäck" => "linus@folkdatorn.se" }
12+
1313
s.platforms = { :ios => "9.0", :tvos => "9.0", :osx => "10.14" }
1414
s.source = { :git => "https://github.com/LinusU/react-native-get-random-values.git", :tag => "v#{s.version}" }
1515

16-
s.source_files = "ios/**/*.{h,m,swift}"
17-
s.requires_arc = true
16+
s.source_files = "ios/**/*.{h,m,mm}"
1817

1918
s.dependency "React-Core"
2019
end

0 commit comments

Comments
 (0)