{"id":13807803,"url":"https://github.com/kevinresol/react-native-default-preference","last_synced_at":"2025-05-16T12:07:13.082Z","repository":{"id":14295590,"uuid":"75902222","full_name":"kevinresol/react-native-default-preference","owner":"kevinresol","description":"Use SharedPreference (Android) and UserDefaults (iOS) with React Native over a unified interface","archived":false,"fork":false,"pushed_at":"2024-04-08T04:03:51.000Z","size":115,"stargazers_count":226,"open_issues_count":3,"forks_count":76,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-29T22:33:04.423Z","etag":null,"topics":["android","ios","react-native","sharedpreferences","userdefaults"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinresol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-08T04:14:32.000Z","updated_at":"2024-08-14T16:10:51.000Z","dependencies_parsed_at":"2024-04-08T05:22:29.930Z","dependency_job_id":"32b114d8-5957-4d84-bf89-809d18a154ee","html_url":"https://github.com/kevinresol/react-native-default-preference","commit_stats":{"total_commits":61,"total_committers":23,"mean_commits":2.652173913043478,"dds":0.7868852459016393,"last_synced_commit":"9176021cf06b70e02dd9007c24bbb4d27ba6d74f"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinresol%2Freact-native-default-preference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinresol%2Freact-native-default-preference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinresol%2Freact-native-default-preference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinresol%2Freact-native-default-preference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinresol","download_url":"https://codeload.github.com/kevinresol/react-native-default-preference/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018032,"owners_count":21034045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","ios","react-native","sharedpreferences","userdefaults"],"created_at":"2024-08-04T01:01:30.575Z","updated_at":"2025-05-16T12:07:13.069Z","avatar_url":"https://github.com/kevinresol.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/react-native-default-preference.svg)](https://badge.fury.io/js/react-native-default-preference)\n\n# react-native-default-preference\n\n\nUse `SharedPreferences` (Android) and `UserDefaults` (iOS) with React Native over a unified interface.\nAll data is stored as a string. If you need to support more complex data structures, use serialization/deserialization (e.g. JSON).\n\n## Getting started\n\n`$ npm install react-native-default-preference --save`\n\n### React Native \u003e= 0.60\n\n`$ cd ios \u0026\u0026 pod install`\n\n### React Native \u003c= 0.59\n\n`$ react-native link react-native-default-preference`\n\n### Manual installation\n\n\n#### iOS\n\n1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`\n2. Go to `node_modules/react-native-default-preference/ios` and add `RNDefaultPreference.xcodeproj`\n3. In XCode, in the project navigator, select your project. Add `libRNDefaultPreference.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`\n4. Run your project (`Cmd+R`)\u003c\n\n#### Android\n\n1. Open up `android/app/src/main/java/[...]/MainApplication.java`\n  - Add `import com.kevinresol.react_native_default_preference.RNDefaultPreferencePackage;` to the imports at the top of the file\n  - Add `new RNDefaultPreferencePackage()` to the list returned by the `getPackages()` method\n2. Append the following lines to `android/settings.gradle`:\n  \t```\n  \tinclude ':react-native-default-preference'\n  \tproject(':react-native-default-preference').projectDir = new File(rootProject.projectDir, \t'../node_modules/react-native-default-preference/android')\n  \t```\n3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:\n  \t```\n      compile project(':react-native-default-preference')\n  \t```\n\n## Usage\n```javascript\nimport DefaultPreference from 'react-native-default-preference';\n\nDefaultPreference.get('my key').then(function(value) {console.log(value)});\nDefaultPreference.set('my key', 'my value').then(function() {console.log('done')});\n```\n\n## API\n\n```typescript\nfunction get(key: string): Promise\u003cstring | undefined | null\u003e;\nfunction set(key: string, value: string): Promise\u003cvoid\u003e;\nfunction clear(key: string): Promise\u003cvoid\u003e;\nfunction getMultiple(keys: string[]): Promise\u003cstring[]\u003e;\nfunction setMultiple(data: {[key: string]: string}): Promise\u003cvoid\u003e;\nfunction clearMultiple(keys: string[]): Promise\u003cvoid\u003e;\nfunction getAll(): Promise\u003c{[key: string]: string}\u003e;\nfunction clearAll(): Promise\u003cvoid\u003e;\n\n/** Gets and sets the current preferences file name (android) or user default suite name (ios) **/\nfunction getName(): Promise\u003cstring\u003e;\nfunction setName(name: string): Promise\u003cvoid\u003e;\n```\n\n## Cordova Native Storage Compatibility\nThis module is compatible with cordova-plugin-native-storage.\n\n### Android\nYou need to use the same SharedPreference as in the cordova plugin, to do so add\nthe following line:\n\n```js\nimport { Platform } from 'react-native';\n// ...\nif (Platform.OS === 'android') DefaultPreference.setName('NativeStorage');\n```\n\n### iOS\nYou don't need to change the name, as cordova-plugin-native-storage uses the default\nvalue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinresol%2Freact-native-default-preference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinresol%2Freact-native-default-preference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinresol%2Freact-native-default-preference/lists"}