@angelo-dev/react-native-storage 0.1.0 → 0.1.1

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.
@@ -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
- NativeReactNativeStorageSpec(reactContext) {
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 getName(): String {
11
- return NAME
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
- // Example method
15
- // See https://reactnative.dev/docs/native-modules-android
16
- override fun multiply(a: Double, b: Double): Double {
17
- return a * b
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
- override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
- return if (name == ReactNativeStorageModule.NAME) {
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(): ReactModuleInfoProvider {
20
- return ReactModuleInfoProvider {
21
- val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
- moduleInfos[ReactNativeStorageModule.NAME] = ReactModuleInfo(
23
- ReactNativeStorageModule.NAME,
24
- ReactNativeStorageModule.NAME,
25
- false, // canOverrideExistingModule
26
- false, // needsEagerInit
27
- false, // isCxxModule
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
- moduleInfos
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;AAMpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,oBAAoB,CAAC","ignoreList":[]}
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":[]}
@@ -1,7 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  import ReactNativeStorage from "./NativeReactNativeStorage.js";
4
- export function multiply(a, b) {
5
- return ReactNativeStorage.multiply(a, b);
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
@@ -1 +1 @@
1
- {"version":3,"names":["ReactNativeStorage","multiply","a","b"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,kBAAkB,MAAM,+BAA4B;AAE3D,OAAO,SAASC,QAAQA,CAACC,CAAS,EAAEC,CAAS,EAAU;EACrD,OAAOH,kBAAkB,CAACC,QAAQ,CAACC,CAAC,EAAEC,CAAC,CAAC;AAC1C","ignoreList":[]}
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
- multiply(a: number, b: number): number;
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,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxC;;AAED,wBAA4E"}
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 multiply(a: number, b: number): number;
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":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD"}
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.0",
3
+ "version": "0.1.1",
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",
@@ -1,7 +1,12 @@
1
1
  import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
2
 
3
3
  export interface Spec extends TurboModule {
4
- multiply(a: number, b: number): number;
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>('ReactNativeStorage');
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 multiply(a: number, b: number): number {
4
- return ReactNativeStorage.multiply(a, b);
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
+ }