From 4115f2e6e9608127bd8a77094de25b2228932a04 Mon Sep 17 00:00:00 2001 From: erezrokah Date: Mon, 12 Aug 2019 12:35:17 +0300 Subject: [PATCH 1/3] update to react-native 0.59.0, add prettier, eslint, flow --- .vscode/settings.json | 1 + example/.babelrc | 3 - example/.eslintrc.js | 16 + example/.flowconfig | 3 +- example/.prettierrc | 14 + example/{app/index.js => App.js} | 219 +- .../{index.android.js => App-test.js} | 15 +- example/__tests__/index.ios.js | 12 - example/android/app/BUCK | 19 +- example/android/app/build.gradle | 13 +- example/android/app/build_defs.bzl | 17 + .../android/app/src/debug/AndroidManifest.xml | 6 + .../src/debug/res/xml/react_native_config.xml | 8 + .../android/app/src/main/AndroidManifest.xml | 4 +- example/android/build.gradle | 22 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/babel.config.js | 3 + example/index.js | 11 +- example/ios/example.xcodeproj/project.pbxproj | 8 + example/ios/example/AppDelegate.h | 5 +- example/ios/example/AppDelegate.m | 28 +- example/ios/example/main.m | 2 +- example/ios/exampleTests/exampleTests.m | 2 +- example/metro.config.js | 16 + example/package.json | 31 +- example/yarn.lock | 4756 +++++++++++------ 26 files changed, 3340 insertions(+), 1896 deletions(-) delete mode 100644 example/.babelrc create mode 100644 example/.eslintrc.js create mode 100644 example/.prettierrc rename example/{app/index.js => App.js} (50%) rename example/__tests__/{index.android.js => App-test.js} (51%) delete mode 100644 example/__tests__/index.ios.js create mode 100644 example/android/app/build_defs.bzl create mode 100644 example/android/app/src/debug/AndroidManifest.xml create mode 100644 example/android/app/src/debug/res/xml/react_native_config.xml create mode 100644 example/babel.config.js create mode 100644 example/metro.config.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 0db377a..a14db86 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "typescript.validate.enable": false, "javascript.validate.enable": false, + "editor.formatOnSave": true, } \ No newline at end of file diff --git a/example/.babelrc b/example/.babelrc deleted file mode 100644 index d4b74b5..0000000 --- a/example/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["module:metro-react-native-babel-preset"] -} diff --git a/example/.eslintrc.js b/example/.eslintrc.js new file mode 100644 index 0000000..8154e69 --- /dev/null +++ b/example/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + extends: ['airbnb', 'prettier', 'prettier/react'], + parser: 'babel-eslint', + env: { + jest: true, + }, + rules: { + 'no-use-before-define': 'off', + 'react/jsx-filename-extension': 'off', + 'react/prop-types': 'off', + 'comma-dangle': 'off', + }, + globals: { + fetch: false, + }, +}; diff --git a/example/.flowconfig b/example/.flowconfig index 1043c82..47d80d9 100644 --- a/example/.flowconfig +++ b/example/.flowconfig @@ -24,7 +24,6 @@ [libs] node_modules/react-native/Libraries/react-native/react-native-interface.js node_modules/react-native/flow/ -node_modules/react-native/flow-github/ [options] emoji=true @@ -67,4 +66,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError [version] -^0.78.0 +^0.92.0 diff --git a/example/.prettierrc b/example/.prettierrc new file mode 100644 index 0000000..e52ad05 --- /dev/null +++ b/example/.prettierrc @@ -0,0 +1,14 @@ +{ + "printWidth": 80, + "tabWidth": 2, + "semi": true, + "singleQuote": true, + "trailingComma": "all", + "useTabs": false, + "overrides": [ + { + "files": "*.json", + "options": { "printWidth": 200 } + } + ] +} diff --git a/example/app/index.js b/example/App.js similarity index 50% rename from example/app/index.js rename to example/App.js index 548a900..f8e407c 100644 --- a/example/app/index.js +++ b/example/App.js @@ -1,7 +1,9 @@ -// @flow -import React, { Component } from 'react' +/** + * @flow + * @format + */ +import React, { Component } from 'react'; import { - AppRegistry, StyleSheet, Text, View, @@ -10,118 +12,119 @@ import { Dimensions, Platform, Alert, -} from 'react-native' -import RNSettings from 'react-native-settings' +} from 'react-native'; +import RNSettings from 'react-native-settings'; type State = { location_on: boolean, airplane_on: boolean, -} - -type Props = {} +}; const Screen = { width: Dimensions.get('window').width, height: Dimensions.get('window').height, -} +}; export default class example extends Component { - state: State - - constructor(props: Props) { - super(props) - this.state = { location_on: false, airplane_on: false } - } - - _handleGPSProviderEvent = e => { - if (e[RNSettings.LOCATION_SETTING] === RNSettings.ENABLED) { - this.setState({ location_on: true }) - } else { - this.setState({ location_on: false }) - } - } - - _handleAirplaneModeEvent = e => { - if (e[RNSettings.AIRPLANE_MODE_SETTING] === RNSettings.ENABLED) { - this.setState({ airplane_on: true }) - } else { - this.setState({ airplane_on: false }) - } - } + state: State; - _openLocationSetting = () => { - if (Platform.OS === 'ios') { - Alert.alert( - 'Not supported!', - 'Not supported on IOS just yet. Stay tuned ~_~' - ) - return - } - RNSettings.openSetting( - RNSettings.ACTION_LOCATION_SOURCE_SETTINGS - ).then(result => { - if (result === RNSettings.ENABLED) { - this.setState({ location_on: true }) - } else { - this.setState({ location_on: false }) - } - }) - } - _openAirplaneSetting = () => { - if (Platform.OS === 'ios') { - Alert.alert( - 'Not supported!', - 'Not supported on IOS just yet. Stay tuned ~_~' - ) - return - } - RNSettings.openSetting( - RNSettings.ACTION_AIRPLANE_MODE_SETTINGS - ).then(result => { - if (result === RNSettings.ENABLED) { - this.setState({ airplane_on: true }) - } else { - this.setState({ airplane_on: false }) - } - }) - } + state = { locationOn: false, airplaneOn: false }; componentDidMount() { RNSettings.getSetting(RNSettings.LOCATION_SETTING).then(result => { if (result === RNSettings.ENABLED) { - this.setState({ location_on: true }) + this.setState({ locationOn: true }); } else { - this.setState({ location_on: false }) + this.setState({ locationOn: false }); } - }) + }); if (Platform.OS === 'android') { RNSettings.getSetting(RNSettings.AIRPLANE_MODE_SETTING).then(result => { if (result === RNSettings.ENABLED) { - this.setState({ airplane_on: true }) + this.setState({ airplaneOn: true }); } else { - this.setState({ airplane_on: false }) + this.setState({ airplaneOn: false }); } - }) + }); // Register to gps provider change event DeviceEventEmitter.addListener( RNSettings.GPS_PROVIDER_EVENT, - this._handleGPSProviderEvent - ) + this.handleGPSProviderEvent, + ); // Register to airplane mode change event DeviceEventEmitter.addListener( RNSettings.AIRPLANE_MODE_EVENT, - this._handleAirplaneModeEvent - ) + this.handleAirplaneModeEvent, + ); } } + handleGPSProviderEvent = e => { + if (e[RNSettings.LOCATION_SETTING] === RNSettings.ENABLED) { + this.setState({ locationOn: true }); + } else { + this.setState({ locationOn: false }); + } + }; + + handleAirplaneModeEvent = e => { + if (e[RNSettings.AIRPLANE_MODE_SETTING] === RNSettings.ENABLED) { + this.setState({ airplaneOn: true }); + } else { + this.setState({ airplaneOn: false }); + } + }; + + openLocationSetting = () => { + if (Platform.OS === 'ios') { + Alert.alert( + 'Not supported!', + 'Not supported on IOS just yet. Stay tuned ~_~', + ); + return; + } + RNSettings.openSetting(RNSettings.ACTION_LOCATION_SOURCE_SETTINGS).then( + result => { + if (result === RNSettings.ENABLED) { + this.setState({ locationOn: true }); + } else { + this.setState({ locationOn: false }); + } + }, + ); + }; + + openAirplaneSetting = () => { + if (Platform.OS === 'ios') { + Alert.alert( + 'Not supported!', + 'Not supported on IOS just yet. Stay tuned ~_~', + ); + return; + } + RNSettings.openSetting(RNSettings.ACTION_AIRPLANE_MODE_SETTINGS).then( + result => { + if (result === RNSettings.ENABLED) { + this.setState({ airplaneOn: true }); + } else { + this.setState({ airplaneOn: false }); + } + }, + ); + }; + render() { const asterisk = - Platform.OS === 'ios' - ? * Not supported yet on iOS. - : + Platform.OS === 'ios' ? ( + * Not supported yet on iOS. + ) : ( + + ); + + const { locationOn, airplaneOn } = this.state; + return ( @@ -129,21 +132,21 @@ export default class example extends Component { {asterisk} - ) + ); } } @@ -153,31 +156,35 @@ type SettingRowProps = { onAvailable: boolean, onPress: () => void, onPressAvailable: boolean, -} - -SettingRow = (props: SettingRowProp) => { - let status = - if (props.onAvailable) { - status = props.on - ? ON - : OFF +}; + +const SettingRow = ({ + name, + onAvailable, + onPressAvailable, + onPress, + on, +}: SettingRowProps) => { + let status = ; + + if (onAvailable) { + status = on ? ( + ON + ) : ( + OFF + ); } else { - status = N/A* + status = N/A*; } return ( - - {props.name}: - + {name}: {status} -