Skip to content

Commit

Permalink
feat: migrate to new rn architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
edeckers committed Apr 30, 2022
1 parent 227c1f4 commit 6a56a0c
Show file tree
Hide file tree
Showing 15 changed files with 3,020 additions and 110 deletions.
16 changes: 16 additions & 0 deletions example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
root: true,
extends: '@react-native-community',
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/no-shadow': ['error'],
'no-shadow': 'off',
'no-undef': 'off',
},
},
],
};
4 changes: 2 additions & 2 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GEM
specs:
CFPropertyList (3.0.5)
rexml
activesupport (6.1.5.1)
activesupport (6.1.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -97,4 +97,4 @@ RUBY VERSION
ruby 2.7.4p191

BUNDLED WITH
2.1.4
2.2.27
31 changes: 14 additions & 17 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import org.apache.tools.ant.taskdefs.condition.Os
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* // the entry file for bundle generation. If none specified and
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
* // default. Can be overridden with ENTRY_FILE environment variable.
* entryFile: "index.android.js",
*
* // https://reactnative.dev/docs/performance#enable-the-ram-format
Expand All @@ -38,7 +40,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for BlobCourierExample: to disable dev mode in the staging build type (if configured)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
Expand All @@ -65,7 +67,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for BlobCourierExample, you might want to remove it from here.
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
Expand All @@ -78,7 +80,6 @@ import org.apache.tools.ant.taskdefs.condition.Os

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
bundleInRelease: true, // whether to bundle JS and assets in release mode
]

apply from: "../../node_modules/react-native/react.gradle"
Expand All @@ -101,7 +102,7 @@ def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For BlobCourierExample, to use the international variant, you can use:
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
Expand Down Expand Up @@ -133,11 +134,6 @@ android {

compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

defaultConfig {
applicationId "io.deckers.blob_courier_example"
minSdkVersion rootProject.ext.minSdkVersion
Expand Down Expand Up @@ -220,8 +216,8 @@ android {
}

lintOptions {
abortOnError true
checkReleaseBuilds true
abortOnError true
checkReleaseBuilds true
}

splits {
Expand Down Expand Up @@ -252,11 +248,13 @@ android {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
Expand All @@ -268,24 +266,23 @@ android {
}
}

dependencyLocking {
lockAllConfigurations()
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.ReactInstanceManager;
import com.facebook.soloader.SoLoader;
import io.deckers.blob_courier_example.newarchitecture.MainApplicationReactNativeHost;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import io.deckers.blob_courier.BlobCourierPackage;
// import io.deckers.blob_courier.BlobCourierPackage;

public class MainApplication extends Application implements ReactApplication {

Expand All @@ -28,10 +28,9 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for BlobCourierExample:
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new BlobCourierPackage());

// packages.add(new BlobCourierPackage());
return packages;
}

Expand Down Expand Up @@ -59,15 +58,18 @@ public void onCreate() {
// If you opted-in for the New Architecture, we enable the TurboModule system
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}

/**
* Loads Flipper in React Native templates.
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
private static void initializeFlipper(
Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.facebook.react.fabric.EmptyReactNativeConfig;
import com.facebook.react.fabric.FabricJSIModuleProvider;
import com.facebook.react.uimanager.ViewManagerRegistry;
import io.deckers.blob_courier.BuildConfig;
import io.deckers.blob_courier.newarchitecture.components.MainComponentsRegistry;
import io.deckers.blob_courier.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
import io.deckers.blob_courier_example.BuildConfig;
import io.deckers.blob_courier_example.newarchitecture.components.MainComponentsRegistry;
import io.deckers.blob_courier_example.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.deckers.blob_courier.newarchitecture.components;
package io.deckers.blob_courier_example.newarchitecture.components;

import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.deckers.blob_courier.newarchitecture.modules;
package io.deckers.blob_courier_example.newarchitecture.modules;

import com.facebook.jni.HybridData;
import com.facebook.react.ReactPackage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MainApplicationTurboModuleManagerDelegate
public:
// Adapt it to the package you used for your Java class.
static constexpr auto kJavaDescriptor =
"Lcom/blob_courier_example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;";
"Lio/deckers/blob_courier_example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;";

static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>);

Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/main/jni/MainComponentsRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MainComponentsRegistry
public:
// Adapt it to the package you used for your Java class.
constexpr static auto kJavaDescriptor =
"Lcom/blob_courier_example/newarchitecture/components/MainComponentsRegistry;";
"Lio/deckers/blob_courier_example/newarchitecture/components/MainComponentsRegistry;";

static void registerNatives();

Expand Down
1 change: 0 additions & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ buildscript {
classpath("com.android.tools.build:gradle:7.0.4")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:4.1.2")

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
12 changes: 6 additions & 6 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.125.0

# Use this property to specify which architecture you want to build.
Expand All @@ -37,4 +37,4 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false
newArchEnabled=true
7 changes: 4 additions & 3 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ rootProject.name = 'BlobCourierExample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/react-native-gradle-plugin')

include ':blob_courier'
project(':blob_courier').projectDir = new File(rootProject.projectDir, '../../android')

if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
include(":ReactAndroid")
project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid')
}

include ':blob_courier'
project(':blob_courier').projectDir = new File(rootProject.projectDir, '../../android')
37 changes: 32 additions & 5 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,44 @@
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start"
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@babel/runtime": "^7.13.10",
"react": "17.0.2",
"react-native": "0.68.1",
"react-native-progress": "^4.1.2"
},
"devDependencies": {
"@babel/core": "^7.13.10",
"babel-plugin-module-resolver": "^4.0.0",
"metro-react-native-babel-preset": "^0.67.0"
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"@types/jest": "^26.0.23",
"@types/react-native": "^0.67.3",
"@types/react-test-renderer": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"babel-jest": "^26.6.3",
"babel-plugin-module-resolver": "^4.1.0",
"eslint": "^7.32.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.67.0",
"react-test-renderer": "17.0.2",
"typescript": "^4.4.4"
},
"resolutions": {
"@types/react": "^17"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}
Loading

0 comments on commit 6a56a0c

Please sign in to comment.