Skip to content

Commit d3128c3

Browse files
author
Krzysztof Borowy
committed
initial
1 parent 8780569 commit d3128c3

File tree

5 files changed

+59
-15
lines changed

5 files changed

+59
-15
lines changed

android/build.gradle

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,30 @@ def safeExtGet(prop, fallback) {
2121
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
2222
}
2323

24+
def getFlagOrDefault(flagName, defaultValue) {
25+
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] == "true" : defaultValue
26+
}
27+
2428
configurations {
2529
compileClasspath
2630
}
2731

2832
buildscript {
29-
if (project == rootProject) {
30-
repositories {
31-
google()
32-
jcenter()
33-
}
34-
dependencies {
33+
// kotlin version is dictated by rootProject extension or property in gradle.properties
34+
ext.asyncStorageKtVersion = rootProject.ext.has('kotlinVersion')
35+
? rootProject.ext['kotlinVersion']
36+
: rootProject.hasProperty('AsyncStorage_kotlinVersion')
37+
? rootProject.properties['AsyncStorage_kotlinVersion']
38+
: '1.4.21'
39+
40+
repositories {
41+
google()
42+
jcenter()
43+
}
44+
dependencies {
45+
if (project == rootProject) {
3546
classpath 'com.android.tools.build:gradle:3.6.4'
47+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$asyncStorageKtVersion"
3648
}
3749
}
3850
}
@@ -42,27 +54,33 @@ buildscript {
4254
// This also protects the database from filling up the disk cache and becoming malformed.
4355
// If you really need bigger size, please keep in mind the potential consequences.
4456
long dbSizeInMB = 6L
45-
4657
def newDbSize = rootProject.properties['AsyncStorage_db_size_in_MB']
47-
4858
if( newDbSize != null && newDbSize.isLong()) {
4959
dbSizeInMB = newDbSize.toLong()
5060
}
5161

52-
def useDedicatedExecutor = rootProject.hasProperty('AsyncStorage_dedicatedExecutor')
53-
? rootProject.properties['AsyncStorage_dedicatedExecutor']
54-
: false
62+
// Instead of reusing AsyncTask thread pool, AsyncStorage can use its own executor
63+
def useDedicatedExecutor = getFlagOrDefault('AsyncStorage_dedicatedExecutor', false)
5564

5665
apply plugin: 'com.android.library'
5766

67+
// todo: decide the name
68+
def useRoomImplementation = getFlagOrDefault("AsyncStorage_useRoomLibrary", false)
69+
70+
if(useRoomImplementation) {
71+
apply plugin: 'kotlin-android'
72+
apply plugin: 'kotlin-kapt'
73+
}
74+
5875
android {
5976
compileSdkVersion safeExtGet('compileSdkVersion', 28)
6077
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
6178
defaultConfig {
6279
minSdkVersion safeExtGet('minSdkVersion', 19)
6380
targetSdkVersion safeExtGet('targetSdkVersion', 28)
6481
buildConfigField "Long", "AsyncStorage_db_size", "${dbSizeInMB}L"
65-
buildConfigField("boolean", "AsyncStorage_useDedicatedExecutor", "${useDedicatedExecutor}")
82+
buildConfigField "boolean", "AsyncStorage_useDedicatedExecutor", "${useDedicatedExecutor}"
83+
buildConfigField "boolean", "AsyncStorage_useRoomLibrary", "${useRoomImplementation}"
6684
}
6785
lintOptions {
6886
abortOnError false

android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@
1212
import com.facebook.react.bridge.NativeModule;
1313
import com.facebook.react.bridge.ReactApplicationContext;
1414
import com.facebook.react.uimanager.ViewManager;
15-
16-
import java.util.Arrays;
15+
import com.reactnativecommunity.asyncstorage.next.StorageModule;
16+
import java.util.ArrayList;
1717
import java.util.Collections;
1818
import java.util.List;
1919

2020
public class AsyncStoragePackage implements ReactPackage {
2121
@Override
2222
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
23-
return Arrays.<NativeModule>asList(new AsyncStorageModule(reactContext));
23+
24+
List<NativeModule> moduleList = new ArrayList<>(1);
25+
26+
if(BuildConfig.AsyncStorage_useRoomLibrary) {
27+
moduleList.add(new StorageModule(reactContext));
28+
} else {
29+
moduleList.add(new AsyncStorageModule(reactContext));
30+
}
31+
32+
return moduleList;
2433
}
2534

2635
// Deprecated in RN 0.47
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.reactnativecommunity.asyncstorage.next
2+
3+
import com.facebook.react.bridge.ReactContext
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule
5+
6+
class StorageModule(private val reactContext: ReactContext) : ReactContextBaseJavaModule() {
7+
override fun getName() = "RNC_AsyncSQLiteDBStorage"
8+
}

example/android/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,21 @@ task fetchDependencies() {
2626
}
2727

2828
buildscript {
29+
/**
30+
* Todo:
31+
* In order to use this feature, the end user will have to also include
32+
* Kotlin plugin. Add this info to docs.
33+
*/
34+
ext.kotlinVersion = '1.4.21'
35+
2936
repositories {
3037
google()
3138
jcenter()
3239
}
3340
dependencies {
3441
// Needs to match `react-native-test-app/android/app/build.gradle`
3542
classpath "com.android.tools.build:gradle:4.0.2"
43+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
3644
}
3745
}
3846

example/android/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
# Enable dedicated thread pool executor
2424
AsyncStorage_dedicatedExecutor=true
25+
AsyncStorage_useRoomLibrary=true
2526

2627
android.useAndroidX=true
2728
android.enableJetifier=true

0 commit comments

Comments
 (0)