Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-native-default-preference
Advanced tools
Use SharedPreference (Android) and UserDefaults (iOS) with React Native over a unified interface
Use SharedPreference
(Android) and UserDefaults
(iOS) with React Native over a unified interface.
All data are stored as String, in case more complex data structure is needed, serialize it (e.g. JSON)
Use >= 1.3.0 for RN >= 0.47; Use <= 1.2.1 for RN <= 0.46;
$ npm install react-native-default-preference --save
$ react-native link react-native-default-preference
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-default-preference
and add RNDefaultPreference.xcodeproj
libRNDefaultPreference.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)<android/app/src/main/java/[...]/MainActivity.java
import com.reactlibrary.RNDefaultPreferencePackage;
to the imports at the top of the filenew RNDefaultPreferencePackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':react-native-default-preference'
project(':react-native-default-preference').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-default-preference/android')
android/app/build.gradle
:
compile project(':react-native-default-preference')
import DefaultPreference from 'react-native-default-preference';
DefaultPreference.get('my key').then(function(value) {console.log(value)});
DefaultPreference.set('my key', 'my value').then(function() {console.log('done')});
function get(key:String):Promise<String>;
function set(key:String, value:String):Promise<Void>;
function clear(key:String):Promise<Void>;
function getMultiple(keys:Array<String>):Promise<Object>;
function setMultiple(data:Object):Promise<Void>;
function clearMultiple(keys:Array<String>):Promise<Void>;
function getAll():Promise<Object>;
function clearAll():Promise<Void>;
/** Gets and sets the current preferences file name (android) or user default suite name (ios) **/
function getName():Promise<String>;
function setName(name:String):Promise<Void>;
This module is compatible with cordova-plugin-native-storage.
You need to use the same SharedPreference as in the cordova plugin, to do so add the following line:
import { Platform } from 'react-native';
// ...
if (Platform.OS === 'android') DefaultPreference.setName('NativeStorage');
You don't need to change the name, as cordova-plugin-native-storage uses the default value.
FAQs
Use SharedPreference (Android) and UserDefaults (iOS) with React Native over a unified interface
The npm package react-native-default-preference receives a total of 9,580 weekly downloads. As such, react-native-default-preference popularity was classified as popular.
We found that react-native-default-preference demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.