@angelo-dev/react-native-storage 0.1.0 → 0.1.2
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.
- package/android/src/main/java/com/angelodev/reactnativestorage/ReactNativeStorageModule.kt +33 -9
- package/android/src/main/java/com/angelodev/reactnativestorage/ReactNativeStoragePackage.kt +15 -17
- package/lib/module/NativeReactNativeStorage.js.map +1 -1
- package/lib/module/index.js +12 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeReactNativeStorage.d.ts +4 -1
- package/lib/typescript/src/NativeReactNativeStorage.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/NativeReactNativeStorage.ts +7 -2
- package/src/index.tsx +16 -2
|
@@ -3,21 +3,45 @@ package com.angelodev.reactnativestorage
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
4
|
import com.facebook.react.module.annotations.ReactModule
|
|
5
5
|
|
|
6
|
+
import android.content.Context
|
|
7
|
+
import android.content.SharedPreferences
|
|
8
|
+
import com.nativelocalstorage.ReactNativeStorageSpec
|
|
9
|
+
|
|
10
|
+
|
|
6
11
|
@ReactModule(name = ReactNativeStorageModule.NAME)
|
|
7
|
-
class ReactNativeStorageModule(reactContext: ReactApplicationContext) :
|
|
8
|
-
|
|
12
|
+
class ReactNativeStorageModule(reactContext: ReactApplicationContext) :
|
|
13
|
+
ReactNativeStorageSpec(reactContext) {
|
|
14
|
+
|
|
15
|
+
override fun getName() = NAME
|
|
16
|
+
|
|
17
|
+
override fun setItem(value: String, key: String) {
|
|
18
|
+
val sharedPref = getReactApplicationContext().getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
|
|
19
|
+
val editor = sharedPref.edit()
|
|
20
|
+
editor.putString(key, value)
|
|
21
|
+
editor.apply()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun getItem(key: String): String? {
|
|
25
|
+
val sharedPref = getReactApplicationContext().getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
|
|
26
|
+
val username = sharedPref.getString(key, null)
|
|
27
|
+
return username.toString()
|
|
28
|
+
}
|
|
9
29
|
|
|
10
|
-
override fun
|
|
11
|
-
|
|
30
|
+
override fun removeItem(key: String) {
|
|
31
|
+
val sharedPref = getReactApplicationContext().getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
|
|
32
|
+
val editor = sharedPref.edit()
|
|
33
|
+
editor.remove(key)
|
|
34
|
+
editor.apply()
|
|
12
35
|
}
|
|
13
36
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
override fun clear() {
|
|
38
|
+
val sharedPref = getReactApplicationContext().getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
|
|
39
|
+
val editor = sharedPref.edit()
|
|
40
|
+
editor.clear()
|
|
41
|
+
editor.apply()
|
|
18
42
|
}
|
|
19
43
|
|
|
20
44
|
companion object {
|
|
21
45
|
const val NAME = "ReactNativeStorage"
|
|
22
46
|
}
|
|
23
|
-
}
|
|
47
|
+
}
|
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
package com.angelodev.reactnativestorage
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
import com.facebook.react.BaseReactPackage
|
|
4
5
|
import com.facebook.react.bridge.NativeModule
|
|
5
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
7
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
8
|
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
-
import java.util.HashMap
|
|
9
9
|
|
|
10
10
|
class ReactNativeStoragePackage : BaseReactPackage() {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
|
|
13
|
+
if (name == ReactNativeStorageModule.NAME) {
|
|
13
14
|
ReactNativeStorageModule(reactContext)
|
|
14
15
|
} else {
|
|
15
16
|
null
|
|
16
17
|
}
|
|
17
|
-
}
|
|
18
18
|
|
|
19
|
-
override fun getReactModuleInfoProvider()
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ReactNativeStorageModule.NAME,
|
|
24
|
-
|
|
25
|
-
false,
|
|
26
|
-
false,
|
|
27
|
-
|
|
28
|
-
true // isTurboModule
|
|
19
|
+
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
|
|
20
|
+
mapOf(
|
|
21
|
+
ReactNativeStorageModule.NAME to ReactModuleInfo(
|
|
22
|
+
name = ReactNativeStorageModule.NAME,
|
|
23
|
+
className = ReactNativeStorageModule.NAME,
|
|
24
|
+
canOverrideExistingModule = false,
|
|
25
|
+
needsEagerInit = false,
|
|
26
|
+
isCxxModule = false,
|
|
27
|
+
isTurboModule = true
|
|
29
28
|
)
|
|
30
|
-
|
|
31
|
-
}
|
|
29
|
+
)
|
|
32
30
|
}
|
|
33
|
-
}
|
|
31
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactNativeStorage.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactNativeStorage.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AASpE,eAAeA,mBAAmB,CAACC,YAAY,CAC7C,oBACF,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import ReactNativeStorage from "./NativeReactNativeStorage.js";
|
|
4
|
-
export function
|
|
5
|
-
return ReactNativeStorage.
|
|
4
|
+
export function setItem(key, value) {
|
|
5
|
+
return ReactNativeStorage.setItem(key, value);
|
|
6
|
+
}
|
|
7
|
+
export async function getItem(key) {
|
|
8
|
+
const item = await ReactNativeStorage.getItem(key);
|
|
9
|
+
return item ?? null;
|
|
10
|
+
}
|
|
11
|
+
export function removeItem(key) {
|
|
12
|
+
return ReactNativeStorage.removeItem(key);
|
|
13
|
+
}
|
|
14
|
+
export function clear() {
|
|
15
|
+
return ReactNativeStorage.clear();
|
|
6
16
|
}
|
|
7
17
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ReactNativeStorage","
|
|
1
|
+
{"version":3,"names":["ReactNativeStorage","setItem","key","value","getItem","item","removeItem","clear"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AACA,OAAOA,kBAAkB,MAAM,+BAA4B;AAE3D,OAAO,SAASC,OAAOA,CAACC,GAAW,EAAEC,KAAa,EAAiB;EACjE,OAAOH,kBAAkB,CAACC,OAAO,CAACC,GAAG,EAAEC,KAAK,CAAC;AAC/C;AAEA,OAAO,eAAeC,OAAOA,CAACF,GAAW,EAA0B;EACjE,MAAMG,IAAI,GAAG,MAAML,kBAAkB,CAACI,OAAO,CAACF,GAAG,CAAC;EAClD,OAAOG,IAAI,IAAI,IAAI;AACrB;AAEA,OAAO,SAASC,UAAUA,CAACJ,GAAW,EAAiB;EACrD,OAAOF,kBAAkB,CAACM,UAAU,CAACJ,GAAG,CAAC;AAC3C;AAEA,OAAO,SAASK,KAAKA,CAAA,EAAkB;EACrC,OAAOP,kBAAkB,CAACO,KAAK,CAAC,CAAC;AACnC","ignoreList":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type TurboModule } from 'react-native';
|
|
2
2
|
export interface Spec extends TurboModule {
|
|
3
|
-
|
|
3
|
+
setItem(key: string, value: string): Promise<void>;
|
|
4
|
+
getItem(key: string): Promise<string | null>;
|
|
5
|
+
removeItem(key: string): Promise<void>;
|
|
6
|
+
clear(): Promise<void>;
|
|
4
7
|
}
|
|
5
8
|
declare const _default: Spec;
|
|
6
9
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeReactNativeStorage.d.ts","sourceRoot":"","sources":["../../../src/NativeReactNativeStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,
|
|
1
|
+
{"version":3,"file":"NativeReactNativeStorage.d.ts","sourceRoot":"","sources":["../../../src/NativeReactNativeStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;;AAED,wBAEE"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function setItem(key: string, value: string): Promise<void>;
|
|
2
|
+
export declare function getItem(key: string): Promise<string | null>;
|
|
3
|
+
export declare function removeItem(key: string): Promise<void>;
|
|
4
|
+
export declare function clear(): Promise<void>;
|
|
2
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE;AAED,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGjE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD;AAED,wBAAgB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAErC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angelo-dev/react-native-storage",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Native local storage module for React Native built with the New Architecture",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -72,7 +72,9 @@
|
|
|
72
72
|
"del-cli": "^6.0.0",
|
|
73
73
|
"eslint": "^9.35.0",
|
|
74
74
|
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
75
76
|
"eslint-plugin-prettier": "^5.5.4",
|
|
77
|
+
"eslint-plugin-react-native": "^5.0.0",
|
|
76
78
|
"jest": "^29.7.0",
|
|
77
79
|
"lefthook": "^2.0.3",
|
|
78
80
|
"prettier": "^3.3.0",
|
|
@@ -110,7 +112,7 @@
|
|
|
110
112
|
]
|
|
111
113
|
},
|
|
112
114
|
"codegenConfig": {
|
|
113
|
-
"name": "
|
|
115
|
+
"name": "ReactNativeStorage",
|
|
114
116
|
"type": "modules",
|
|
115
117
|
"jsSrcsDir": "src",
|
|
116
118
|
"android": {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
2
2
|
|
|
3
3
|
export interface Spec extends TurboModule {
|
|
4
|
-
|
|
4
|
+
setItem(key: string, value: string): Promise<void>;
|
|
5
|
+
getItem(key: string): Promise<string | null>;
|
|
6
|
+
removeItem(key: string): Promise<void>;
|
|
7
|
+
clear(): Promise<void>;
|
|
5
8
|
}
|
|
6
9
|
|
|
7
|
-
export default TurboModuleRegistry.getEnforcing<Spec>(
|
|
10
|
+
export default TurboModuleRegistry.getEnforcing<Spec>(
|
|
11
|
+
'ReactNativeStorage',
|
|
12
|
+
);
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
|
|
1
2
|
import ReactNativeStorage from './NativeReactNativeStorage';
|
|
2
3
|
|
|
3
|
-
export function
|
|
4
|
-
return ReactNativeStorage.
|
|
4
|
+
export function setItem(key: string, value: string): Promise<void> {
|
|
5
|
+
return ReactNativeStorage.setItem(key, value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function getItem(key: string): Promise<string | null> {
|
|
9
|
+
const item = await ReactNativeStorage.getItem(key);
|
|
10
|
+
return item ?? null;
|
|
5
11
|
}
|
|
12
|
+
|
|
13
|
+
export function removeItem(key: string): Promise<void> {
|
|
14
|
+
return ReactNativeStorage.removeItem(key);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function clear(): Promise<void> {
|
|
18
|
+
return ReactNativeStorage.clear();
|
|
19
|
+
}
|