Skip to content

Commit fc1c0f2

Browse files
vonovakWoLewicki
andauthored
feat: new architecture support (#649)
* feat: rn 70 ios builds with new arch * feat: android migration wip * fix: update test-app, react-native and react version, fix codegen config * fix: change spec for backward compat * fix: simplify android code and make it work * fix: ios code * fix: remove unnecessary folly version * fix: srcDirs on paper * refactor: review * refactor: review * refactor: node 18 * docs: new arch in readme * docs: new arch in readme * refactor: use Spec --------- Co-authored-by: Wojciech Lewicki <wojciech.lewicki@swmansion.com>
1 parent 301c551 commit fc1c0f2

21 files changed

Lines changed: 3404 additions & 2583 deletions

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
strategy:
2020
matrix:
21-
node-version: [15.x]
21+
node-version: [18.x]
2222

2323
steps:
2424
- uses: actions/checkout@v2

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ A React Native wrapper for:
1818
</tr>
1919
</table>
2020

21-
Requires RN >= 0.63, Android 5.0+ and iOS 11+
21+
Requires RN >= 0.69, Android 5.0+ and iOS 11+
22+
23+
New architecture is supported.
2224

2325
# Table of Contents
2426

android/build.gradle

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
11
buildscript {
2-
if (project == rootProject) {
3-
repositories {
4-
google()
5-
mavenCentral()
6-
}
7-
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.3'
10-
}
2+
repositories {
3+
google()
4+
mavenCentral()
115
}
126
}
137

14-
apply plugin: 'com.android.library'
8+
def getExtOrIntegerDefault(name) {
9+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeDocumentPicker_' + name]).toInteger()
10+
}
1511

16-
def safeExtGet(prop, fallback) {
17-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
12+
def isNewArchitectureEnabled() {
13+
// To opt-in for the New Architecture, you can either:
14+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
15+
// - Invoke gradle with `-newArchEnabled=true`
16+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
17+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
1818
}
1919

20+
apply plugin: 'com.android.library'
21+
if (isNewArchitectureEnabled()) {
22+
apply plugin: "com.facebook.react"
23+
}
24+
25+
2026
android {
21-
compileSdkVersion safeExtGet('compileSdkVersion', 29)
22-
buildToolsVersion safeExtGet('buildToolsVersion', '29.0.2')
27+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
28+
29+
// Used to override the NDK path/version on internal CI or by allowing
30+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
31+
if (rootProject.hasProperty("ndkPath")) {
32+
ndkPath rootProject.ext.ndkPath
33+
}
34+
if (rootProject.hasProperty("ndkVersion")) {
35+
ndkVersion rootProject.ext.ndkVersion
36+
}
37+
2338
defaultConfig {
24-
minSdkVersion safeExtGet('minSdkVersion', 21)
25-
targetSdkVersion safeExtGet('targetSdkVersion', 29)
26-
versionCode 1
27-
versionName "1.0"
39+
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
40+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
41+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
2842
}
2943

30-
buildTypes {
31-
release {
32-
minifyEnabled false
44+
sourceSets.main {
45+
java {
46+
if (!isNewArchitectureEnabled()) {
47+
srcDirs += 'src/paper/java'
48+
}
3349
}
3450
}
35-
lintOptions {
36-
disable 'GradleCompatible'
37-
}
38-
compileOptions {
39-
sourceCompatibility JavaVersion.VERSION_1_8
40-
targetCompatibility JavaVersion.VERSION_1_8
41-
}
4251
}
4352

4453
repositories {
45-
mavenLocal()
46-
maven {
47-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
48-
url("$rootDir/../node_modules/react-native/android")
49-
}
5054
google()
55+
mavenLocal()
56+
mavenCentral()
5157
}
5258

5359
dependencies {
5460
//noinspection GradleDynamicVersion
55-
implementation "com.facebook.react:react-native:+" // From node_modules
61+
implementation 'com.facebook.react:react-native:+' // from node_modules
5662
}

android/src/main/java/com/reactnativedocumentpicker/DocumentPickerPackage.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

android/src/main/java/com/reactnativedocumentpicker/DocumentPickerModule.java renamed to android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import com.facebook.react.bridge.Promise;
2323
import com.facebook.react.bridge.ReactApplicationContext;
2424
import com.facebook.react.bridge.ReactContext;
25-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
2625
import com.facebook.react.bridge.ReactMethod;
2726
import com.facebook.react.bridge.ReadableArray;
2827
import com.facebook.react.bridge.ReadableMap;
2928
import com.facebook.react.bridge.WritableArray;
3029
import com.facebook.react.bridge.WritableMap;
31-
import com.facebook.react.module.annotations.ReactModule;
3230

3331
import java.io.File;
3432
import java.io.FileOutputStream;
@@ -39,8 +37,7 @@
3937
import java.util.List;
4038
import java.util.UUID;
4139

42-
@ReactModule(name = DocumentPickerModule.NAME)
43-
public class DocumentPickerModule extends ReactContextBaseJavaModule {
40+
public class RNDocumentPickerModule extends NativeDocumentPickerSpec {
4441
public static final String NAME = "RNDocumentPicker";
4542
private static final int READ_REQUEST_CODE = 41;
4643
private static final int PICK_DIR_REQUEST_CODE = 42;
@@ -64,6 +61,14 @@ public class DocumentPickerModule extends ReactContextBaseJavaModule {
6461
private static final String FIELD_TYPE = "type";
6562
private static final String FIELD_SIZE = "size";
6663

64+
private Promise promise;
65+
private String copyTo;
66+
67+
public RNDocumentPickerModule(ReactApplicationContext reactContext) {
68+
super(reactContext);
69+
reactContext.addActivityEventListener(activityEventListener);
70+
}
71+
6772
private final ActivityEventListener activityEventListener = new BaseActivityEventListener() {
6873
@Override
6974
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
@@ -89,14 +94,6 @@ private String[] readableArrayToStringArray(ReadableArray readableArray) {
8994
return array;
9095
}
9196

92-
private Promise promise;
93-
private String copyTo;
94-
95-
public DocumentPickerModule(ReactApplicationContext reactContext) {
96-
super(reactContext);
97-
reactContext.addActivityEventListener(activityEventListener);
98-
}
99-
10097
@Override
10198
public void onCatalystInstanceDestroy() {
10299
super.onCatalystInstanceDestroy();
@@ -167,6 +164,11 @@ public void pickDirectory(Promise promise) {
167164
}
168165
}
169166

167+
@Override
168+
public void releaseSecureAccess(ReadableArray uris, Promise promise) {
169+
promise.reject("RNDocumentPicker:releaseSecureAccess", "releaseSecureAccess is not supported on Android");
170+
}
171+
170172
private void onPickDirectoryResult(int resultCode, Intent data) {
171173
if (resultCode == Activity.RESULT_CANCELED) {
172174
sendError(E_DOCUMENT_PICKER_CANCELED, "User canceled directory picker");
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.reactnativedocumentpicker;
2+
3+
import androidx.annotation.Nullable;
4+
5+
import com.facebook.react.TurboReactPackage;
6+
import com.facebook.react.bridge.NativeModule;
7+
import com.facebook.react.bridge.ReactApplicationContext;
8+
import com.facebook.react.module.model.ReactModuleInfo;
9+
import com.facebook.react.module.model.ReactModuleInfoProvider;
10+
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
public class RNDocumentPickerPackage extends TurboReactPackage {
15+
16+
@Nullable
17+
@Override
18+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
19+
if (name.equals(RNDocumentPickerModule.NAME)) {
20+
return new RNDocumentPickerModule(reactContext);
21+
} else {
22+
return null;
23+
}
24+
}
25+
26+
@Override
27+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
28+
return () -> {
29+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
30+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
31+
moduleInfos.put(
32+
RNDocumentPickerModule.NAME,
33+
new ReactModuleInfo(
34+
RNDocumentPickerModule.NAME,
35+
RNDocumentPickerModule.NAME,
36+
// "DocumentPickerModule",
37+
false, // canOverrideExistingModule
38+
false, // needsEagerInit
39+
true, // hasConstants
40+
false, // isCxxModule
41+
isTurboModule // isTurboModule
42+
));
43+
return moduleInfos;
44+
};
45+
}
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
/**
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4+
*
5+
* Then it was commited. It is here to support the old architecture.
6+
* If you use the new architecture, this file won't be included and instead will be generated by the codegen.
7+
*
8+
* @generated by codegen project: GenerateModuleJavaSpec.js
9+
*
10+
* @nolint
11+
*/
12+
13+
package com.reactnativedocumentpicker;
14+
15+
import com.facebook.proguard.annotations.DoNotStrip;
16+
import com.facebook.react.bridge.Promise;
17+
import com.facebook.react.bridge.ReactApplicationContext;
18+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
19+
import com.facebook.react.bridge.ReactMethod;
20+
import com.facebook.react.bridge.ReactModuleWithSpec;
21+
import com.facebook.react.bridge.ReadableArray;
22+
import com.facebook.react.bridge.ReadableMap;
23+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
24+
25+
public abstract class NativeDocumentPickerSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
26+
public NativeDocumentPickerSpec(ReactApplicationContext reactContext) {
27+
super(reactContext);
28+
}
29+
30+
@ReactMethod
31+
@DoNotStrip
32+
public abstract void pick(ReadableMap options, Promise promise);
33+
34+
@ReactMethod
35+
@DoNotStrip
36+
public abstract void releaseSecureAccess(ReadableArray uris, Promise promise);
37+
38+
@ReactMethod
39+
@DoNotStrip
40+
public abstract void pickDirectory(Promise promise);
41+
}

example/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const styles = StyleSheet.create({
9999
flex: 1,
100100
alignItems: 'center',
101101
justifyContent: 'center',
102+
backgroundColor: 'white',
102103
},
103104
box: {
104105
width: 60,

example/android/build.gradle

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
buildscript {
2-
def androidTestAppDir = "../../node_modules/react-native-test-app/android"
3-
apply(from: "${androidTestAppDir}/dependencies.gradle")
2+
def androidTestAppDir = "../../node_modules/react-native-test-app/android"
3+
apply(from: "${androidTestAppDir}/dependencies.gradle")
44

5-
repositories {
6-
mavenCentral()
7-
google()
8-
}
5+
repositories {
6+
mavenCentral()
7+
google()
8+
}
99

10-
dependencies {
11-
classpath "com.android.tools.build:gradle:$androidPluginVersion"
12-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
10+
dependencies {
11+
getReactNativeDependencies().each { dependency ->
12+
classpath(dependency)
1313
}
14+
}
1415
}
1516

1617
allprojects {
17-
repositories {
18-
maven {
19-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
20-
url("${rootDir}/../../node_modules/react-native/android")
21-
}
22-
mavenCentral()
23-
google()
18+
repositories {
19+
maven {
20+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
21+
url("${rootDir}/../../node_modules/react-native/android")
2422
}
23+
mavenCentral()
24+
google()
25+
}
2526
}

example/android/gradle.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ android.enableJetifier=true
3030
# Version of Flipper to use with React Native. Default value is whatever React
3131
# Native defaults to. To disable Flipper, set it to `false`.
3232
#FLIPPER_VERSION=0.125.0
33+
FLIPPER_VERSION=false
3334

3435
# Enable Fabric at runtime.
3536
#USE_FABRIC=1
3637

38+
# Enable new architecture, i.e. Fabric + TurboModule - implies USE_FABRIC=1.
39+
# Note that this is incompatible with web debugging.
40+
newArchEnabled=false
41+
3742
# Uncomment the line below if building react-native from source
3843
#ANDROID_NDK_VERSION=21.4.7075529
44+
45+
# Version of Kotlin to build against.
46+
#KOTLIN_VERSION=1.7.10

0 commit comments

Comments
 (0)