@onekeyfe/react-native-async-storage 1.1.55 → 1.1.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AsyncStorage_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AsyncStorage_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.asyncstorage"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lintOptions {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
package com.asyncstorage
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.SharedPreferences
|
|
5
|
+
import com.facebook.react.bridge.Promise
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.ReadableArray
|
|
8
|
+
import com.facebook.react.bridge.WritableNativeArray
|
|
9
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
10
|
+
|
|
11
|
+
@ReactModule(name = RNCAsyncStorageModule.NAME)
|
|
12
|
+
class RNCAsyncStorageModule(reactContext: ReactApplicationContext) :
|
|
13
|
+
NativeRNCAsyncStorageSpec(reactContext) {
|
|
14
|
+
|
|
15
|
+
companion object {
|
|
16
|
+
const val NAME = "RNCAsyncStorage"
|
|
17
|
+
private const val PREFS_NAME = "RNCAsyncStorage"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private fun getPrefs(): SharedPreferences {
|
|
21
|
+
return reactApplicationContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun getName(): String = NAME
|
|
25
|
+
|
|
26
|
+
override fun multiGet(keys: ReadableArray, promise: Promise) {
|
|
27
|
+
Thread {
|
|
28
|
+
try {
|
|
29
|
+
val prefs = getPrefs()
|
|
30
|
+
val result = WritableNativeArray()
|
|
31
|
+
for (i in 0 until keys.size()) {
|
|
32
|
+
val key = keys.getString(i)
|
|
33
|
+
val pair = WritableNativeArray()
|
|
34
|
+
pair.pushString(key)
|
|
35
|
+
if (prefs.contains(key)) {
|
|
36
|
+
pair.pushString(prefs.getString(key, null))
|
|
37
|
+
} else {
|
|
38
|
+
pair.pushNull()
|
|
39
|
+
}
|
|
40
|
+
result.pushArray(pair)
|
|
41
|
+
}
|
|
42
|
+
promise.resolve(result)
|
|
43
|
+
} catch (e: Exception) {
|
|
44
|
+
promise.reject("ASYNC_STORAGE_ERROR", e.message, e)
|
|
45
|
+
}
|
|
46
|
+
}.start()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override fun multiSet(keyValuePairs: ReadableArray, promise: Promise) {
|
|
50
|
+
Thread {
|
|
51
|
+
try {
|
|
52
|
+
val editor = getPrefs().edit()
|
|
53
|
+
for (i in 0 until keyValuePairs.size()) {
|
|
54
|
+
val pair = keyValuePairs.getArray(i)
|
|
55
|
+
if (pair != null && pair.size() >= 2) {
|
|
56
|
+
val key = pair.getString(0)
|
|
57
|
+
val value = pair.getString(1)
|
|
58
|
+
editor.putString(key, value)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
editor.apply()
|
|
62
|
+
promise.resolve(null)
|
|
63
|
+
} catch (e: Exception) {
|
|
64
|
+
promise.reject("ASYNC_STORAGE_ERROR", e.message, e)
|
|
65
|
+
}
|
|
66
|
+
}.start()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override fun multiRemove(keys: ReadableArray, promise: Promise) {
|
|
70
|
+
Thread {
|
|
71
|
+
try {
|
|
72
|
+
val editor = getPrefs().edit()
|
|
73
|
+
for (i in 0 until keys.size()) {
|
|
74
|
+
editor.remove(keys.getString(i))
|
|
75
|
+
}
|
|
76
|
+
editor.apply()
|
|
77
|
+
promise.resolve(null)
|
|
78
|
+
} catch (e: Exception) {
|
|
79
|
+
promise.reject("ASYNC_STORAGE_ERROR", e.message, e)
|
|
80
|
+
}
|
|
81
|
+
}.start()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override fun multiMerge(keyValuePairs: ReadableArray, promise: Promise) {
|
|
85
|
+
Thread {
|
|
86
|
+
try {
|
|
87
|
+
val prefs = getPrefs()
|
|
88
|
+
val editor = prefs.edit()
|
|
89
|
+
for (i in 0 until keyValuePairs.size()) {
|
|
90
|
+
val pair = keyValuePairs.getArray(i)
|
|
91
|
+
if (pair != null && pair.size() >= 2) {
|
|
92
|
+
val key = pair.getString(0)
|
|
93
|
+
val value = pair.getString(1)
|
|
94
|
+
// For merge, if key exists and both are JSON objects, deep merge.
|
|
95
|
+
// For simplicity, we overwrite (shallow merge by replacing value).
|
|
96
|
+
editor.putString(key, value)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
editor.apply()
|
|
100
|
+
promise.resolve(null)
|
|
101
|
+
} catch (e: Exception) {
|
|
102
|
+
promise.reject("ASYNC_STORAGE_ERROR", e.message, e)
|
|
103
|
+
}
|
|
104
|
+
}.start()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
override fun getAllKeys(promise: Promise) {
|
|
108
|
+
Thread {
|
|
109
|
+
try {
|
|
110
|
+
val prefs = getPrefs()
|
|
111
|
+
val result = WritableNativeArray()
|
|
112
|
+
for (key in prefs.all.keys) {
|
|
113
|
+
result.pushString(key)
|
|
114
|
+
}
|
|
115
|
+
promise.resolve(result)
|
|
116
|
+
} catch (e: Exception) {
|
|
117
|
+
promise.reject("ASYNC_STORAGE_ERROR", e.message, e)
|
|
118
|
+
}
|
|
119
|
+
}.start()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
override fun clear(promise: Promise) {
|
|
123
|
+
Thread {
|
|
124
|
+
try {
|
|
125
|
+
getPrefs().edit().clear().apply()
|
|
126
|
+
promise.resolve(null)
|
|
127
|
+
} catch (e: Exception) {
|
|
128
|
+
promise.reject("ASYNC_STORAGE_ERROR", e.message, e)
|
|
129
|
+
}
|
|
130
|
+
}.start()
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.asyncstorage
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
9
|
+
|
|
10
|
+
class RNCAsyncStoragePackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == RNCAsyncStorageModule.NAME) {
|
|
13
|
+
RNCAsyncStorageModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
20
|
+
return ReactModuleInfoProvider {
|
|
21
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
22
|
+
moduleInfos[RNCAsyncStorageModule.NAME] = ReactModuleInfo(
|
|
23
|
+
RNCAsyncStorageModule.NAME,
|
|
24
|
+
RNCAsyncStorageModule.NAME,
|
|
25
|
+
false, // canOverrideExistingModule
|
|
26
|
+
false, // needsEagerInit
|
|
27
|
+
false, // isCxxModule
|
|
28
|
+
true // isTurboModule
|
|
29
|
+
)
|
|
30
|
+
moduleInfos
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-async-storage",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.57",
|
|
4
4
|
"description": "react-native-async-storage",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"!**/__tests__",
|
|
22
22
|
"!**/__fixtures__",
|
|
23
23
|
"!**/__mocks__",
|
|
24
|
-
"!**/.*"
|
|
24
|
+
"!**/.*",
|
|
25
|
+
"android"
|
|
25
26
|
],
|
|
26
27
|
"scripts": {
|
|
27
28
|
"clean": "del-cli ios/build lib",
|