Skip to content

Create a macOS implementation of AsyncStorage + macOS example app and e2e tests #296

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
merged 24 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d9bda40
Switch to consume microsoft fork.
tom-un Jan 2, 2020
04c5800
Mac test app.
tom-un Jan 7, 2020
2d33f65
Merge remote-tracking branch 'as/LEGACY' into tomun/macos
tom-un Feb 12, 2020
6d7d8f3
Create seperate macos xcodeproj. Refactor metro.config and react-nat…
tom-un Feb 12, 2020
83269c9
Remove unused file
tom-un Feb 12, 2020
69ab8eb
mac example building and working.
tom-un Feb 13, 2020
3ea7ddf
Updated docs for macOS
tom-un Feb 13, 2020
105134d
Simplified example test app
tom-un Feb 14, 2020
1deb2d3
Got mac build/test scripts working
tom-un Feb 14, 2020
66239e1
Added simple macOS XCUITest
tom-un Feb 14, 2020
215323b
Add mac tests to circle ci
tom-un Feb 14, 2020
acc584f
Got simple test to click add 10 button and test results
tom-un Feb 14, 2020
6cd308b
Implemented three macOS tests
tom-un Feb 15, 2020
7c0c10b
Got all mac tests to parity with iOS.
tom-un Feb 16, 2020
64574a5
Revert changes to ios xcodeproj
tom-un Feb 17, 2020
3b2d939
XCUITests for macOS not supported on CCI. So just build the example …
tom-un Feb 17, 2020
19ba4d3
Removed escape from string
tom-un Feb 17, 2020
6ba4665
Attempt to test macOS using GitHub Actions
tom-un Feb 17, 2020
9f46e99
Removed mac from CCI since CCI doesn't support mac tests.
tom-un Feb 17, 2020
18216d1
Update docs/Linking.md
tom-un Feb 20, 2020
7c643f4
Update example/macos/AsyncStorageExample-macOS/Info.plist
tom-un Feb 20, 2020
54ea5a4
Changes per tido64 code review feedback.
tom-un Feb 20, 2020
fecdd1c
Removed redundant source files.
tom-un Feb 20, 2020
526f6b3
Optimized 'test' e2e scripts to not reduntantly build.
tom-un Feb 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches:
- LEGACY
pull_request:
branches:
- LEGACY

jobs:
build:

runs-on: macOS-latest

steps:
- uses: actions/checkout@master
- name: Installing Yarn dependencies
run: yarn install
- name: Build macOS app and run e2e tests
run: yarn test:e2e:macos

3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jsconfig.json
.eslintignore
codecov.yml

# Scripts
scripts/

# Example
example/

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We use `flow` for type check, `eslint` with `prettier` for linting/formatting, `
* `yarn test`: Run all tests, except for e2e (see note below).
* `yarn test:lint`: Run `eslint` check.
* `yarn test:flow`: Run `flow` type check.
* `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>`.
* `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>`.


## Sending a pull request
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ $ cd ios/ && pod install

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

*Note* For `macOS` the [manual linking](docs/Linking.md) is currently the only linking option.

### **Upgrading to React Native *0.60+***

New React Native comes with `autolinking` feature, which automatically links Native Modules in your project.
Expand Down
11 changes: 11 additions & 0 deletions docs/Linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@

3. Run `pod install`

## macOS

#### Project linking
1. Open your project `.xcodeproj` on xcode.

2. Right click on the Libraries folder and select `Add files to "yourProjectName"`.

3. Add `RNCAsyncStorage.xcodeproj` (located at `node_modules/@react-native-community/async-storage/macos`) to your project Libraries.

4. Go to `Build Phases -> Link Binary with Libraries` and add: `libRNCAsyncStorage-macOS.a`.


## Android
1. Add project to `android/settings.gradle`:
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/BrownfieldIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
## iOS and macOS

AsyncStorage can be controlled by the hosting app via the delegate on
`RNCAsyncStorage`:
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/IncreaseDbSize.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ AsyncStorage_db_size_in_MB=10
Now you can define the new size in MB. In this example, the new limit is 10 MB.


## iOS
## iOS and macOS

Async Storage size is not limited programmatically on iOS.
17 changes: 17 additions & 0 deletions example/macos/AsyncStorageExample-macOS/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 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 <Cocoa/Cocoa.h>

@class RCTBridge;

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (nonatomic, readonly) RCTBridge *bridge;
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *memoryStorage;

@end
59 changes: 59 additions & 0 deletions example/macos/AsyncStorageExample-macOS/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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 "RNCTestAsyncStorageDelegate.h"
#import <RNCAsyncStorage/RNCAsyncStorage.h>

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>

@interface AppDelegate () <RCTBridgeDelegate>

@end

@implementation AppDelegate {
RNCTestAsyncStorageDelegate *_testDelegate;
}

- (void)awakeFromNib {
[super awakeFromNib];

_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];

_memoryStorage = [NSMutableDictionary dictionary];
}

- (void)application:(NSApplication *)application openURLs:(NSArray<NSURL *> *)urls {
NSURL *url = [urls firstObject];

if (![url.scheme isEqualToString:@"rnc-asyncstorage"]) {
return;
}

if ([url.host isEqualToString:@"set-delegate"]) {
if (_testDelegate == nil) {
_testDelegate = [RNCTestAsyncStorageDelegate new];
}
RNCAsyncStorage *asyncStorage = [_bridge moduleForClass:[RNCAsyncStorage class]];
asyncStorage.delegate = _testDelegate;
} else if ([url.host isEqualToString:@"unset-delegate"]) {
RNCAsyncStorage *asyncStorage = [_bridge moduleForClass:[RNCAsyncStorage class]];
asyncStorage.delegate = nil;
} else if ([url.host isEqualToString:@"clear-all-data"]) {
[RNCAsyncStorage clearAllData];
}
}

#pragma mark - RCTBridgeDelegate Methods

- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge {
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"example/index" fallbackResource:@"main"]; // .jsbundle;
}

@end
50 changes: 50 additions & 0 deletions example/macos/AsyncStorageExample-macOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>org.reactjs.native.example.AsyncStorageExample</string>
<key>CFBundleURLSchemes</key>
<array>
<string>rnc-asyncstorage</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 Facebook. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Loading