package com.unitreactnativecomponents.nativeModules.unStoreModule import android.content.Context import android.content.SharedPreferences import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod class UNStoreModule(var reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { private val sharedPreferences: SharedPreferences get() = reactContext.getSharedPreferences("YourProjectPreferences", Context.MODE_PRIVATE) @ReactMethod fun saveValue(key: String, value: String) { sharedPreferences.edit().putString(key, value).apply() } @ReactMethod fun getValue(key: String, promise: Promise) { val value = sharedPreferences.getString(key, null) promise.resolve(value) } @ReactMethod fun cleanValue(key: String) { sharedPreferences.edit().remove(key).apply() } override fun getName() = NAME companion object { const val NAME = "UNStoreModule" } }