Skip to content

Commit 05d3939

Browse files
authored
Create a macOS implementation of AsyncStorage + macOS example app and e2e tests (#296)
1 parent 8112a33 commit 05d3939

31 files changed

+4374
-80
lines changed

Diff for: .github/workflows/ci.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- LEGACY
7+
pull_request:
8+
branches:
9+
- LEGACY
10+
11+
jobs:
12+
build:
13+
14+
runs-on: macOS-latest
15+
16+
steps:
17+
- uses: actions/checkout@master
18+
- name: Installing Yarn dependencies
19+
run: yarn install
20+
- name: Build macOS app and run e2e tests
21+
run: yarn test:e2e:macos
22+

Diff for: .npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jsconfig.json
2424
.eslintignore
2525
codecov.yml
2626

27+
# Scripts
28+
scripts/
29+
2730
# Example
2831
example/
2932

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ We use `flow` for type check, `eslint` with `prettier` for linting/formatting, `
1010
* `yarn test`: Run all tests, except for e2e (see note below).
1111
* `yarn test:lint`: Run `eslint` check.
1212
* `yarn test:flow`: Run `flow` type check.
13-
* `yarn test:e2e:<ios|android>`: Runs e2e tests. Before you can run it, you should build the app that can be run, by using `yarn build:e2e:<ios|android>`.
13+
* `yarn test:e2e:<ios|android|macos>`: Runs e2e tests. Before you can run it, you should build the app that can be run, by using `yarn build:e2e:<ios|android|macos>`.
1414

1515

1616
## Sending a pull request

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ $ cd ios/ && pod install
4040

4141
See docs for [manual linking guide](docs/Linking.md)
4242

43+
*Note* For `macOS` the [manual linking](docs/Linking.md) is currently the only linking option.
44+
4345
### **Upgrading to React Native *0.60+***
4446

4547
New React Native comes with `autolinking` feature, which automatically links Native Modules in your project.

Diff for: docs/Linking.md

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
3. Run `pod install`
2424

25+
## macOS
26+
27+
#### Project linking
28+
1. Open your project `.xcodeproj` on xcode.
29+
30+
2. Right click on the Libraries folder and select `Add files to "yourProjectName"`.
31+
32+
3. Add `RNCAsyncStorage.xcodeproj` (located at `node_modules/@react-native-community/async-storage/macos`) to your project Libraries.
33+
34+
4. Go to `Build Phases -> Link Binary with Libraries` and add: `libRNCAsyncStorage-macOS.a`.
35+
2536

2637
## Android
2738
1. Add project to `android/settings.gradle`:

Diff for: docs/advanced/BrownfieldIntegration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
If you're embedding React Native into native application, you can also integrate
44
Async Storage module, so that both worlds will use one storage solution.
55

6-
## iOS
6+
## iOS and macOS
77

88
AsyncStorage can be controlled by the hosting app via the delegate on
99
`RNCAsyncStorage`:

Diff for: docs/advanced/IncreaseDbSize.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ AsyncStorage_db_size_in_MB=10
1515
Now you can define the new size in MB. In this example, the new limit is 10 MB.
1616

1717

18-
## iOS
18+
## iOS and macOS
1919

2020
Async Storage size is not limited programmatically on iOS.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <Cocoa/Cocoa.h>
9+
10+
@class RCTBridge;
11+
12+
@interface AppDelegate : NSObject <NSApplicationDelegate>
13+
14+
@property (nonatomic, readonly) RCTBridge *bridge;
15+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *memoryStorage;
16+
17+
@end
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "AppDelegate.h"
9+
10+
#import "RNCTestAsyncStorageDelegate.h"
11+
#import <RNCAsyncStorage/RNCAsyncStorage.h>
12+
13+
#import <React/RCTBridge.h>
14+
#import <React/RCTBundleURLProvider.h>
15+
16+
@interface AppDelegate () <RCTBridgeDelegate>
17+
18+
@end
19+
20+
@implementation AppDelegate {
21+
RNCTestAsyncStorageDelegate *_testDelegate;
22+
}
23+
24+
- (void)awakeFromNib {
25+
[super awakeFromNib];
26+
27+
_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
28+
29+
_memoryStorage = [NSMutableDictionary dictionary];
30+
}
31+
32+
- (void)application:(NSApplication *)application openURLs:(NSArray<NSURL *> *)urls {
33+
NSURL *url = [urls firstObject];
34+
35+
if (![url.scheme isEqualToString:@"rnc-asyncstorage"]) {
36+
return;
37+
}
38+
39+
if ([url.host isEqualToString:@"set-delegate"]) {
40+
if (_testDelegate == nil) {
41+
_testDelegate = [RNCTestAsyncStorageDelegate new];
42+
}
43+
RNCAsyncStorage *asyncStorage = [_bridge moduleForClass:[RNCAsyncStorage class]];
44+
asyncStorage.delegate = _testDelegate;
45+
} else if ([url.host isEqualToString:@"unset-delegate"]) {
46+
RNCAsyncStorage *asyncStorage = [_bridge moduleForClass:[RNCAsyncStorage class]];
47+
asyncStorage.delegate = nil;
48+
} else if ([url.host isEqualToString:@"clear-all-data"]) {
49+
[RNCAsyncStorage clearAllData];
50+
}
51+
}
52+
53+
#pragma mark - RCTBridgeDelegate Methods
54+
55+
- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge {
56+
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"example/index" fallbackResource:@"main"]; // .jsbundle;
57+
}
58+
59+
@end

Diff for: example/macos/AsyncStorageExample-macOS/Info.plist

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleURLTypes</key>
22+
<array>
23+
<dict>
24+
<key>CFBundleTypeRole</key>
25+
<string>Editor</string>
26+
<key>CFBundleURLName</key>
27+
<string>org.reactjs.native.example.AsyncStorageExample</string>
28+
<key>CFBundleURLSchemes</key>
29+
<array>
30+
<string>rnc-asyncstorage</string>
31+
</array>
32+
</dict>
33+
</array>
34+
<key>CFBundleVersion</key>
35+
<string>1</string>
36+
<key>LSMinimumSystemVersion</key>
37+
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
38+
<key>NSAppTransportSecurity</key>
39+
<dict>
40+
<key>NSAllowsArbitraryLoads</key>
41+
<true/>
42+
</dict>
43+
<key>NSHumanReadableCopyright</key>
44+
<string>Copyright © 2020 Facebook. All rights reserved.</string>
45+
<key>NSMainStoryboardFile</key>
46+
<string>Main</string>
47+
<key>NSPrincipalClass</key>
48+
<string>NSApplication</string>
49+
</dict>
50+
</plist>

0 commit comments

Comments
 (0)