-
Notifications
You must be signed in to change notification settings - Fork 475
feat: Allow brownfield iOS apps to handle storage. #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tido64
merged 16 commits into
react-native-async-storage:master
from
tido64:tonguye/ios-delegate
Apr 10, 2019
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e3ceb41
feat: Allow brownfield iOS apps to handle storage.
tido64 efca317
Allow passthrough.
tido64 fff6459
Added docs.
tido64 a6af9d0
Added tests.
tido64 b711c63
Fixed lint errors.
tido64 eb3b262
Fixed tests failing on Android.
tido64 15b722b
Update README.md
ee0efe2
Update docs/AdvancedUsage.md
8f0a2c0
Split RNCAsyncStorageDelegate impl from AppDelegate
tido64 c8b8ac6
Added horizontal rules between each method.
tido64 5c894f7
Removed redundant tests.
tido64 d6ac327
Fixed tests failing due to inter-test deps
tido64 0b71efb
Ensure all tests can be run independently
tido64 0ebbe13
Rewrite tests to ensure calls reach the delegate
tido64 3197ae1
Docs changes by krizzu :)
tido64 e82c530
Empty commit to trigger a new build.
tido64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Integrating Async Storage with embedded React Native apps | ||
|
||
If you're embedding React Native into native application, you can also integrate | ||
Async Storage module, so that both worlds will use one storage solution. | ||
|
||
## iOS | ||
|
||
AsyncStorage can be controlled by the hosting app via the delegate on | ||
`RNCAsyncStorage`: | ||
|
||
```objc | ||
RNCAsyncStorage *asyncStorage = [bridge moduleForClass:[RNCAsyncStorage class]]; | ||
asyncStorage.delegate = self; | ||
``` | ||
|
||
### The procotol | ||
|
||
The delegate must conform to the `RNCAsyncStorageDelegate` protocol | ||
|
||
--- | ||
|
||
```objc | ||
- (void)allKeys:(RNCAsyncStorageResultCallback)block; | ||
``` | ||
|
||
Returns all keys currently stored. If none, an empty array is returned. | ||
Called by `getAllKeys` in JS. | ||
|
||
--- | ||
|
||
```objc | ||
- (void)mergeValues:(NSArray<NSString *> *)values | ||
forKeys:(NSArray<NSString *> *)keys | ||
completion:(RNCAsyncStorageResultCallback)block; | ||
``` | ||
|
||
Merges values with the corresponding values stored at specified keys. | ||
Called by `mergeItem` and `multiMerge` in JS. | ||
|
||
--- | ||
|
||
```objc | ||
- (void)removeAllValues:(RNCAsyncStorageCompletion)block; | ||
``` | ||
|
||
Removes all values from the store. Called by `clear` in JS. | ||
|
||
--- | ||
|
||
```objc | ||
- (void)removeValuesForKeys:(NSArray<NSString *> *)keys | ||
completion:(RNCAsyncStorageResultCallback)block; | ||
``` | ||
|
||
Removes all values associated with specified keys. | ||
Called by `removeItem` and `multiRemove` in JS. | ||
|
||
--- | ||
|
||
```objc | ||
- (void)setValues:(NSArray<NSString *> *)values | ||
forKeys:(NSArray<NSString *> *)keys | ||
completion:(RNCAsyncStorageResultCallback)block; | ||
``` | ||
|
||
Sets specified key-value pairs. Called by `setItem` and `multiSet` in JS. | ||
|
||
--- | ||
|
||
```objc | ||
- (void)valuesForKeys:(NSArray<NSString *> *)keys | ||
completion:(RNCAsyncStorageResultCallback)block; | ||
``` | ||
|
||
Returns values associated with specified keys. | ||
Called by `getItem` and `multiGet` in JS. | ||
|
||
--- | ||
|
||
```objc | ||
@optional | ||
@property (nonatomic, readonly, getter=isPassthrough) BOOL passthrough; | ||
``` | ||
|
||
**Optional:** Returns whether the delegate should be treated as a passthrough. | ||
This is useful for monitoring storage usage among other things. Returns `NO` by | ||
default. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
example/ios/AsyncStorageExample/AppDelegate+RNCAsyncStorageDelegate.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "AppDelegate.h" | ||
|
||
#import <RNCAsyncStorage/RNCAsyncStorageDelegate.h> | ||
|
||
@interface AppDelegate (RNCAsyncStorageDelegate) <RNCAsyncStorageDelegate> | ||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.