Coder Social home page Coder Social logo

react-native-async-storage / async-storage Goto Github PK

View Code? Open in Web Editor NEW
4.7K 4.7K 466.0 9.16 MB

An asynchronous, persistent, key-value storage system for React Native.

Home Page: https://react-native-async-storage.github.io/async-storage/

License: MIT License

Java 16.74% JavaScript 5.47% Objective-C 6.48% Ruby 2.72% Shell 1.09% C++ 14.29% CSS 0.57% Kotlin 10.13% C 0.17% TypeScript 27.80% Objective-C++ 14.44% Swift 0.10%

async-storage's People

Contributors

aaronechiu avatar andreicoman11 avatar asyncstoragebot avatar bell-steven avatar brentvatne avatar cortinico avatar cpojer avatar dependabot[bot] avatar douglowder avatar evanbacon avatar hramos avatar ifsnow avatar javache avatar kaiguo avatar krizzu avatar matthamil avatar milend avatar motiz88 avatar mrilob avatar nickgerleman avatar nicklockwood avatar retyui avatar sahrens avatar semantic-release-bot avatar simek avatar tadeuzagallo avatar thesavior avatar tido64 avatar vjeux avatar vmoroz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

async-storage's Issues

Xcode archive generates Generic Xcode Archive instead of IPA

Current behavior

after updating to 1.3.1 Xcode creates Generic Xcode Archive instead of creating IPA. after looking up the problem and checking created archive, i found out RNCAsyncStorage.h and RNCAsyncStorageDelegate.h which are header files for the library is included in archive. you can find headers in
Archive.xcarchive -> show Package Content/Products/usr/local/include

after looking up the problem i found a solution here which is to move headers from Public to Project in the Build Phase / Headers.

Expected behavior

Xcode should create IPA not a Generic Xcode Archive

Repro steps

  • Xcode -> Clean
  • Xcode -> clean DerivedData folder
  • Xcode -> Archive

Environment

  • Async Storage version: 1.3.1
  • React-Native version: 0.59.4
  • Platform tested: iOS

AsyncStorage.getItem() doesn't seem to work


This issue was originally created by @mrded as facebook/react-native#18372.


When I try to set a value via AsyncStorage.getItem(), I cannot request it back.

Environment

Environment:
OS: macOS High Sierra 10.13.3
Node: 9.8.0
Yarn: 1.5.1
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: Not Found

Packages: (wanted => installed)
react: ^16.3.0-alpha.1 => 16.3.0-alpha.1
react-native: 0.54.0 => 0.54.0

Expected Behavior

await AsyncStorage.setItem('foo', 'bar');
await AsyncStorage.getItem('foo').then(console.log); // 'bar'
await AsyncStorage.getAllKeys().then(console.log); // ['foo']

Actual Behavior

await AsyncStorage.setItem('foo', 'bar');
await AsyncStorage.getItem('foo').then(console.log); // null
await AsyncStorage.getAllKeys().then(console.log); // []

Steps to Reproduce

import { AsyncStorage } from 'react-native';

it('should be able to request a value after it was set', async () => {
  await AsyncStorage.setItem('foo', 'bar');
  const output = await AsyncStorage.getItem('foo');

  expect(output).toBe('bar');
});

it('should be able to see a new key after a value was set', async () => {
  await AsyncStorage.setItem('foo', 'bar');
  const output = await AsyncStorage.getAllKeys();

  expect(output).toContain('foo');
});

The folder “manifest.json” doesn’t exist

Current behavior

I am getting a crash report from Sentry saying:

