Skip to content

Commit

Permalink
Compatibility with the old arch
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki committed Feb 7, 2023
1 parent 1a5587a commit 1a99729
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
47 changes: 46 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@ def getVersionOrDefault(String flagName, String defaultVersion) {
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] : defaultVersion
}

def resolveReactNativeDirectory() {
def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
if (reactNativeLocation != null) {
return file(reactNativeLocation)
}

// monorepo workaround
// react-native can be hoisted or in project's own node_modules
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

def reactNativeFromNodeModulesWithReanimated = file("${projectDir}/../../react-native")
if (reactNativeFromNodeModulesWithReanimated.exists()) {
return reactNativeFromNodeModulesWithReanimated
}

throw new Exception(
"[react-native-async-storage] Unable to resolve react-native location in " +
"node_modules. You should add project extension property (in app/build.gradle) " +
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
)
}

def getReactNativeMinorVersion() {
def REACT_NATIVE_DIR = resolveReactNativeDirectory()

def reactProperties = new Properties()
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }

def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()

return REACT_NATIVE_MINOR_VERSION
}

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
Expand Down Expand Up @@ -128,6 +165,10 @@ android {
} else {
srcDirs += 'src/javaPackage/java'
}

if (!isNewArchitectureEnabled()) {
srcDirs += 'src/paper/java'
}
}
}
}
Expand Down Expand Up @@ -174,5 +215,9 @@ dependencies {
}

//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
if (isNewArchitectureEnabled() && getReactNativeMinorVersion() < 71) {
implementation project(":ReactAndroid")
} else {
implementation 'com.facebook.react:react-native:+' // from node_modules
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package com.reactnativecommunity.asyncstorage;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;

public abstract class NativeAsyncStorageModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public NativeAsyncStorageModuleSpec(ReactApplicationContext reactContext) {
super(reactContext);
}

@ReactMethod
@DoNotStrip
public abstract void multiGet(ReadableArray keys, Callback callback);

@ReactMethod
@DoNotStrip
public abstract void multiSet(ReadableArray kvPairs, Callback callback);

@ReactMethod
@DoNotStrip
public abstract void multiRemove(ReadableArray keys, Callback callback);

@ReactMethod
@DoNotStrip
public abstract void multiMerge(ReadableArray kvPairs, Callback callback);

@ReactMethod
@DoNotStrip
public abstract void getAllKeys(Callback callback);

@ReactMethod
@DoNotStrip
public abstract void clear(Callback callback);
}

0 comments on commit 1a99729

Please sign in to comment.