From e2e4d881ab8e52066d104ee5c668145eae7a2824 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Wed, 14 Oct 2020 12:33:30 +0200 Subject: [PATCH 1/2] chore: Bump RN to 0.62 We only bump to 0.62 because react-native-macos 0.63 isn't out yet. To simplify our lives, we stay in sync to avoid any potential issues from having both 0.62 and 0.63 installed. --- .flowconfig | 10 +- example/.gitignore | 1 + example/__tests__/App.js | 24 +- example/app.json | 9 +- example/examples/GetSetClear.js | 92 +- example/examples/MergeItem.js | 13 +- .../project.pbxproj | 4 +- example/ios/Podfile | 12 +- .../macos/AsyncStorageExample-UITests.podspec | 24 + .../AsyncStorageExample-macOS/AppDelegate.h | 17 - .../AsyncStorageExample-macOS/AppDelegate.m | 59 - .../AsyncStorageExample-macOS/Info.plist | 50 - .../AsyncStorageExample-macOS/Main.storyboard | 713 --- .../ViewController.h | 12 - .../ViewController.m | 29 - .../macos/AsyncStorageExample-macOS/main.m | 12 - .../Info.plist | 22 - .../project.pbxproj | 1720 ------ .../AsyncStorageExample-macOS.xcscheme | 102 - .../AsyncStorageExample-tvOS.xcscheme | 129 - .../xcschemes/AsyncStorageExample.xcscheme | 125 - .../contents.xcworkspacedata | 10 + .../xcshareddata/IDEWorkspaceChecks.plist} | 6 +- example/macos/Podfile | 17 + example/windows/AsyncStorageExample.sln | 2 +- .../AsyncStorageExample.vcxproj | 3 +- jest/async-storage-mock.js | 14 +- metro.config.macos.js | 4 +- package.json | 31 +- react-native.config.js | 29 +- scripts/run_macos_e2e.sh | 7 +- src/AsyncStorage.native.js | 52 +- src/RCTAsyncStorage.expo.js | 2 +- src/RCTAsyncStorage.js | 2 +- yarn.lock | 4950 +++++++++-------- 35 files changed, 2973 insertions(+), 5335 deletions(-) create mode 100644 example/macos/AsyncStorageExample-UITests.podspec delete mode 100644 example/macos/AsyncStorageExample-macOS/AppDelegate.h delete mode 100644 example/macos/AsyncStorageExample-macOS/AppDelegate.m delete mode 100644 example/macos/AsyncStorageExample-macOS/Info.plist delete mode 100644 example/macos/AsyncStorageExample-macOS/Main.storyboard delete mode 100644 example/macos/AsyncStorageExample-macOS/ViewController.h delete mode 100644 example/macos/AsyncStorageExample-macOS/ViewController.m delete mode 100644 example/macos/AsyncStorageExample-macOS/main.m delete mode 100644 example/macos/AsyncStorageExample-macOSUITests/Info.plist delete mode 100644 example/macos/AsyncStorageExample.xcodeproj/project.pbxproj delete mode 100644 example/macos/AsyncStorageExample.xcodeproj/xcshareddata/xcschemes/AsyncStorageExample-macOS.xcscheme delete mode 100644 example/macos/AsyncStorageExample.xcodeproj/xcshareddata/xcschemes/AsyncStorageExample-tvOS.xcscheme delete mode 100644 example/macos/AsyncStorageExample.xcodeproj/xcshareddata/xcschemes/AsyncStorageExample.xcscheme create mode 100644 example/macos/AsyncStorageExample.xcworkspace/contents.xcworkspacedata rename example/macos/{AsyncStorageExample.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings => AsyncStorageExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist} (66%) create mode 100644 example/macos/Podfile diff --git a/.flowconfig b/.flowconfig index f69a9009..6abbe180 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,4 +1,7 @@ [ignore] +; Build output +/lib/ + ; We fork some components by platform .*/*[.]android.js @@ -21,7 +24,7 @@ node_modules/warning/.* [include] [libs] -node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/interface.js node_modules/react-native/flow/ [options] @@ -41,9 +44,8 @@ server.max_workers=1 # Support the library import in examples module.name_mapper='^\@react-native-async-storage/async-storage$' -> '/src/AsyncStorage.js' -module.name_mapper='^react-native$' -> '/node_modules/react-native/Libraries/react-native/react-native-implementation' module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' -module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' +module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' suppress_type=$FlowIssue suppress_type=$FlowFixMe @@ -77,4 +79,4 @@ untyped-import untyped-type-import [version] -^0.105.0 +^0.113.0 diff --git a/example/.gitignore b/example/.gitignore index 2033db00..22f263aa 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -57,4 +57,5 @@ buck-out/ # CocoaPods /ios/Pods/ +/macos/Pods/ Podfile.lock diff --git a/example/__tests__/App.js b/example/__tests__/App.js index fb918122..4415462f 100644 --- a/example/__tests__/App.js +++ b/example/__tests__/App.js @@ -79,17 +79,17 @@ describe('Async Storage mock functionality', () => { }); describe('Callback based', () => { - it('can read/write data to/from storage', done => { + it('can read/write data to/from storage', (done) => { const newData = Math.floor(Math.random() * 1000); - AsyncStorage.setItem('key', newData, function() { - AsyncStorage.getItem('key', function(_, value) { + AsyncStorage.setItem('key', newData, function () { + AsyncStorage.getItem('key', function (_, value) { expect(value).toBe(newData); done(); - }).catch(e => done.fail(e)); + }).catch((e) => done.fail(e)); }); }); - it('can clear storage', done => { + it('can clear storage', (done) => { AsyncStorage.setItem('temp_key', Math.random() * 1000, () => { AsyncStorage.getItem('temp_key', (_, currentValue) => { expect(currentValue).not.toBeNull(); @@ -97,13 +97,13 @@ describe('Async Storage mock functionality', () => { AsyncStorage.getItem('temp_key', (_, value) => { expect(value).toBeNull(); done(); - }).catch(e => done.fail(e)); + }).catch((e) => done.fail(e)); }); - }).catch(e => done.fail(e)); + }).catch((e) => done.fail(e)); }); }); - it('can clear entries in storage', done => { + it('can clear entries in storage', (done) => { AsyncStorage.setItem('random1', Math.random() * 1000, () => { AsyncStorage.setItem('random2', Math.random() * 1000, () => { AsyncStorage.getItem('random1', (_, data1) => { @@ -118,17 +118,17 @@ describe('Async Storage mock functionality', () => { expect(value1).toBeNull(); expect(value2).toBeNull(); done(); - }).catch(e => done.fail(e)); + }).catch((e) => done.fail(e)); }); }); }); - }).catch(e => done.fail(e)); + }).catch((e) => done.fail(e)); }); }); }); }); - it('can use merge with current data in storage', done => { + it('can use merge with current data in storage', (done) => { let originalPerson = { name: 'Jerry', age: 21, @@ -149,7 +149,7 @@ describe('Async Storage mock functionality', () => { expect(person.characteristics).toHaveProperty('hair', 'red'); expect(person.characteristics).toHaveProperty('shoeSize', 40); done(); - }).catch(e => done.fail(e)); + }).catch((e) => done.fail(e)); }); }); }); diff --git a/example/app.json b/example/app.json index de5021de..8d6c1faa 100644 --- a/example/app.json +++ b/example/app.json @@ -1,4 +1,9 @@ { "name": "AsyncStorageExample", - "displayName": "AsyncStorageExample" -} \ No newline at end of file + "displayName": "AsyncStorageExample", + "components": [ + { + "appKey": "AsyncStorageExample" + } + ] +} diff --git a/example/examples/GetSetClear.js b/example/examples/GetSetClear.js index fa88cd17..6cc1853c 100644 --- a/example/examples/GetSetClear.js +++ b/example/examples/GetSetClear.js @@ -8,76 +8,60 @@ * @flow */ -import React, {Component} from 'react'; +import React from 'react'; import {StyleSheet, Text, View, Button} from 'react-native'; import AsyncStorage from '@react-native-async-storage/async-storage'; -type Props = {}; -type State = { - storedNumber: string, - needRestart: boolean, -}; -export default class GetSet extends Component { - state = { - storedNumber: '', - needRestart: false, - }; +export default function GetSet() { + const [storedNumber, setStoredNumber] = React.useState(''); + const [needsRestart, setNeedsRestart] = React.useState(false); - async componentWillMount() { - const storedNumber = await AsyncStorage.getItem(STORAGE_KEY); - if (storedNumber) { - this.setState({ - storedNumber, - }); - } - } - - increaseByTen = async () => { - const {storedNumber} = this.state; + React.useEffect(() => { + AsyncStorage.getItem(STORAGE_KEY).then((value) => { + if (value) { + setStoredNumber(value); + } + }); + }, []); + const increaseByTen = React.useCallback(async () => { const newNumber = +storedNumber > 0 ? +storedNumber + 10 : 10; await AsyncStorage.setItem(STORAGE_KEY, `${newNumber}`); - this.setState({storedNumber: `${newNumber}`, needRestart: true}); - }; + setStoredNumber(`${newNumber}`); + setNeedsRestart(true); + }, [setNeedsRestart, setStoredNumber, storedNumber]); - clearItem = async () => { + const clearItem = React.useCallback(async () => { await AsyncStorage.removeItem(STORAGE_KEY); - - this.setState({needRestart: true}); - }; - - render() { - const {storedNumber, needRestart} = this.state; - return ( - - Currently stored: - - {storedNumber} - - -