Failed to write manifest file.Error Domain=NSCocoaErrorDomain Code=4 "The folder “manifest.json” doesn’t exist." UserInfo={NSURL=file:///var/mobile/Containers/Data/Application/A7CD2724-A623-49F8-82A5-9B433D1C697F/Documents/RCTAsyncLocalStorage_V1/manifest.json, NSUserStringVariant=Folder, NSUnderlyingError=0x2822e0ae0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

This crash has the highest frequency in my project. ~1.5k a week.

I think the crash occur at this line.

https://github.com/react-native-community/react-native-async-storage/blob/8d275ad706c27962f71849119bc0f1be811a375e/ios/RNCAsyncStorage.m#L366

PS: I am using AsyncStorage through react-native-storage, but because the crash occur in AsyncStorage I report it here.

PPS: I think it's weird that the crash log says "The folder “manifest.json” doesn’t exist.", because manifest.json isn't a folder.

Expected behavior

Shouldn't crash.

Repro steps

I don't have a way to reproduce yet, but I will keep investigating this issue on my side, and update this thread if I find a way to reproduce.

Any clue to debug this is welcome.

Environment

  • Async Storage version: Embedded with React Native 0.58.6
  • React-Native version: 0.58.6
  • Platform: iOS 12.1.4
  • Logs/Error that are relevant:
Failed to write manifest file.Error Domain=NSCocoaErrorDomain Code=4 "The folder “manifest.json” doesn’t exist." UserInfo={NSURL=file:///var/mobile/Containers/Data/Application/A7CD2724-A623-49F8-82A5-9B433D1C697F/Documents/RCTAsyncLocalStorage_V1/manifest.json, NSUserStringVariant=Folder, NSUnderlyingError=0x2822e0ae0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Allow brownfield apps to handle requests

Motivation

We have brownfield apps with existing storage solutions that we want our React Native components to take advantage of. For example, one of our apps use PINCache to control lifetime of the stored data and the size of the disk cache.

Description

Before I start implementing on this, I'd like to run you by my solution and get some feedback on whether I'm on the correct path.

In RNCAsyncStorage, we add a delegate @property, e.g.:

@property (nonatomic, weak, nullable) id<RNCAsyncStorageDelegate> delegate;

For every RCT_EXPORT_METHOD, we call the delegate if it's set, otherwise we do the normal operations.

Consumers can then set the delegate like so:

RNCAsyncStorage *asyncStorage = [bridge moduleForClass:[RNCAsyncStorage class]];
asyncStorage.delegate = self;

Let me know what you think.

Thanks.

cannot run my app on web with yarn start-web error on asyncstorage

Current behavior

so i am trying to export my project into web app and when i do yarn start-web it show me some error about asyncstorage(the log is above) and wont compile.

but when i create a new project it work great without the asyncstorage libraries..any suggstion what may be the problem?

Expected behavior

to be able to run my app over web without the problem of asyncstorage/or other solution

Repro steps

try to delete the node_modules and re install try to add this line :

"transformIgnorePatterns": ["/node_modules/@react-native-community/async-storage/(?!(lib))"]

into

"jest": {
},

on packege.json

Environment

  • Async Storage version: "^1.2.2",
  • React-Native version: react native version- 0.59.0
  • Platform tested: web
  • Logs/Error that are relevant:
    Failed to compile.

./node_modules/@react-native-community/async-storage/lib/AsyncStorage.js
SyntaxError: C:\Users\user\WebstormProjects\ElectorMain\node_modules@react-native-community\async-storage\lib\AsyncStorage.js: Unexpected token, expected ";" (40:5)

38 | }
39 |

40 | type ReadOnlyArrayString = $ReadOnlyArray;
| ^
41 |
42 | type MultiGetCallbackFunction = (
43 | errors: ?$ReadOnlyArray,

Could not open AsyncStorage.js in the editor.

When running on Windows, file names are checked against a whitelist to protect against remote code execution attacks. File names may consist only of alphanumeric characters (all languages),
periods, dashes, slashes, and underscores.

Could not open AsyncStorage.js in the editor.

When running on Windows, file names are checked against a whitelist to protect against remote code execution attacks. File names may consist only of alphanumeric characters (all languages),
periods, dashes, slashes, and underscores.

Could not open AsyncStorage.js in the editor.

When running on Windows, file names are checked against a whitelist to protect against remote code execution attacks. File names may consist only of alphanumeric characters (all languages),
periods, dashes, slashes, and underscores.

[General] Cleanup

About

I call this cleanup task, but it's actually a to do that I believe will increase the usability of this repo.
Open for any discussion/proposals. If someone would like to help with anything, feel free to (just post in this issue).

Todo list

Auto-generated documentation

  • In progress

I believe simple HTML-from-markdown generator would do the job. We currently have two pages - API and Manual Linking - so GitHub pages should be sufficient to display them as HMTL.

Unit tests for JS interface

  • In progress

Test public interface that consumes the native module.

Done:

GitHub template issues

To help maintainers maintain and issuers issue, unified way of communication is the key. I believe a separate template for bugs, feature request, and questions would be helpful here.

Write CONTRIBUTORS guide

A helpful guide for newcomers, willing to help out with Async Storage.

Automatic sematic releases

Automatic, regular, semantic releases with patches/fixes would be useful.


More to come

The list will keep growing over time, so feel free to post your ideas/thoughts.

Thanks!

iOS Headers should be added at project level not public level

Current behavior

When manually linking the library, archiving will fail due to headers not being added to project level. With will cause the app to be bundled as a Generic XCode project instead of an iOS App.

Expected behavior

The app to be bundled as an iOS App.

Repro steps

Create a new react-native project and manually link AsyncStorage. Attempt to Archive. In the Organiser window you will see the new Archive listed under "Other" instead of under iOS Apps.

Solution

Screenshot 2019-04-20 at 13 30 42

Screenshot 2019-04-20 at 13 30 47

AsyncStorage.getItem blocks when debugging remotely


This issue was originally created by @bartolkaruza as facebook/react-native#12830.


Description

In some situations when calling AsyncStorage.getItem, either with a callback, calling then or using async await, the proceeding callback is not called and the promise does not resolve. This only happens when the remote debugger is on.

result or error are not called below:

AsyncStorage.getItem('key')
      .then(result => console.log('result', result))
      .catch(e => console.log('err', e));

AFTER is not printed (and no error is thrown):

console.log('BEFORE');
const result = await AsyncStorage.getItem('key');
console.log('AFTER');

The same code above completes the first time (and several consecutive times) it is run in the same debug session but blocks at a later stage. The point in time where it starts blocking is consistent in my app, so there is a piece of context that I haven't found yet which is causing it. I will continue searching for this context. Are maybe others running into similar behavior?

No matter the availability of data, getItem should always resolve (or reject), right?

Reproduction

I will keep trying to isolate the reproduction but so far I have not been able to cleanly reproduce, but in my full app, it is consistently occurring.

Solution

Additional Information

This issue is occurring on both iOS devices and simulators. I haven't seen it on Android yet.
OS X 10.11.6
Xcode 8.2.1
React Native Debugger 0.5.6
React Native 0.42.0

  "dependencies": {
    "react": "15.4.2",
    "react-native": "0.42.0",
    "analytics-react-native": "^1.0.1",
    "axios": "^0.11.1",
    "bugsnag-react-native": "^2.0.2",
    "firebase": "^3.6.10",
    "moment": "2.17.1",
    "react-native-auth0": "^1.0.0-beta.1",
    "react-native-code-push": "^1.17.2-beta",
    "react-native-drawer": "^2.2.3",
    "react-native-gifted-chat": "https://github.com/immidi/react-native-gifted-chat",
    "react-native-loading-spinner-overlay": "^0.4.1s",
    "react-native-lock": "git+ssh://[email protected]/auth0/react-native-lock.git",
    "react-native-navbar-wrapper": "^1.0.0",
    "react-native-onesignal": "^3.0.2",
    "react-native-smart-badge": "1.1.1",
    "react-navigation": "1.0.0-beta.3",
    "react-redux": "^4.4.5",
    "redux": "^3.5.2",
    "redux-devtools-extension": "^2.13.0"
  },
  "devDependencies": {
    "babel-jest": "19.0.0",
    "babel-preset-react-native": "1.9.1",
    "jest": "19.0.2",
    "react-test-renderer": "15.4.2",
    "remote-redux-devtools": "^0.5.7",
    "chai": "*",
    "chai-as-promised": "*",
    "colors": "*",
    "mocha": "*",
    "q": "*",
    "underscore": "*",
    "wd": "*",
    "eslint": "^3.1.1",
    "eslint-plugin-react": "^5.2.2",
    "eslint-plugin-react-native": "^1.1.0",
    "babel-eslint": "^6.1.2"
  }

Flow support

You want to:

Hi !

Are react-native-community packages extracted from react-native core supporting officially flow ?

Details:

There are some @flow annotation in sources but not all, and there is no flowconfig file in the npm package. This leads to a typing regression when using flow checker.

I've seen a great work about linking standardization by react-native-community, and I think it could be great if the same job was done for flow typing.

Document semantics

This is a documentation request. It's not clear to me the intended semantics of this library.

If setItem promise resolves, does that indicate that a subsequent getItem will return the latest value? Or that it will be eventually consistent?

If it fails, is the state of the store the old value, or undefined?

For setMultiple, is it atomic?

etc...

Thanks!

Recovering from pre-1.2.2 versions

What's going on?

It came to my attention that I've introduced a Breaking change, without properly announcing it.

This is only related to iOS platform. Since version 1.0.2, location where Async Storage kept files was changed: 34fb665

Some time age, issue #40 was raised, saying that smooth transition from Core's Async Storage to Community's was not possible, as data was lost on migration (actually, stored somewhere else). I've merged a fix in #46, to bring back the compatibility.

Now, devs that already transitioned to this repo (pre v1.2.2), planning to upgrade to the latest (v1.2.2), would be left off with the same issue as before - their current local data would not be accessible again.

I can imagine how this can be frustrating, to see no breaking change note in the changelog, yet experiencing different module behavior than expected. If this is a case that you got into - I'm sorry, the blame is all mine.

What now?

I wanted to discuss a way to fix this issue, and give pre-v1.2.2 devs ability to upgrade to next versions, without breaking anything on the way.

To make this work, we need to move manifest.json file from old (RNCAsyncLocalStorage_V1) directory to a new, correct one (RCTAsyncLocalStorage_V1), deleting unnecessary folder afterwards. This will ensure that data will be kept and in the right directory.


// pseudo native code

fun migrateToAsyncStorage() {
    let oldDir = Dir('RNCAsyncLocalStorage_V1')
    let newDir = Dir('RCTAsyncLocalStorage_V1')

    if(oldDir.exists) {
        moveManifest(oldDir, newDir);
        deleteDir(oldDir);
    }
}

This could be introduced as Native Module or just a simple check on iOS side, when module is build.

Any feedback as always is appreciated, please let me know what you think.

thanks.

Setting this.props into Async

I can't set this.state.user inside AsyncStorage.setItem() on the latest RN version, now with this package i can't use it. It shows warning message... Line Column sourceURL.

Recent 1.3.1 release breaks iOS build if linked with pods

Screenshot 2019-04-12 14 45 19

Repro steps

I've created an example app at https://github.com/timmywil/react-native-async-storage-1.3.1

This app was created with react-native init and async-storage included with react-native link... && cd ios/ && pod install after creating a Podfile.

Building without pods seems to work fine, but if async-storage is included with pods, you get the error shown above.

Downgrading to 1.3.0 fixes the issue.

Environment

  • Async Storage version: 1.3.1
  • React-Native version: 0.59.4
  • Platform tested: iOS only

AsyncStorage on iOS is buggy

Current behavior

Using @react-native-community/react-native-async-storage for Android works but for iOS is null when .getItem('@key', value) after .setItem('@key', value)

Expected behavior

AsyncStorage should get values from .setItem().
I had to revert to use react-native's built-in AsyncStorage in the meantime.

Repro steps

  • Install react-native-community/async-storage:"^1.3.3"
  • Launch react-native run ios
  • in the code, run await AsyncStorage.setItem('@key', 'value')
  • the same code with alert(await AsyncStorage.getItem('@key'))
  • value is null

Environment

  • Async Storage version: 1.3.3
  • React-Native version: 0.59.4
  • Platform tested: iOS and Android
  • Logs/Error that are relevant:

Incorrect podspec's git tag

Current behavior

pod install causes an error (at least when installing AsyncStorage manually): Could not find remote branch 1.2.1 to clone.

Expected behavior

No error occurs.

Repro steps

  1. Create new empty RN project with iOS project based on Cocoapods
  2. Add "@react-native-community/async-storage": "^1.2.1" to package.json dependencies
  3. npm install
  4. Add pod 'react-native-async-storage', :podspec => '../node_modules/@react-native-community/async-storage' to Podfile
  5. pod install

Environment

  • Async Storage version: 1.2.1
  • React-Native version: 0.59.1
  • Platform tested: iOS (the issue is not applicable to Android)
  • Logs/Error that are relevant:
[!] Error installing react-native-async-storage
[!] /usr/bin/git clone https://github.com/react-native-community/react-native-async-storage.git /var/folders/... --template= --single-branch --depth 1 --branch 1.2.1

Cloning into '/var/folders/...'...
warning: Could not find remote branch 1.2.1 to clone.

How do I add AsyncStorage to a project started with expo

I want to use AsynStorage for a project which was started with expo init.

I added the library with yarn add @react-native-community/async-storage

When I try to import AsyncStorage in my project file like below, I get the error shown in the screenshot.

import AsyncStorage from '@react-native-community/async-storage';

rnc-issue

When I try to run this command react-native link @react-native-community/async-storage as directed in the docs, I get the following error 'react-native' is not recognized as an internal or external command, operable program or batch file

How do I resolve this issue. I have tested on both my android phone and on a Genymotion virtual android device.

Undefined is not an object (evaluating 'RCTAsyncStorage.multiMerge')


This issue was originally created by @boreales as facebook/react-native#22556.


Environment

React Native Environment Info:
System:
OS: macOS 10.14.1
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 463.56 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 9.5.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 26, 27
Build Tools: 27.0.3
System Images: android-27 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.1 AI-173.4907809
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.5.0 => 16.5.0
react-native: https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz => 0.57.1
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1

Description

image

Reproducible Demo

// Store/configureStore.js

import { createStore } from 'redux'
import toggleFavorite from './reducers/favoriteReducer'
import setAvatar from './reducers/avatarReducer'
import { persistCombineReducers } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

const rootPersistConfig = {
  key: 'root',
  storage: storage
}

export default createStore(persistCombineReducers(rootPersistConfig, {toggleFavorite, setAvatar}))

The problem seems to be the same as #21948 but I have last react-native version and can't fix it anyway. Any idea ?

Pod added to podfile after running link

You want to:

Ask question

Details:

In the manual linking instructions, the iOS instructions do not say to add a pod inside the Podfile. However, when I ran react-native link @react-native-community/async-storage it added the following line:

pod 'react-native-async-storage', :path => '../node_modules/@react-native-community/async-storage'

I presume this is expected behavior? Should the instructions be updated?

When to use flushGetRequests?

You want to:

When to use flushGetRequests?

Details:

I posted this question also an StackOverflow, but still did not get any answer.
https://stackoverflow.com/questions/52526121/when-to-use-flushgetrequests-in-asyncstorage-in-react-native

I integrated it into my own get function, since I had sometimes the problem, that the function did not complete. Still, this way of doing it, does not feel right to me:

getItem(key) {
    let resultPromise = AsyncStorage.getItem(PREFIX + key);
    AsyncStorage.flushGetRequests();
    return resultPromise.catch(() => null);
}

Please clarify. Thank you!

~ Manuel

Build error `RNCAsyncstorage.m` not found

Hi,

Edit: with version 1.0.2

There's a typo in RNCAsyncStorage.m filename, which is RNCAsyncstorage.m in build (notice the S of Storage)

error: Build input file cannot be found: '/Users/.../node_modules/@react-native-community/async-storage/ios/RNCAsyncstorage.m'

I tried to rename the file and it works

[General] Update Readme

Update README to cover:

  • Available API (Installation steps, linking)
  • Example usages
  • Contribution list

react-native-web implementation of AsyncStorage

Should the react-native-web implementation of AsyncStorage also reside in this community library?

When changing to @react-native-community/async-storage the web version of my React Native app fails on multiMerge

I believe it would be a simple copy paste of the localStorage code here: https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/exports/AsyncStorage/index.js

And it appears the react-native-web maintainers agree with the functionality residing in this library - necolas/react-native-web#1260

Thank you.

SyntaxError: Unexpected token export using jest

Current behavior

/@react-native-community/async-storage/lib/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export default from './AsyncStorage';

 SyntaxError: Unexpected token export

    > 1 | import AsyncStorage  from "@react-native-community/async-storage"
        | ^
      2 | 
      3 | /**
      4 |  * Loads a string from storage.

Repro steps

import @react-native-community/async-storage and test with jest.

Environment

  • Async Storage version: 1.2.1
  • React-Native version: 0.57.7
  • Platform tested: iOS / Android
  • Jest version: 24.0.11
  • Logs/Error that are relevant: see above

[iOS] Cannot get data set by react-native's AsyncStorage

Current behavior

  • On iOS, data (set by react-native core's AsyncStorage) cannot be accessed from this library's AsyncStorage.

Expected behavior

  • Data can be accessed from both AsyncStorage.

Repro steps

  • react-native init Sample --version 0.59.0
  • yarn add @react-native-community/[email protected]
  • Use AsyncStorage in react-native and set data using AsyncStorage.setItem
  • then Use AsyncStorage in @react-native-community/async-storage and get data using AsyncStorage.getItem

Environment

  • Async Storage version: 1.2.1
  • React-Native version: 0.59.0
  • Platform tested: iOS
  • Logs/Error that are relevant:

Linking when using kotlin not possible? NativeModule.RCTAsyncStorage is null.

You want to:

Since I was getting warnings that the react-native asyncStorags is becomming deprecated and is moved (here) to individual package, I decided to install... This seems to be a pain in the a** every time, was also troubleful when I installed RCs' extracted WebView. (grumpy sorry)....

Anyway, this time I am stuck with failing jest tests that I have not been able to resolve after 24 hours of trying. Have had multiple colleges passing by as well as asked for help on SO.
Please check this link for further issue despription: https://stackoverflow.com/questions/55418910/jest-test-fails-after-installing-react-native-async-storage

I did manual linking since react-native link will not work for this module as MainApplication.java does not exist when using kotlin. Instead I have MainApplication.kt

After linking manually the async functions are working just fine. Except the jest test are unable to find the module.
@RNCommunity/AsyncStorage: NativeModule.RCTAsyncStorage is null.

Any suggestions?

AsyncStorage.multiRemove method has different behavior on Android and iOS

When calling the AsyncStorage.multiRemove method with an empty array, the behavior on Android and iOS is different:

I created this issue at the facebook/react-native repo: facebook/react-native#23412 where I was told to create it at this repo.

How to not include react-native AsyncStorage.

After I've switched to community AsyncStorage, my apk became 3MB bigger. I'm guessing because it still compiles react-native side of things as well. Is there a way to disable it?

[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

Hello Guys, am new to react native i just facing a new problem which i cannot understand what and why its happening ? any one help me with this,
I was just try to use AsyncStorage for local storage and its just working fine when i import the AsyncStorage from react-native like :
import { AsyncStorage } from 'react-native'; (its working fine )

But when i try to use by import the AsyncStorage from @react-native-community/async-storage
like :

import AsyncStorage from '@react-native-community/async-storage';

it produce error like :

[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

To fix this issue try these steps:

• Run react-native link @react-native-community/async-storage in the project root.

• Rebuild and restart the app.

• Run the packager with --clearCache flag.

• If you are using CocoaPods on iOS, run pod install in the ios directory and then rebuild and re-run the app.

Why it is Happning with this import ? and I forget to tell that I also run the link command as

react-native link @react-native-community/async-storage after installing
Still not working why ?

Serial Executor hangs on Android 9

Current behavior

I'm upgrading my RN app from 0.56 to 0.59.3 and decided to move back to the community AsyncStorage solution. The problem I'm running into is that the serial Executor is getting jammed up processing getKey requests after about the 3rd request for a getKey. The result is in the JS side, the Promise never returns and locks up the app.

Expected behavior

The Serial Executor in use by the AsyncStorage solution would process the AsyncStorage request or fail but not go into a locked up state.

Repro steps

In my RN app, I have 4 AsyncStorage getKey requests during startup which all happen in succession. I've never seen the 4th request return. Sometimes I'll see requests 1-3 return before it hangs on the 4th. This happens on the Simulator and on the device. I've only tested on Android 9 sim and Pixel 2 Android 9.

To point to the Serial Executor as the problem, I removed all references to the Serial Executor in the AsyncStorage code base and just let the SQL Lite requests run on the main thread and it works perfectly.

Environment

  • Async Storage version: 1.3.3
  • React-Native version: 0.59.3
  • Platform tested: Android 9 sim and device (iOS sim and device works great)

No podspec found issue

You want to:

Prevent issue for others.
Hopefully, it will help someone.

Details:

In case of this issue:

[!] No podspec found for `react-native-async-storage` in `../node_modules/@react-native-community/async-storage`

Just check out this commit and at Podfile change line:
Form

pod 'react-native-async-storage', :path => '../node_modules/@react-native-community/async-storage'

To

pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

Accessing stored data from native code?

You want to:

From my iOS extension be able to access the data stored by my JavaScript code within the react native app.

Is it possible to call read/write functions from native code?

Exmaple:
From javascript

import AsyncStorage from '@react-native-community/async-storage';
await AsyncStorage.setItem('count', 999);

and then, from my native code I want to call what would be equivalent to getItem('count') to access the stored data. In my case, from the iOS share extension which needs to access this data. Are there any working example of how to do this? Is it even possible?

Details:

Sorry for asking questions that are a bit outside the scope of this module. I know it is supposed to be react native context, but some documentation about how this work behind the scene would be fantastic.

fatal error: 'React/RCTBridgeModule.h' file not found

Current behavior

After adding Async Storage build fails with fatal error: 'React/RCTBridgeModule.h' file not found.

info In file included from /Users/.../node_modules/@react-native-community/async-storage/ios/RNCAsyncStorage.m:8:
/Users/.../node_modules/@react-native-community/async-storage/ios/RNCAsyncStorage.h:8:9: fatal error: 'React/RCTBridgeModule.h' file not found

info #import <React/RCTBridgeModule.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~

info 1 error generated.
The following build commands failed:
	CompileC /Users/.../ios/build/.../Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/RNCAsyncStorage.build/Objects-normal/x86_64/RNCAsyncStorage.o /Users/.../node_modules/@react-native-community/async-storage/ios/RNCAsyncStorage.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Environment

  • Async Storage version: ^1.3.3
  • React-Native version: 0.59.5
  • Platform tested: iOS

Screenshot 2019-04-30 11 03 25

Create `useAsyncStorage` hook

What do you think of creating useAsyncStore hook, that encapsulates the most popular AsyncStorage methods?

const [getItem, setItem] = useAsyncStorage('@NameOfTheStore')

Where setItem(key, value) would save the key in @NameOfTheStore:${key}, and getItem(key) would read from it.

It's just a thought 😅

AsyncStorage Couldn't read row 0, col 0 from CursorWindow


This issue was originally created by @JAStanton as facebook/react-native#12529.


Description

When reading values that are too large using AsyncStorage on Android I run into this error:

I wrote a large value with AsyncStorage and later tried to read it, but it crashed.

BaseError: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
  at e (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:423:22)
  at None (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:416:71)
  at map ([native code])
  at errors (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:416:51)
  at slicedToArray (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:54:33)

Reproduction

It looks like on iOS we write to disk when the value is above a threshold and on Android we write to sqllite always.

let x = 'x';
while (x.length <= 3194304) {
  x = `${x}${x}`;
}
await AsyncStorage.setItem('@@GARBAGE@@', x); // works
const garbage = await AsyncStorage.getItem('@@GARBAGE@@'); // throws

Solution

In order for me to fix this I'll need to re-write AsyncStorage to write to disk instead of writing to sql. https://github.com/mvayngrib/react-native-safe-async-storage <--- this guys has the right idea but his code is super old and broken.

Additional Information

  • React Native version: 0.39.2
  • Platform: Android
  • Operating System: Samsung Galaxy S4

@react-native-community_async-storage:verifyReleaseResources FAILED

Hey, Whenever I run ./gradlew assembleRelease I got this error:

Execution failed for task ':@react-native-community_async-storage:verifyReleaseResources'.
java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  /Users/darkkingmarvel/Desktop/Jiffeo/v2/jiffeoApp/node_modules/@react-native-community/async-storage/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
  /Users/darkkingmarvel/Desktop/Jiffeo/v2/jiffeoApp/node_modules/@react-native-community/async-storage/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
  /Users/darkkingmarvel/Desktop/Jiffeo/v2/jiffeoApp/node_modules/@react-native-community/async-storage/android/build/intermediates/res/merged/release/values/values.xml:2714: error: resource android:attr/fontVariationSettings not found.
  /Users/darkkingmarvel/Desktop/Jiffeo/v2/jiffeoApp/node_modules/@react-native-community/async-storage/android/build/intermediates/res/merged/release/values/values.xml:2715: error: resource android:attr/ttcIndex not found.
  error: failed linking references.
  • Async Storage version:1.2.2
  • React-Native version: 0.59.2
  • Platform tested: Android

multiGet can return nulls, but the TS types do not reflect this

Current behavior

Querying AsyncStorage for an unknown key using multiGet can return null values.

However the types indicate this is impossible.

Expected behavior

Types should indicate that returning null is possible, OR null should never be returned (I don't know which is correct, but I would think the types).

Repro steps

Run code:

  const [testPair] = await AsyncStorage.multiGet(["DOES NOT EXIST"]);
  console.log(testPair);

return value: ["DOES NOT EXIST", null]

Environment

  • Async Storage version: Latest

"@react-native-community/async-storage": "^1.2.2",

"react-native": "0.59.1",

  • Platform tested: iOS

Setting up Jest mock does not work

Current behavior

Following docs in order to setup jest mock end up in error.

`import mockAsyncStorage from '@react-native-community/async-storage/jest/async-storage-mock';
' does not work as a file cannot be found.

After inspecting node_modules/@react-native-community/async-storage I have found out that there is nojest folder, only lib folder

as

Environment

  • Async Storage version: 1.2.4
  • React-Native version: 0.59.2
  • Platform tested:iOS/Android

info
React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 422.65 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.13.0 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 21, 23, 25, 26, 27, 28
Build Tools: 23.0.1, 26.0.2, 27.0.3, 28.0.2, 28.0.3
System Images: android-25 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5014246
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.3 => 0.59.3
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7

Doesn't run on Android with RN > 0.58

Current behavior

Running an app which includes AsyncStorage from this package instead of react-native will crash the app on startup.

Expected behavior

It doesn't crash the app on startup.

Repro steps

Just include the package with any RN > 0.58 (I think with all the gradle upgrades coming in 0.58 as well)

Environment

  • Async Storage version: 1.2.1
  • React-Native version: > 0.58
  • Platform tested: Android only, iOS works fine
  • Logs/Error that are relevant:

This is the log from the production device / emulator:

2019-03-20 16:21:35.950 9719-9742/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.bundlenam, PID: 9719
    com.facebook.react.common.JavascriptException: null is not an object (evaluating 'l.multiMerge'), stack:
    <unknown>@1436:2386
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1435:298
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1434:447
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1428:293
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1420:875
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1419:207
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1418:164
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1414:345
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1413:164
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@358:416
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@11:71
    _@2:1514
    d@2:897
    o@2:435
    global code@1618:4
    
        at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
        at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:164)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
        at java.lang.Thread.run(Thread.java:764)
2019-03-20 16:24:15.347 9940-9963/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.bundlename, PID: 9940
    com.facebook.react.common.JavascriptException: null is not an object (evaluating 'l.multiMerge'), stack:
    <unknown>@1436:2386
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1435:298
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1434:447
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1428:293
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1420:875
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1419:207
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1418:164
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1414:345
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@1413:164
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@358:416
    _@2:1514
    d@2:967
    o@2:435
    <unknown>@11:71
    _@2:1514
    d@2:897
    o@2:435
    global code@1618:4
    
        at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
        at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:164)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
        at java.lang.Thread.run(Thread.java:764)

Revisiting Hooks implementation

You want to:

Discuss required changes to current 'hook-ish' implementation for Hooks support.

Details:

As you can see here, we've got a nice wrapper on top AsyncStorage, to mimic hooks usage.
This discussion here is to come up with better and valid implementation, that leverages hooks API.

Example implementation could look like this:

function useAsyncStorage(key, defaultValue) {
  const [storageValue, updateStorageValue] = useState(defaultValue);

  useEffect(() => {
    getStorageValue();
  }, []);

  async function getStorageValue() {
    let value = defaultValue;
    try {
      value = (await AsyncStorage.getItem(key)) || defaultValue;
    } catch (e) {
      // handle here
    } finally {
      updateStorageValue(value);
    }
  }

  async function updateStorage(newValue) {
    try {
      await AsyncStorage.setItem(key, newValue);
    } catch (e) {
      // handle here
    } finally {
      getStorageValue();
    }
  }

  return [storageValue, updateStorage];
}

The problem in here is that, once we got a value inside AsyncStorage, we'll be getting two rerenders one component mounting - one returning the default value, second the actual stored data.

I'm more than happy to discuss this, so please let me know what you think.

Allow control over AsyncStorage location on iOS


This issue was originally created by @sam1463 as facebook/react-native#19692.


Environment

Environment:
OS: macOS High Sierra 10.13.5
Node: 9.4.0
Yarn: Not Found
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.4.1 Build version 9F2000
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.52.2 => 0.52.2

Description

Currently, AsyncStorage stores data in the Documents directory on iOS. However, as discussed in this issue, this abandoned PR, and this abandoned PR, there should be an option to store elsewhere, as this location is not appropriate for non-user-created content, as it is visible for apps that enable file sharing with iTunes or the Files app on iOS.

Steps to Reproduce

This is the case on AsyncStorage on all versions of react-native to my knowledge.

Expected Behavior

Some sort of control over the location in which AsyncStorage stores data, so that it will not be exported to iTunes, viewable via the Files app, etc. on iOS

Actual Behavior

AsyncStorage saves to the Documents directory.

Warning: AsyncStorage has been extracted from react-native core

Current behavior

After having switched to React Native Community Async Storage via

yarn add @react-native-community/async-storage

and having updated its usage using

import AsyncStorage from '@react-native-community/async-storage';

I still get the yellow box saying that "AsyncStorage has been extracted from react-native core and will be removed in a future release". This happens on both iOS and Android

Expected behavior

The yellow box shouldn't appear

Repro steps

  1. Adding @react-native-community/async-storage using yarn
  2. Importing it and running the application

Environment

  • Async Storage version: 1.2.4
  • React-Native version: 0.59.4
  • Platform tested: iOS and Android

Proguard

You want to:

Hi, is there any proguard rules for android?

Details:

No info provided about proguard rules

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.