From 435b137290b9e66025137ae0f94bcac15670e7b3 Mon Sep 17 00:00:00 2001 From: Andy Stanberry Date: Sat, 18 Aug 2018 22:46:39 -0400 Subject: [PATCH] Add prettier, format files --- .eslintrc | 14 +- .prettierrc | 6 + package.json | 7 +- .../EventEmitter/EmitterSubscription.js | 1 - src/Libraries/EventEmitter/EventEmitter.js | 40 +-- .../EventEmitter/EventSubscriptionVendor.js | 4 +- .../NavigationExperimental/NavigationCard.js | 6 +- .../NavigationStateUtils.js | 10 +- src/NativeModules/ActionSheetManager.js | 9 +- src/NativeModules/AlertManager.js | 4 +- src/NativeModules/AppState.js | 4 +- src/NativeModules/CameraRollManager.js | 26 +- src/NativeModules/DatePickerAndroid.js | 2 +- src/NativeModules/DeviceEventManager.js | 4 +- src/NativeModules/LinkingManager.js | 2 +- src/NativeModules/ScrollViewManager.js | 31 +- src/NativeModules/SourceCode.js | 4 +- src/NativeModules/TestModule.js | 8 +- src/NativeModules/TimePickerAndroid.js | 6 +- src/NativeModules/Timing.js | 8 +- src/NativeModules/UIManager.js | 77 ++--- src/NativeModules/Vibration.js | 4 +- src/NativeModules/WebViewManager.js | 19 +- src/NativeModules/index.js | 1 - src/api/ActionSheetIOS.js | 29 +- src/api/Alert.js | 4 +- src/api/AlertIOS.js | 21 +- src/api/Animated/AnimatedImplementation.js | 309 ++++++++++-------- src/api/Animated/Easing.js | 14 +- src/api/Animated/SpringConfig.js | 22 +- src/api/Animated/createAnimatedComponent.js | 13 +- src/api/AppRegistry.js | 14 +- src/api/AppState.js | 33 +- src/api/AppStateIOS.js | 46 ++- src/api/AsyncStorage.js | 6 +- src/api/BackAndroid.js | 6 +- src/api/CameraRoll.js | 5 +- src/api/DatePickerAndroid.js | 8 +- src/api/Dimensions.js | 12 +- src/api/ImagePickerIOS.js | 13 +- src/api/IntentAndroid.js | 7 +- src/api/InteractionManager.js | 7 +- src/api/Keyboard.js | 4 +- src/api/LayoutAnimation.js | 35 +- src/api/Linking.js | 32 +- src/api/LinkingIOS.js | 10 +- src/api/ListViewDataSource.js | 6 +- src/api/NetInfo.js | 19 +- src/api/PanResponder.js | 59 ++-- src/api/PixelRatio.js | 4 +- src/api/PushNotificationIOS.js | 51 +-- src/api/Settings.js | 10 +- src/api/StatusBarIOS.js | 1 - src/api/StyleSheet.js | 2 +- src/api/TextInputState.js | 3 +- src/api/TimePickerAndroid.js | 9 +- src/api/TouchHistoryMath.js | 58 ++-- src/api/VibrationIOS.js | 7 +- src/components/ART/Path.js | 2 +- src/components/ART/Transform.js | 1 - src/components/ActivityIndicator.js | 5 +- src/components/ActivityIndicatorIOS.js | 5 +- src/components/DrawerLayoutAndroid.js | 9 +- src/components/FlatList.js | 98 +++--- src/components/Image.js | 10 +- src/components/ImageBackground.js | 10 +- src/components/ListView.js | 12 +- src/components/Navigator.js | 10 +- src/components/Picker.js | 6 +- src/components/ScrollView.js | 12 +- src/components/StatusBar.js | 7 +- src/components/TabBarIOS.js | 6 +- src/components/Text.js | 2 +- src/components/TextInput.js | 16 +- src/components/TouchableNativeFeedback.js | 6 +- src/components/TouchableWithoutFeedback.js | 6 +- src/components/View.js | 15 +- src/components/VirtualizedList.js | 260 ++++++++------- src/components/createMockComponent.js | 8 +- src/mixins/NativeMethodsMixin.js | 20 +- src/mixins/ScrollResponder.js | 55 +++- src/mixins/Subscribable.js | 12 +- src/propTypes/ColorPropType.js | 2 +- src/propTypes/ImageResizeMode.js | 6 +- src/propTypes/LayoutPropTypes.js | 149 ++------- src/propTypes/StyleSheetPropType.js | 2 +- src/propTypes/TextStylePropTypes.js | 54 +-- src/propTypes/TransformPropTypes.js | 35 +- src/propTypes/ViewPropTypes.js | 18 +- src/react-native.js | 7 +- src/requireLibrary.js | 1 - test/StyleSheet.js | 33 +- test/api/Animated.js | 10 +- test/api/CameraRoll.js | 30 +- test/api/Dimensions.js | 10 +- test/api/NetInfo.js | 9 +- test/components/DrawerLayoutAndroid.js | 10 +- test/components/Picker.js | 2 +- test/components/TabBarIOS.js | 2 +- test/components/View.js | 10 +- test/mixins/Subscribable.js | 8 +- test/react-native-test.js | 6 +- test/setup-tests.js | 10 +- yarn.lock | 14 + 104 files changed, 1014 insertions(+), 1183 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index 7ebf40f..87fd12f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,6 @@ { - "extends": "airbnb", - "plugins": [ + "extends": ["airbnb", "prettier"], + "plugins": [ "react", "react-native" ], @@ -21,14 +21,6 @@ "no-restricted-syntax": 0, "prefer-template": 0, "no-console": 0, - "react/prefer-stateless-function": 0, - "max-len": [ - 2, - 120, - 2, - { - "ignoreComments": true - } - ] + "react/prefer-stateless-function": 0 } } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..4af0646 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "bracketSpacing": false, + "jsxBracketSameLine": true +} diff --git a/package.json b/package.json index 101ae84..74a9b25 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,12 @@ "main": "build/react-native.js", "scripts": { "prepublish": "npm run build", - "test": "npm run lint && npm run mocha", + "test": "npm run lint && prettier \"./**/*.js\" --list-different && npm run mocha", "mocha": "mocha --require test/setup-tests.js --require babel-core/register 'test/**/*.js'", "mocha:watch": "npm run test -- --watch", "build": "babel src --out-dir build", - "lint": "./node_modules/.bin/eslint 'src/' 'test/' 'mock.js'" + "lint": "./node_modules/.bin/eslint 'src/' 'test/' 'mock.js'", + "prettier": "prettier \"./**/*.js\" --write" }, "repository": { "type": "git", @@ -38,12 +39,14 @@ "enzyme-adapter-react-16": "^1.0.0", "eslint": "2.10.2", "eslint-config-airbnb": "9.0.1", + "eslint-config-prettier": "2.9.0", "eslint-plugin-import": "1.8.0", "eslint-plugin-jsx-a11y": "1.2.2", "eslint-plugin-react": "5.1.1", "eslint-plugin-react-native": "1.0.2", "jsdom": "^11.3.0", "mocha": "^3.0.2", + "prettier": "1.14.2", "react": "16.0.0-beta.5", "react-native": "^0.49.3", "react-test-renderer": "^16.0.0", diff --git a/src/Libraries/EventEmitter/EmitterSubscription.js b/src/Libraries/EventEmitter/EmitterSubscription.js index f7140e9..e6c2047 100644 --- a/src/Libraries/EventEmitter/EmitterSubscription.js +++ b/src/Libraries/EventEmitter/EmitterSubscription.js @@ -13,7 +13,6 @@ const EventSubscription = require('./EventSubscription'); * EmitterSubscription represents a subscription with listener and context data. */ class EmitterSubscription extends EventSubscription { - /** * @param {EventEmitter} emitter - The event emitter that registered this * subscription diff --git a/src/Libraries/EventEmitter/EventEmitter.js b/src/Libraries/EventEmitter/EventEmitter.js index 315f575..0311570 100644 --- a/src/Libraries/EventEmitter/EventEmitter.js +++ b/src/Libraries/EventEmitter/EventEmitter.js @@ -50,10 +50,10 @@ class EventEmitter { * listener */ addListener(eventType, listener, context) { - return (this._subscriber.addSubscription( + return this._subscriber.addSubscription( eventType, - new EmitterSubscription(this, this._subscriber, listener, context) - )); + new EmitterSubscription(this, this._subscriber, listener, context), + ); } /** @@ -96,11 +96,11 @@ class EventEmitter { * * @example * var subscription = emitter.addListenerMap({ - * someEvent: function(data, event) { - * console.log(data); - * emitter.removeCurrentListener(); - * } - * }); + * someEvent: function(data, event) { + * console.log(data); + * emitter.removeCurrentListener(); + * } + * }); * * emitter.emit('someEvent', 'abc'); // logs 'abc' * emitter.emit('someEvent', 'def'); // does not log anything @@ -108,7 +108,7 @@ class EventEmitter { removeCurrentListener() { invariant( !!this._currentSubscription, - 'Not in an emitting cycle; there is no current subscription' + 'Not in an emitting cycle; there is no current subscription', ); this.removeSubscription(this._currentSubscription); } @@ -120,7 +120,7 @@ class EventEmitter { removeSubscription(subscription) { invariant( subscription.emitter === this, - 'Subscription does not belong to this emitter.' + 'Subscription does not belong to this emitter.', ); this._subscriber.removeSubscription(subscription); } @@ -133,8 +133,10 @@ class EventEmitter { * @returns {array} */ listeners(eventType) { - const subscriptions = (this._subscriber.getSubscriptionsForType(eventType)); - return subscriptions ? subscriptions.map(subscription => subscription.listener) : []; + const subscriptions = this._subscriber.getSubscriptionsForType(eventType); + return subscriptions + ? subscriptions.map(subscription => subscription.listener) + : []; } /** @@ -146,13 +148,13 @@ class EventEmitter { * * @example * emitter.addListener('someEvent', function(message) { - * console.log(message); - * }); + * console.log(message); + * }); * * emitter.emit('someEvent', 'abc'); // logs 'abc' */ emit(eventType) { - const subscriptions = (this._subscriber.getSubscriptionsForType(eventType)); + const subscriptions = this._subscriber.getSubscriptionsForType(eventType); if (subscriptions) { for (let i = 0, l = subscriptions.length; i < l; i++) { const subscription = subscriptions[i]; @@ -162,7 +164,7 @@ class EventEmitter { this._currentSubscription = subscription; subscription.listener.apply( subscription.context, - Array.prototype.slice.call(arguments, 1) + Array.prototype.slice.call(arguments, 1), ); } } @@ -179,12 +181,12 @@ class EventEmitter { * * @example * emitter.removeListener('someEvent', function(message) { - * console.log(message); - * }); // removes the listener if already registered + * console.log(message); + * }); // removes the listener if already registered * */ removeListener(eventType, listener) { - const subscriptions = (this._subscriber.getSubscriptionsForType(eventType)); + const subscriptions = this._subscriber.getSubscriptionsForType(eventType); if (subscriptions) { for (let i = 0, l = subscriptions.length; i < l; i++) { const subscription = subscriptions[i]; diff --git a/src/Libraries/EventEmitter/EventSubscriptionVendor.js b/src/Libraries/EventEmitter/EventSubscriptionVendor.js index 4c18c3c..b579f6d 100644 --- a/src/Libraries/EventEmitter/EventSubscriptionVendor.js +++ b/src/Libraries/EventEmitter/EventSubscriptionVendor.js @@ -14,7 +14,6 @@ const invariant = require('invariant'); * subscribed to a particular event type. */ class EventSubscriptionVendor { - constructor() { this._subscriptionsForType = {}; this._currentSubscription = null; @@ -30,7 +29,8 @@ class EventSubscriptionVendor { /* eslint-disable no-param-reassign */ invariant( subscription.subscriber === this, - 'The subscriber of the subscription is incorrectly set.'); + 'The subscriber of the subscription is incorrectly set.', + ); if (!this._subscriptionsForType[eventType]) { this._subscriptionsForType[eventType] = []; } diff --git a/src/Libraries/NavigationExperimental/NavigationCard.js b/src/Libraries/NavigationExperimental/NavigationCard.js index 01563d6..2323f53 100644 --- a/src/Libraries/NavigationExperimental/NavigationCard.js +++ b/src/Libraries/NavigationExperimental/NavigationCard.js @@ -1,10 +1,8 @@ import React from 'react'; -class CardStackPanResponder { -} +class CardStackPanResponder {} -class PagerPanResponder { -} +class PagerPanResponder {} class NavigationCard extends React.Component { static CardStackPanResponder = CardStackPanResponder; diff --git a/src/Libraries/NavigationExperimental/NavigationStateUtils.js b/src/Libraries/NavigationExperimental/NavigationStateUtils.js index d0c2f50..f5b2693 100644 --- a/src/Libraries/NavigationExperimental/NavigationStateUtils.js +++ b/src/Libraries/NavigationExperimental/NavigationStateUtils.js @@ -15,10 +15,7 @@ function push(state, route) { throw new Error('should not push route with duplicated key ' + route.key); } - const routes = [ - ...state.routes, - route, - ]; + const routes = [...state.routes, route]; return { ...state, @@ -54,7 +51,6 @@ function jumpToIndex(state, index: number) { }; } - function jumpTo(state, key) { const index = indexOf(state, key); return jumpToIndex(state, index); @@ -62,7 +58,9 @@ function jumpTo(state, key) { function replaceAtIndex(state, index, route) { if (!state.routes[index]) { - throw new Error('invalid index ' + index + ' for replacing route ' + route.key); + throw new Error( + 'invalid index ' + index + ' for replacing route ' + route.key, + ); } if (state.routes[index] === route) { diff --git a/src/NativeModules/ActionSheetManager.js b/src/NativeModules/ActionSheetManager.js index 24c3a2f..b6e9c56 100644 --- a/src/NativeModules/ActionSheetManager.js +++ b/src/NativeModules/ActionSheetManager.js @@ -1,11 +1,6 @@ - const ActionSheetManager = { - showActionSheetWithOptions(options, callback) { - - }, - showShareActionSheetWithOptions(options, failure, success) { - - }, + showActionSheetWithOptions(options, callback) {}, + showShareActionSheetWithOptions(options, failure, success) {}, }; module.exports = ActionSheetManager; diff --git a/src/NativeModules/AlertManager.js b/src/NativeModules/AlertManager.js index 3a1ea6b..16b08aa 100644 --- a/src/NativeModules/AlertManager.js +++ b/src/NativeModules/AlertManager.js @@ -2,9 +2,7 @@ * https://github.com/facebook/react-native/blob/master/React/Modules/RCTAlertManager.m */ const AlertManager = { - alertWithArgs(args, callback) { - - }, + alertWithArgs(args, callback) {}, }; module.exports = AlertManager; diff --git a/src/NativeModules/AppState.js b/src/NativeModules/AppState.js index dfd705b..1063c35 100644 --- a/src/NativeModules/AppState.js +++ b/src/NativeModules/AppState.js @@ -8,11 +8,11 @@ DeviceEventEmitter.on('appStateDidChange', data => { const AppState = { getCurrentAppState(callback, error) { - Promise.resolve({ _appState }).then(callback); + Promise.resolve({_appState}).then(callback); }, __setAppState(appState) { - DeviceEventEmitter.emit('appStateDidChange', { _appState: appState }); + DeviceEventEmitter.emit('appStateDidChange', {_appState: appState}); }, }; diff --git a/src/NativeModules/CameraRollManager.js b/src/NativeModules/CameraRollManager.js index 99445df..9916a63 100644 --- a/src/NativeModules/CameraRollManager.js +++ b/src/NativeModules/CameraRollManager.js @@ -12,10 +12,10 @@ const CameraRollManager = { image: { uri: 'content://media/external/images/media/1', height: 2448, - width: 3968 + width: 3968, }, - timestamp: 1528972673375 - } + timestamp: 1528972673375, + }, }, { node: { @@ -24,10 +24,10 @@ const CameraRollManager = { image: { uri: 'content://media/external/images/media/2', height: 2448, - width: 3968 + width: 3968, }, - timestamp: 1528972673375 - } + timestamp: 1528972673375, + }, }, { node: { @@ -36,18 +36,18 @@ const CameraRollManager = { image: { uri: 'content://media/external/images/media/3', height: 2448, - width: 3968 + width: 3968, }, - timestamp: 1528972673375 - } - } + timestamp: 1528972673375, + }, + }, ], page_info: { has_next_page: true, - end_cursor: '1528919312601' - } + end_cursor: '1528919312601', + }, }); - } + }, }; module.exports = CameraRollManager; diff --git a/src/NativeModules/DatePickerAndroid.js b/src/NativeModules/DatePickerAndroid.js index 3b9bb67..cef7fdb 100644 --- a/src/NativeModules/DatePickerAndroid.js +++ b/src/NativeModules/DatePickerAndroid.js @@ -1,7 +1,7 @@ // TODO(lmr): figure out a good way to have separate responses like "dismissed" vs "set". const DatePickerAndroid = { open(options) { - return Promise.resolve().then({ action: 'dismissedAction' }); + return Promise.resolve().then({action: 'dismissedAction'}); }, }; diff --git a/src/NativeModules/DeviceEventManager.js b/src/NativeModules/DeviceEventManager.js index 1b7fc91..59b3b64 100644 --- a/src/NativeModules/DeviceEventManager.js +++ b/src/NativeModules/DeviceEventManager.js @@ -1,7 +1,5 @@ const DeviceEventManager = { - invokeDefaultBackPressHandler() { - - }, + invokeDefaultBackPressHandler() {}, }; module.exports = DeviceEventManager; diff --git a/src/NativeModules/LinkingManager.js b/src/NativeModules/LinkingManager.js index 805685f..f89d0d1 100644 --- a/src/NativeModules/LinkingManager.js +++ b/src/NativeModules/LinkingManager.js @@ -9,7 +9,7 @@ const LinkingManger = { __setCanOpenURLTest(test) { _test = test; - } + }, }; module.exports = LinkingManger; diff --git a/src/NativeModules/ScrollViewManager.js b/src/NativeModules/ScrollViewManager.js index 761fee1..585782d 100644 --- a/src/NativeModules/ScrollViewManager.js +++ b/src/NativeModules/ScrollViewManager.js @@ -1,25 +1,22 @@ - const ScrollViewManager = { getContentSize(reactTag, callback) { - Promise.resolve().then(() => callback({ - width: 20, - height: 20, - })); + Promise.resolve().then(() => + callback({ + width: 20, + height: 20, + }), + ); }, calculateChildFrames(reactTag, callback) { - Promise.resolve().then(() => callback({ - // TODO(lmr): - })); - }, - endRefreshing(reactTag) { - - }, - scrollTo(reactTag, offset, animated) { - - }, - zoomToRect(reactTag, rect, animated) { - + Promise.resolve().then(() => + callback({ + // TODO(lmr): + }), + ); }, + endRefreshing(reactTag) {}, + scrollTo(reactTag, offset, animated) {}, + zoomToRect(reactTag, rect, animated) {}, DecelerationRate: { normal: 0, fast: 1, diff --git a/src/NativeModules/SourceCode.js b/src/NativeModules/SourceCode.js index a420ce9..c7d9d2e 100644 --- a/src/NativeModules/SourceCode.js +++ b/src/NativeModules/SourceCode.js @@ -10,9 +10,7 @@ const SourceCode = { : Promise.reject(new Error('Source code is not available')); }, __setScriptText(url, text) { - _sourceCode = !!url && !!text - ? { url, text } - : null; + _sourceCode = !!url && !!text ? {url, text} : null; }, }; diff --git a/src/NativeModules/TestModule.js b/src/NativeModules/TestModule.js index fb1bbe2..c0626c3 100644 --- a/src/NativeModules/TestModule.js +++ b/src/NativeModules/TestModule.js @@ -13,12 +13,8 @@ const TestModule = { shouldReject() { return Promise.reject(null); }, - markTestCompleted() { - - }, - markTestPassed(success) { - - }, + markTestCompleted() {}, + markTestPassed(success) {}, }; module.exports = TestModule; diff --git a/src/NativeModules/TimePickerAndroid.js b/src/NativeModules/TimePickerAndroid.js index 1b61601..2878ebc 100644 --- a/src/NativeModules/TimePickerAndroid.js +++ b/src/NativeModules/TimePickerAndroid.js @@ -1,14 +1,14 @@ // TODO(lmr): figure out a good way to toggle between timeSetAction and dismissedAction -let _resolver = () => ({ action: 'timeSetAction', hour: 2, minute: 30 }); +let _resolver = () => ({action: 'timeSetAction', hour: 2, minute: 30}); const TimePickerAndroid = { open(options) { - const result = _resolver(options) || { action: 'dismissedAction' }; + const result = _resolver(options) || {action: 'dismissedAction'}; return Promise.resolve(result); }, __setResolverFunction(resolver) { _resolver = resolver; - } + }, }; module.exports = TimePickerAndroid; diff --git a/src/NativeModules/Timing.js b/src/NativeModules/Timing.js index 1b2fa46..e2f263f 100644 --- a/src/NativeModules/Timing.js +++ b/src/NativeModules/Timing.js @@ -2,12 +2,8 @@ * https://github.com/facebook/react-native/blob/master/React/Modules/RCTTiming.m */ const Timing = { - createTimer(callbackId, duration, jsSchedulingTime, repeats) { - - }, - deleteTimer(timerId) { - - }, + createTimer(callbackId, duration, jsSchedulingTime, repeats) {}, + deleteTimer(timerId) {}, }; module.exports = Timing; diff --git a/src/NativeModules/UIManager.js b/src/NativeModules/UIManager.js index a7be40a..dce5c7c 100644 --- a/src/NativeModules/UIManager.js +++ b/src/NativeModules/UIManager.js @@ -1,69 +1,32 @@ - const UIManager = { - removeSubviewsFromContainerWithID(containerId) { - - }, - removeRootView(rootReactTag) { - - }, - replaceExistingNonRootView(reactTag, newReactTag) { - - }, - setChildren(containerTag, reactTags) { - - }, + removeSubviewsFromContainerWithID(containerId) {}, + removeRootView(rootReactTag) {}, + replaceExistingNonRootView(reactTag, newReactTag) {}, + setChildren(containerTag, reactTags) {}, manageChildren( containerReactTag, moveFromIndices, moveToIndices, addChildReactTags, addAtIndices, - removeAtIndices - ) { - - }, - createView(reactTag, viewName, rootTag, props) { - - }, - updateView(reactTag, viewName, props) { - - }, - focus(reactTag) { - - }, - blur(reactTag) { - - }, - findSubviewIn(reactTag, atPoint, callback) { - - }, - dispatchViewManagerCommand(reactTag, commandID, commandArgs) { - - }, - measure(reactTag, callback) { - - }, - measureLayout(reactTag, relativeTo, errorCallback, callback) { - - }, - measureLayoutRelativeToParent(reactTag, errorCallback, callback) { - - }, - measureViewsInRect(rect, parentView, errorCallback, callback) { - - }, - setJSResponder(reactTag, blockNativeResponder) { - - }, - clearJSResponder() { - - }, - configureNextLayoutAnimation(callback, errorCallback) { - - }, + removeAtIndices, + ) {}, + createView(reactTag, viewName, rootTag, props) {}, + updateView(reactTag, viewName, props) {}, + focus(reactTag) {}, + blur(reactTag) {}, + findSubviewIn(reactTag, atPoint, callback) {}, + dispatchViewManagerCommand(reactTag, commandID, commandArgs) {}, + measure(reactTag, callback) {}, + measureLayout(reactTag, relativeTo, errorCallback, callback) {}, + measureLayoutRelativeToParent(reactTag, errorCallback, callback) {}, + measureViewsInRect(rect, parentView, errorCallback, callback) {}, + setJSResponder(reactTag, blockNativeResponder) {}, + clearJSResponder() {}, + configureNextLayoutAnimation(callback, errorCallback) {}, AndroidDrawerLayout: { Constants: { - DrawerPosition: { Left: 8388611, Right: 8388613 }, + DrawerPosition: {Left: 8388611, Right: 8388613}, }, }, }; diff --git a/src/NativeModules/Vibration.js b/src/NativeModules/Vibration.js index 8345c50..76c12f6 100644 --- a/src/NativeModules/Vibration.js +++ b/src/NativeModules/Vibration.js @@ -1,7 +1,5 @@ const Vibration = { - vibrate() { - - }, + vibrate() {}, }; module.exports = Vibration; diff --git a/src/NativeModules/WebViewManager.js b/src/NativeModules/WebViewManager.js index 6c1ce39..2ee2c9d 100644 --- a/src/NativeModules/WebViewManager.js +++ b/src/NativeModules/WebViewManager.js @@ -1,17 +1,8 @@ - const WebViewManager = { - goBack(reactTag) { - - }, - goForward(reactTag) { - - }, - reload(reactTag) { - - }, - startLoadWithResult(result, lockIdentifier) { - - }, + goBack(reactTag) {}, + goForward(reactTag) {}, + reload(reactTag) {}, + startLoadWithResult(result, lockIdentifier) {}, JSNavigationScheme: 'react-js-navigation', NavigationType: { LinkClicked: 0, @@ -20,7 +11,7 @@ const WebViewManager = { Reload: 3, FormResubmitted: 4, Other: 5, - } + }, }; module.exports = WebViewManager; diff --git a/src/NativeModules/index.js b/src/NativeModules/index.js index 31b1c1f..851a362 100644 --- a/src/NativeModules/index.js +++ b/src/NativeModules/index.js @@ -1,4 +1,3 @@ - const NativeModules = { Timing: require('./Timing'), UIManager: require('./UIManager'), diff --git a/src/api/ActionSheetIOS.js b/src/api/ActionSheetIOS.js index 88477dc..2640312 100644 --- a/src/api/ActionSheetIOS.js +++ b/src/api/ActionSheetIOS.js @@ -6,41 +6,34 @@ const ActionSheetIOS = { showActionSheetWithOptions(options, callback) { invariant( typeof options === 'object' && options !== null, - 'Options must a valid object' - ); - invariant( - typeof callback === 'function', - 'Must provide a valid callback' + 'Options must a valid object', ); + invariant(typeof callback === 'function', 'Must provide a valid callback'); ActionSheetManager.showActionSheetWithOptions( - { ...options, tintColor: processColor(options.tintColor) }, - callback + {...options, tintColor: processColor(options.tintColor)}, + callback, ); }, - showShareActionSheetWithOptions( - options, - failureCallback, - successCallback - ) { + showShareActionSheetWithOptions(options, failureCallback, successCallback) { invariant( typeof options === 'object' && options !== null, - 'Options must a valid object' + 'Options must a valid object', ); invariant( typeof failureCallback === 'function', - 'Must provide a valid failureCallback' + 'Must provide a valid failureCallback', ); invariant( typeof successCallback === 'function', - 'Must provide a valid successCallback' + 'Must provide a valid successCallback', ); ActionSheetManager.showShareActionSheetWithOptions( - { ...options, tintColor: processColor(options.tintColor) }, + {...options, tintColor: processColor(options.tintColor)}, failureCallback, - successCallback + successCallback, ); - } + }, }; module.exports = ActionSheetIOS; diff --git a/src/api/Alert.js b/src/api/Alert.js index ac2c918..3397f6e 100644 --- a/src/api/Alert.js +++ b/src/api/Alert.js @@ -2,9 +2,7 @@ * https://github.com/facebook/react-native/blob/master/Libraries/Utilities/Alert.js */ const Alert = { - alert(title, message, buttons, type) { - - }, + alert(title, message, buttons, type) {}, }; module.exports = Alert; diff --git a/src/api/AlertIOS.js b/src/api/AlertIOS.js index 9d86ad5..dc4ad03 100644 --- a/src/api/AlertIOS.js +++ b/src/api/AlertIOS.js @@ -37,7 +37,7 @@ class AlertIOS { static alert(title, message, callbackOrButtons, type) { if (typeof type !== 'undefined') { console.warn( - 'AlertIOS.alert() with a 4th "type" parameter is deprecated and will be removed. Use AlertIOS.prompt() instead.' + 'AlertIOS.alert() with a 4th "type" parameter is deprecated and will be removed. Use AlertIOS.prompt() instead.', ); this.prompt(title, message, callbackOrButtons, type); return; @@ -88,13 +88,16 @@ class AlertIOS { static prompt(title, message, callbackOrButtons, type, defaultValue) { if (typeof type === 'function') { const callback = type; - AlertManager.alertWithArgs({ - title: title || undefined, - type: 'plain-text', - message, - }, (id, value) => { - callback(value); - }); + AlertManager.alertWithArgs( + { + title: title || undefined, + type: 'plain-text', + message, + }, + (id, value) => { + callback(value); + }, + ); return; } @@ -135,7 +138,7 @@ class AlertIOS { if (cb) { cb(value); } - } + }, ); } } diff --git a/src/api/Animated/AnimatedImplementation.js b/src/api/Animated/AnimatedImplementation.js index 07d31cc..8017dcb 100644 --- a/src/api/Animated/AnimatedImplementation.js +++ b/src/api/Animated/AnimatedImplementation.js @@ -8,7 +8,7 @@ import flattenStyle from '../../propTypes/flattenStyle'; // vars to modify for a tests const testingVars = { - duration: null + duration: null, }; const testingMethods = { @@ -18,17 +18,21 @@ const testingMethods = { __restoreDuration() { testingVars.duration = null; - } + }, }; class Animated { __attach() {} __detach() {} __getValue() {} - __getAnimatedValue() { return this.__getValue(); } + __getAnimatedValue() { + return this.__getValue(); + } __addChild(child) {} __removeChild(child) {} - __getChildren() { return []; } + __getChildren() { + return []; + } } class Animation { @@ -59,9 +63,7 @@ class AnimatedWithChildren extends Animated { __removeChild(child) { const index = this._children.indexOf(child); if (index === -1) { - console.warn( - 'Trying to remove a child that doesn\'t exist' - ); + console.warn("Trying to remove a child that doesn't exist"); return; } this._children.splice(index, 1); @@ -119,7 +121,8 @@ class TimingAnimation extends Animation { this._easing = config.easing || easeInOut; this._duration = config.duration !== undefined ? config.duration : 500; this._delay = config.delay || 0; - this.__isInteraction = config.isInteraction !== undefined ? config.isInteraction : true; + this.__isInteraction = + config.isInteraction !== undefined ? config.isInteraction : true; } start(fromValue, onUpdate, onEnd) { @@ -129,10 +132,11 @@ class TimingAnimation extends Animation { this.__onEnd = onEnd; const start = () => { - const duration = testingVars.duration !== null ? testingVars.duration : this._duration; + const duration = + testingVars.duration !== null ? testingVars.duration : this._duration; if (duration === 0) { this._onUpdate(this._toValue); - this.__debouncedOnEnd({ finished: true }); + this.__debouncedOnEnd({finished: true}); } else { this._startTime = Date.now(); this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this)); @@ -147,24 +151,25 @@ class TimingAnimation extends Animation { onUpdate() { const now = Date.now(); - const duration = testingVars.duration !== null ? testingVars.duration : this._duration; + const duration = + testingVars.duration !== null ? testingVars.duration : this._duration; if (now >= this._startTime + duration) { if (duration === 0) { this._onUpdate(this._toValue); } else { this._onUpdate( - this._fromValue + this._easing(1) * (this._toValue - this._fromValue) + this._fromValue + this._easing(1) * (this._toValue - this._fromValue), ); } - this.__debouncedOnEnd({ finished: true }); + this.__debouncedOnEnd({finished: true}); return; } this._onUpdate( this._fromValue + - this._easing((now - this._startTime) / duration) * - (this._toValue - this._fromValue) + this._easing((now - this._startTime) / duration) * + (this._toValue - this._fromValue), ); if (this.__active) { this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this)); @@ -177,7 +182,7 @@ class TimingAnimation extends Animation { if (global && global.cancelAnimationFrame) { global.cancelAnimationFrame(this._animationFrame); } - this.__debouncedOnEnd({ finished: false }); + this.__debouncedOnEnd({finished: false}); } } @@ -186,7 +191,8 @@ class DecayAnimation extends Animation { super(); this._deceleration = config.deceleration || 0.998; this._velocity = config.velocity; - this.__isInteraction = config.isInteraction !== undefined ? config.isInteraction : true; + this.__isInteraction = + config.isInteraction !== undefined ? config.isInteraction : true; } start(fromValue, onUpdate, onEnd) { @@ -202,14 +208,15 @@ class DecayAnimation extends Animation { onUpdate() { const now = Date.now(); - const value = this._fromValue + + const value = + this._fromValue + (this._velocity / (1 - this._deceleration)) * - (1 - Math.exp(-(1 - this._deceleration) * (now - this._startTime))); + (1 - Math.exp(-(1 - this._deceleration) * (now - this._startTime))); this._onUpdate(value); if (Math.abs(this._lastValue - value) < 0.1) { - this.__debouncedOnEnd({ finished: true }); + this.__debouncedOnEnd({finished: true}); return; } @@ -224,7 +231,7 @@ class DecayAnimation extends Animation { if (global && global.cancelAnimationFrame) { global.cancelAnimationFrame(this._animationFrame); } - this.__debouncedOnEnd({ finished: false }); + this.__debouncedOnEnd({finished: false}); } } @@ -240,18 +247,22 @@ class SpringAnimation extends Animation { super(); this._overshootClamping = withDefault(config.overshootClamping, false); - this._restDisplacementThreshold = withDefault(config.restDisplacementThreshold, 0.001); + this._restDisplacementThreshold = withDefault( + config.restDisplacementThreshold, + 0.001, + ); this._restSpeedThreshold = withDefault(config.restSpeedThreshold, 0.001); this._initialVelocity = config.velocity; this._lastVelocity = withDefault(config.velocity, 0); this._toValue = config.toValue; - this.__isInteraction = config.isInteraction !== undefined ? config.isInteraction : true; + this.__isInteraction = + config.isInteraction !== undefined ? config.isInteraction : true; let springConfig; if (config.bounciness !== undefined || config.speed !== undefined) { invariant( config.tension === undefined && config.friction === undefined, - 'You can only define bounciness/speed or tension/friction but not both' + 'You can only define bounciness/speed or tension/friction but not both', ); springConfig = SpringConfig.fromBouncinessAndSpeed( withDefault(config.bounciness, 8), @@ -327,30 +338,36 @@ class SpringAnimation extends Animation { // http://gafferongames.com/game-physics/integration-basics/ const aVelocity = velocity; const aAcceleration = - this._tension * (this._toValue - tempPosition) - this._friction * tempVelocity; - tempPosition = position + aVelocity * step / 2; - tempVelocity = velocity + aAcceleration * step / 2; + this._tension * (this._toValue - tempPosition) - + this._friction * tempVelocity; + tempPosition = position + (aVelocity * step) / 2; + tempVelocity = velocity + (aAcceleration * step) / 2; const bVelocity = tempVelocity; const bAcceleration = - this._tension * (this._toValue - tempPosition) - this._friction * tempVelocity; - tempPosition = position + bVelocity * step / 2; - tempVelocity = velocity + bAcceleration * step / 2; + this._tension * (this._toValue - tempPosition) - + this._friction * tempVelocity; + tempPosition = position + (bVelocity * step) / 2; + tempVelocity = velocity + (bAcceleration * step) / 2; const cVelocity = tempVelocity; const cAcceleration = - this._tension * (this._toValue - tempPosition) - this._friction * tempVelocity; - tempPosition = position + cVelocity * step / 2; - tempVelocity = velocity + cAcceleration * step / 2; + this._tension * (this._toValue - tempPosition) - + this._friction * tempVelocity; + tempPosition = position + (cVelocity * step) / 2; + tempVelocity = velocity + (cAcceleration * step) / 2; const dVelocity = tempVelocity; const dAcceleration = - this._tension * (this._toValue - tempPosition) - this._friction * tempVelocity; - tempPosition = position + cVelocity * step / 2; - tempVelocity = velocity + cAcceleration * step / 2; + this._tension * (this._toValue - tempPosition) - + this._friction * tempVelocity; + tempPosition = position + (cVelocity * step) / 2; + tempVelocity = velocity + (cAcceleration * step) / 2; const dxdt = (aVelocity + 2 * (bVelocity + cVelocity) + dVelocity) / 6; - const dvdt = (aAcceleration + 2 * (bAcceleration + cAcceleration) + dAcceleration) / 6; + const dvdt = + (aAcceleration + 2 * (bAcceleration + cAcceleration) + dAcceleration) / + 6; position += dxdt * step; velocity += dvdt * step; @@ -361,7 +378,8 @@ class SpringAnimation extends Animation { this._lastVelocity = velocity; this._onUpdate(position); - if (!this.__active) { // a listener might have stopped us in _onUpdate + if (!this.__active) { + // a listener might have stopped us in _onUpdate return; } @@ -378,7 +396,8 @@ class SpringAnimation extends Animation { const isVelocity = Math.abs(velocity) <= this._restSpeedThreshold; let isDisplacement = true; if (this._tension !== 0) { - isDisplacement = Math.abs(this._toValue - position) <= this._restDisplacementThreshold; + isDisplacement = + Math.abs(this._toValue - position) <= this._restDisplacementThreshold; } if (isOvershooting || (isVelocity && isDisplacement)) { @@ -387,7 +406,7 @@ class SpringAnimation extends Animation { this._onUpdate(this._toValue); } - this.__debouncedOnEnd({ finished: true }); + this.__debouncedOnEnd({finished: true}); return; } this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this)); @@ -398,7 +417,7 @@ class SpringAnimation extends Animation { if (global && global.cancelAnimationFrame) { global.cancelAnimationFrame(this._animationFrame); } - this.__debouncedOnEnd({ finished: false }); + this.__debouncedOnEnd({finished: false}); } } @@ -415,7 +434,7 @@ class AnimatedInterpolation extends AnimatedWithChildren { const parentValue = this._parent.__getValue(); invariant( typeof parentValue === 'number', - 'Cannot interpolate an input which is not a number.' + 'Cannot interpolate an input which is not a number.', ); return this._interpolation(parentValue); } @@ -433,7 +452,6 @@ class AnimatedInterpolation extends AnimatedWithChildren { } } - class AnimatedValue extends AnimatedWithChildren { constructor(value) { super(); @@ -540,10 +558,10 @@ class AnimatedValue extends AnimatedWithChildren { this._animation = animation; animation.start( this._value, - (value) => { + value => { this._updateValue(value); }, - (result) => { + result => { this._animation = null; if (handle !== null) { InteractionManager.clearInteractionHandle(handle); @@ -552,7 +570,7 @@ class AnimatedValue extends AnimatedWithChildren { callback(result); } }, - previousAnimation + previousAnimation, ); } @@ -578,25 +596,23 @@ class AnimatedValue extends AnimatedWithChildren { this._value = value; _flush(this); for (const key in this._listeners) { - this._listeners[key]({ value: this.__getValue() }); + this._listeners[key]({value: this.__getValue()}); } } } - class AnimatedValueXY extends AnimatedWithChildren { constructor(valueIn) { super(); - const value = valueIn || { x: 0, y: 0 }; // @flowfixme: shouldn't need `: any` + const value = valueIn || {x: 0, y: 0}; // @flowfixme: shouldn't need `: any` if (typeof value.x === 'number' && typeof value.y === 'number') { this.x = new AnimatedValue(value.x); this.y = new AnimatedValue(value.y); } else { invariant( - value.x instanceof AnimatedValue && - value.y instanceof AnimatedValue, + value.x instanceof AnimatedValue && value.y instanceof AnimatedValue, 'AnimatedValueXY must be initalized with an object of numbers or ' + - 'AnimatedValues.' + 'AnimatedValues.', ); this.x = value.x; this.y = value.y; @@ -636,7 +652,7 @@ class AnimatedValueXY extends AnimatedWithChildren { addListener(callback) { const id = String(_uniqueId++); - const jointCallback = ({ value }) => { + const jointCallback = ({value}) => { callback(this.__getValue()); }; this._listeners[id] = { @@ -671,19 +687,15 @@ class AnimatedValueXY extends AnimatedWithChildren { * *```javascript * style={{ - * transform: this.state.anim.getTranslateTransform() - * }} + * transform: this.state.anim.getTranslateTransform() + * }} *``` */ getTranslateTransform() { - return [ - { translateX: this.x }, - { translateY: this.y } - ]; + return [{translateX: this.x}, {translateY: this.y}]; } } - class AnimatedAddition extends AnimatedWithChildren { constructor(a, b) { super(); @@ -938,10 +950,13 @@ class AnimatedTracking extends Animated { } update() { - this._value.animate(new this._animationClass({ - ...this._animationConfig, - toValue: this._animationConfig.toValue.__getValue(), - }), this._callback); + this._value.animate( + new this._animationClass({ + ...this._animationConfig, + toValue: this._animationConfig.toValue.__getValue(), + }), + this._callback, + ); } } @@ -963,13 +978,13 @@ function parallel(animations, config) { start(callback) { if (doneCount === animations.length) { if (callback) { - callback({ finished: true }); + callback({finished: true}); } return; } animations.forEach((animation, idx) => { - const cb = function (endResult) { + const cb = function(endResult) { hasEnded[idx] = true; doneCount++; if (doneCount === animations.length) { @@ -986,7 +1001,7 @@ function parallel(animations, config) { }; if (!animation) { - cb({ finished: true }); + cb({finished: true}); } else { animation.start(cb); } @@ -1000,7 +1015,7 @@ function parallel(animations, config) { } hasEnded[idx] = true; }); - } + }, }; return result; @@ -1008,10 +1023,10 @@ function parallel(animations, config) { function maybeVectorAnim(value, config, anim) { if (value instanceof AnimatedValueXY) { - const configX = { ...config }; - const configY = { ...config }; + const configX = {...config}; + const configY = {...config}; for (const key in config) { - const { x, y } = config[key]; + const {x, y} = config[key]; if (x !== undefined && y !== undefined) { configX[key] = x; configY[key] = y; @@ -1021,81 +1036,91 @@ function maybeVectorAnim(value, config, anim) { const aY = anim(value.y, configY); // We use `stopTogether: false` here because otherwise tracking will break // because the second animation will get stopped before it can update. - return parallel([aX, aY], { stopTogether: false }); + return parallel([aX, aY], {stopTogether: false}); } return null; } function spring(value, config) { - return maybeVectorAnim(value, config, spring) || { - start(callback) { - const singleValue = value; - const singleConfig = config; - singleValue.stopTracking(); - if (config.toValue instanceof Animated) { - singleValue.track(new AnimatedTracking( - singleValue, - config.toValue, - SpringAnimation, - singleConfig, - callback - )); - } else { - singleValue.animate(new SpringAnimation(singleConfig), callback); - } - }, + return ( + maybeVectorAnim(value, config, spring) || { + start(callback) { + const singleValue = value; + const singleConfig = config; + singleValue.stopTracking(); + if (config.toValue instanceof Animated) { + singleValue.track( + new AnimatedTracking( + singleValue, + config.toValue, + SpringAnimation, + singleConfig, + callback, + ), + ); + } else { + singleValue.animate(new SpringAnimation(singleConfig), callback); + } + }, - stop() { - value.stopAnimation(); - }, - }; + stop() { + value.stopAnimation(); + }, + } + ); } function timing(value, config) { - return maybeVectorAnim(value, config, timing) || { - start(callback) { - const singleValue = value; - const singleConfig = config; - singleValue.stopTracking(); - if (config.toValue instanceof Animated) { - singleValue.track(new AnimatedTracking( - singleValue, - config.toValue, - TimingAnimation, - singleConfig, - callback - )); - } else { - singleValue.animate(new TimingAnimation(singleConfig), callback); - } - }, + return ( + maybeVectorAnim(value, config, timing) || { + start(callback) { + const singleValue = value; + const singleConfig = config; + singleValue.stopTracking(); + if (config.toValue instanceof Animated) { + singleValue.track( + new AnimatedTracking( + singleValue, + config.toValue, + TimingAnimation, + singleConfig, + callback, + ), + ); + } else { + singleValue.animate(new TimingAnimation(singleConfig), callback); + } + }, - stop() { - value.stopAnimation(); - }, - }; + stop() { + value.stopAnimation(); + }, + } + ); } function decay(value, config) { - return maybeVectorAnim(value, config, decay) || { - start(callback) { - const singleValue = value; - const singleConfig = config; - singleValue.stopTracking(); - singleValue.animate(new DecayAnimation(singleConfig), callback); - }, + return ( + maybeVectorAnim(value, config, decay) || { + start(callback) { + const singleValue = value; + const singleConfig = config; + singleValue.stopTracking(); + singleValue.animate(new DecayAnimation(singleConfig), callback); + }, - stop() { - value.stopAnimation(); - }, - }; + stop() { + value.stopAnimation(); + }, + } + ); } function sequence(animations) { let current = 0; return { start(callback) { - const onComplete = function (result) { + const onComplete = function(result) { if (!result.finished) { if (callback) { callback(result); @@ -1117,7 +1142,7 @@ function sequence(animations) { if (animations.length === 0) { if (callback) { - callback({ finished: true }); + callback({finished: true}); } } else { animations[current].start(onComplete); @@ -1128,43 +1153,45 @@ function sequence(animations) { if (current < animations.length) { animations[current].stop(); } - } + }, }; } function delay(time) { // Would be nice to make a specialized implementation - return timing(new AnimatedValue(0), { toValue: 0, delay: time, duration: 0 }); + return timing(new AnimatedValue(0), {toValue: 0, delay: time, duration: 0}); } function stagger(time, animations) { - return parallel(animations.map(function (animation, i) { - return sequence([ - delay(time * i), - animation, - ]); - })); + return parallel( + animations.map(function(animation, i) { + return sequence([delay(time * i), animation]); + }), + ); } function event(argMapping, config) { - return function (...args) { - const traverse = function (recMapping, recEvt, key) { + return function(...args) { + const traverse = function(recMapping, recEvt, key) { if (typeof recEvt === 'number') { invariant( recMapping instanceof AnimatedValue, - 'Bad mapping of type ' + typeof recMapping + ' for key ' + key + - ', event value must map to AnimatedValue' + 'Bad mapping of type ' + + typeof recMapping + + ' for key ' + + key + + ', event value must map to AnimatedValue', ); recMapping.setValue(recEvt); return; } invariant( typeof recMapping === 'object', - 'Bad mapping of type ' + typeof recMapping + ' for key ' + key + 'Bad mapping of type ' + typeof recMapping + ' for key ' + key, ); invariant( typeof recEvt === 'object', - 'Bad event of type ' + typeof recEvt + ' for key ' + key + 'Bad event of type ' + typeof recEvt + ' for key ' + key, ); for (const i in recMapping) { traverse(recMapping[i], recEvt[i], i); diff --git a/src/api/Animated/Easing.js b/src/api/Animated/Easing.js index 6183793..17da99c 100644 --- a/src/api/Animated/Easing.js +++ b/src/api/Animated/Easing.js @@ -2,7 +2,7 @@ import _bezier from 'cubic-bezier'; let _ease = () => {}; -const EPSILON = (1000 / 60 / 500) / 4; +const EPSILON = 1000 / 60 / 500 / 4; /** * This class implements common easing functions. The math is pretty obscure, @@ -35,11 +35,11 @@ class Easing { } static poly(n) { - return (t) => Math.pow(t, n); + return t => Math.pow(t, n); } static sin(t) { - return 1 - Math.cos(t * Math.PI / 2); + return 1 - Math.cos((t * Math.PI) / 2); } static circle(t) { @@ -62,11 +62,11 @@ class Easing { */ static elastic(bounciness = 1) { const p = bounciness * Math.PI; - return (t) => 1 - Math.pow(Math.cos(t * Math.PI / 2), 3) * Math.cos(t * p); + return t => 1 - Math.pow(Math.cos((t * Math.PI) / 2), 3) * Math.cos(t * p); } static back(s = 1.70158) { - return (t) => t * t * ((s + 1) * t - s); + return t => t * t * ((s + 1) * t - s); } static bounce(argT) { @@ -101,14 +101,14 @@ class Easing { * Runs an easing function backwards. */ static out(easing) { - return (t) => 1 - easing(1 - t); + return t => 1 - easing(1 - t); } /** * Makes any easing function symmetrical. */ static inOut(easing) { - return (t) => { + return t => { if (t < 0.5) { return easing(t * 2) / 2; } diff --git a/src/api/Animated/SpringConfig.js b/src/api/Animated/SpringConfig.js index 0488523..d0280d4 100644 --- a/src/api/Animated/SpringConfig.js +++ b/src/api/Animated/SpringConfig.js @@ -13,7 +13,7 @@ function frictionFromOrigamiValue(oValue) { function fromOrigamiTensionAndFriction(tension, friction) { return { tension: tensionFromOrigamiValue(tension), - friction: frictionFromOrigamiValue(friction) + friction: frictionFromOrigamiValue(friction), }; } @@ -23,7 +23,7 @@ function fromBouncinessAndSpeed(bounciness, speed) { } function projectNormal(n, start, end) { - return start + (n * (end - start)); + return start + n * (end - start); } function linearInterpolation(t, start, end) { @@ -35,18 +35,20 @@ function fromBouncinessAndSpeed(bounciness, speed) { } function b3Friction1(x) { - return (0.0007 * Math.pow(x, 3)) - - (0.031 * Math.pow(x, 2)) + 0.64 * x + 1.28; + return 0.0007 * Math.pow(x, 3) - 0.031 * Math.pow(x, 2) + 0.64 * x + 1.28; } function b3Friction2(x) { - return (0.000044 * Math.pow(x, 3)) - - (0.006 * Math.pow(x, 2)) + 0.36 * x + 2; + return 0.000044 * Math.pow(x, 3) - 0.006 * Math.pow(x, 2) + 0.36 * x + 2; } function b3Friction3(x) { - return (0.00000045 * Math.pow(x, 3)) - - (0.000332 * Math.pow(x, 2)) + 0.1078 * x + 5.84; + return ( + 0.00000045 * Math.pow(x, 3) - + 0.000332 * Math.pow(x, 2) + + 0.1078 * x + + 5.84 + ); } function b3Nobounce(tension) { @@ -65,12 +67,12 @@ function fromBouncinessAndSpeed(bounciness, speed) { const bouncyFriction = quadraticOutInterpolation( b, b3Nobounce(bouncyTension), - 0.01 + 0.01, ); return { tension: tensionFromOrigamiValue(bouncyTension), - friction: frictionFromOrigamiValue(bouncyFriction) + friction: frictionFromOrigamiValue(bouncyFriction), }; } diff --git a/src/api/Animated/createAnimatedComponent.js b/src/api/Animated/createAnimatedComponent.js index 2adc802..dfc8220 100644 --- a/src/api/Animated/createAnimatedComponent.js +++ b/src/api/Animated/createAnimatedComponent.js @@ -5,19 +5,12 @@ function createAnimatedComponent(Component) { class AnimatedComponent extends React.Component { static propTypes = { children: PropTypes.node, - } + }; - setNativeProps() { - } + setNativeProps() {} render() { - return ( - {}} - > - {this.props.children} - - ); + return {}}>{this.props.children}; } } diff --git a/src/api/AppRegistry.js b/src/api/AppRegistry.js index df50345..a791541 100644 --- a/src/api/AppRegistry.js +++ b/src/api/AppRegistry.js @@ -4,16 +4,14 @@ const runnables = {}; const AppRegistry = { - registerConfig(configs) { - - }, + registerConfig(configs) {}, registerComponent(appKey, getComponentFunc) { return appKey; }, registerRunnable(appKey, func) { - runnables[appKey] = { run: func }; + runnables[appKey] = {run: func}; return appKey; }, @@ -21,13 +19,9 @@ const AppRegistry = { return Object.keys(runnables); }, - runApplication(appKey, appParameters) { - - }, - - unmountApplicationComponentAtRootTag(rootTag) { + runApplication(appKey, appParameters) {}, - }, + unmountApplicationComponentAtRootTag(rootTag) {}, }; module.exports = AppRegistry; diff --git a/src/api/AppState.js b/src/api/AppState.js index 3e9cd7c..a0b2f94 100644 --- a/src/api/AppState.js +++ b/src/api/AppState.js @@ -13,25 +13,29 @@ const AppState = { addEventListener(type, handler) { invariant( ['change', 'memoryWarning'].indexOf(type) !== -1, - 'Trying to subscribe to unknown event: "%s"', type + 'Trying to subscribe to unknown event: "%s"', + type, ); if (type === 'change') { - _eventHandlers[type].set(handler, DeviceEventEmitter.addListener( - 'appStateDidChange', - (appStateData) => handler(appStateData.appState) - )); + _eventHandlers[type].set( + handler, + DeviceEventEmitter.addListener('appStateDidChange', appStateData => + handler(appStateData.appState), + ), + ); } else if (type === 'memoryWarning') { - _eventHandlers[type].set(handler, DeviceEventEmitter.addListener( - 'memoryWarning', - handler - )); + _eventHandlers[type].set( + handler, + DeviceEventEmitter.addListener('memoryWarning', handler), + ); } }, removeEventListener(type, handler) { invariant( ['change', 'memoryWarning'].indexOf(type) !== -1, - 'Trying to remove listener for unknown event: "%s"', type + 'Trying to remove listener for unknown event: "%s"', + type, ); if (!_eventHandlers[type].has(handler)) { return; @@ -42,13 +46,12 @@ const AppState = { currentState: 'active', __setAppState(appState) { - DeviceEventEmitter.emit('appStateDidChange', { appState }); + DeviceEventEmitter.emit('appStateDidChange', {appState}); }, }; -DeviceEventEmitter.addListener( - 'appStateDidChange', - (appStateData) => { AppState.currentState = appStateData.appState; } -); +DeviceEventEmitter.addListener('appStateDidChange', appStateData => { + AppState.currentState = appStateData.appState; +}); module.exports = AppState; diff --git a/src/api/AppStateIOS.js b/src/api/AppStateIOS.js index 5066681..930760c 100644 --- a/src/api/AppStateIOS.js +++ b/src/api/AppStateIOS.js @@ -2,7 +2,7 @@ import DeviceEventEmitter from '../plugins/DeviceEventEmitter'; import AppState from '../NativeModules/AppState'; import invariant from 'invariant'; -const logError = (error) => console.error(error); +const logError = error => console.error(error); const _eventHandlers = { change: new Map(), @@ -61,7 +61,6 @@ const _eventHandlers = { */ const AppStateIOS = { - /** * Add a handler to AppState changes by listening to the `change` event type * and providing the handler @@ -69,20 +68,21 @@ const AppStateIOS = { addEventListener(type, handler) { invariant( ['change', 'memoryWarning'].indexOf(type) !== -1, - 'Trying to subscribe to unknown event: "%s"', type + 'Trying to subscribe to unknown event: "%s"', + type, ); if (type === 'change') { - _eventHandlers[type].set(handler, DeviceEventEmitter.addListener( - 'appStateDidChange', - (appStateData) => { + _eventHandlers[type].set( + handler, + DeviceEventEmitter.addListener('appStateDidChange', appStateData => { handler(appStateData.app_state); - } - )); + }), + ); } else if (type === 'memoryWarning') { - _eventHandlers[type].set(handler, DeviceEventEmitter.addListener( - 'memoryWarning', - handler - )); + _eventHandlers[type].set( + handler, + DeviceEventEmitter.addListener('memoryWarning', handler), + ); } }, @@ -92,7 +92,8 @@ const AppStateIOS = { removeEventListener(type, handler) { invariant( ['change', 'memoryWarning'].indexOf(type) !== -1, - 'Trying to remove listener for unknown event: "%s"', type + 'Trying to remove listener for unknown event: "%s"', + type, ); if (!_eventHandlers[type].has(handler)) { return; @@ -106,21 +107,14 @@ const AppStateIOS = { // will likely to have the initial value here. // Initialize to 'active' instead of null. currentState: 'active', - }; -DeviceEventEmitter.addListener( - 'appStateDidChange', - (appStateData) => { - AppStateIOS.currentState = appStateData.app_state; - } -); +DeviceEventEmitter.addListener('appStateDidChange', appStateData => { + AppStateIOS.currentState = appStateData.app_state; +}); -AppState.getCurrentAppState( - (appStateData) => { - AppStateIOS.currentState = appStateData.app_state; - }, - logError -); +AppState.getCurrentAppState(appStateData => { + AppStateIOS.currentState = appStateData.app_state; +}, logError); module.exports = AppStateIOS; diff --git a/src/api/AsyncStorage.js b/src/api/AsyncStorage.js index 94655e4..769d687 100644 --- a/src/api/AsyncStorage.js +++ b/src/api/AsyncStorage.js @@ -15,7 +15,7 @@ function wrap(value, callback) { callback(err); } throw err; - } + }, ); } @@ -50,9 +50,7 @@ const AsyncStorage = { return wrap(Object.keys(db), callback); }, - flushGetRequests() { - - }, + flushGetRequests() {}, multiGet(keys, callback) { return wrap(keys.map(k => [k, db[k] || null]), callback); diff --git a/src/api/BackAndroid.js b/src/api/BackAndroid.js index 2214fdf..bb5aa69 100644 --- a/src/api/BackAndroid.js +++ b/src/api/BackAndroid.js @@ -22,7 +22,6 @@ const _backPressSubscriptions = new Set(); * ``` */ const BackAndroid = { - exitApp() { DeviceEventManager.invokeDefaultBackPressHandler(); }, @@ -37,12 +36,11 @@ const BackAndroid = { removeEventListener(eventName, handler) { _backPressSubscriptions.delete(handler); }, - }; -DeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function () { +DeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { let invokeDefault = true; - _backPressSubscriptions.forEach((subscription) => { + _backPressSubscriptions.forEach(subscription => { if (subscription()) { invokeDefault = false; } diff --git a/src/api/CameraRoll.js b/src/api/CameraRoll.js index 719ef4b..5e6c075 100644 --- a/src/api/CameraRoll.js +++ b/src/api/CameraRoll.js @@ -57,7 +57,6 @@ const getPhotosParamChecker = PropTypes.shape({ }); class CameraRoll { - /** * Saves the image to the camera roll / gallery. * @@ -75,7 +74,7 @@ class CameraRoll { static saveImageWithTag(tag) { invariant( typeof tag === 'string', - 'CameraRoll.saveImageWithTag tag must be a valid string.' + 'CameraRoll.saveImageWithTag tag must be a valid string.', ); // TODO(lmr): return CameraRollManager.saveImageWithTag(tag); @@ -91,7 +90,7 @@ class CameraRoll { */ static getPhotos(params) { if (process.env.NODE_ENV === 'development') { - getPhotosParamChecker({ params }, 'params', 'CameraRoll.getPhotos'); + getPhotosParamChecker({params}, 'params', 'CameraRoll.getPhotos'); } // TODO(lmr): // TODO: Add the __DEV__ check back in to verify the Promise result diff --git a/src/api/DatePickerAndroid.js b/src/api/DatePickerAndroid.js index f7d403a..3bb42dc 100644 --- a/src/api/DatePickerAndroid.js +++ b/src/api/DatePickerAndroid.js @@ -61,11 +61,15 @@ class DatePickerAndroid { /** * A date has been selected. */ - static get dateSetAction() { return 'dateSetAction'; } + static get dateSetAction() { + return 'dateSetAction'; + } /** * The dialog has been dismissed. */ - static get dismissedAction() { return 'dismissedAction'; } + static get dismissedAction() { + return 'dismissedAction'; + } } module.exports = DatePickerAndroid; diff --git a/src/api/Dimensions.js b/src/api/Dimensions.js index 4567126..7cb270c 100644 --- a/src/api/Dimensions.js +++ b/src/api/Dimensions.js @@ -13,7 +13,7 @@ const DEFAULT_DIMENSIONS = Object.freeze({ let dimensions = { window: DEFAULT_DIMENSIONS, - screen: DEFAULT_DIMENSIONS + screen: DEFAULT_DIMENSIONS, }; const DEVICE_EVENT = 'didUpdateDimensions'; @@ -24,7 +24,7 @@ const _eventHandlers = { const Dimensions = { set(dims) { dimensions = Object.assign({}, dimensions, dims); - DeviceEventEmitter.emit(DEVICE_EVENT, { dims }); + DeviceEventEmitter.emit(DEVICE_EVENT, {dims}); return true; }, get(dim) { @@ -33,10 +33,11 @@ const Dimensions = { addEventListener(type, handler) { invariant( ['change'].indexOf(type) !== -1, - 'Trying to subscribe to unknown event: "%s"', type + 'Trying to subscribe to unknown event: "%s"', + type, ); if (type === 'change') { - const listener = ({ dims }) => handler(dims); + const listener = ({dims}) => handler(dims); DeviceEventEmitter.addListener(DEVICE_EVENT, listener); _eventHandlers[type].set(handler, listener); } @@ -44,7 +45,8 @@ const Dimensions = { removeEventListener(type, handler) { invariant( ['change'].indexOf(type) !== -1, - 'Trying to remove listener for unknown event: "%s"', type + 'Trying to remove listener for unknown event: "%s"', + type, ); const listener = _eventHandlers[type].get(handler); if (!listener) { diff --git a/src/api/ImagePickerIOS.js b/src/api/ImagePickerIOS.js index 4cb5001..a2180bd 100644 --- a/src/api/ImagePickerIOS.js +++ b/src/api/ImagePickerIOS.js @@ -1,4 +1,3 @@ - import ImagePicker from '../NativeModules/ImagePickerIOS'; const ImagePickerIOS = { @@ -13,7 +12,11 @@ const ImagePickerIOS = { videoMode: false, ...config, }; - return ImagePicker.openCameraDialog(newConfig, successCallback, cancelCallback); + return ImagePicker.openCameraDialog( + newConfig, + successCallback, + cancelCallback, + ); }, openSelectDialog(config, successCallback, cancelCallback) { const newConfig = { @@ -21,7 +24,11 @@ const ImagePickerIOS = { showVideos: false, ...config, }; - return ImagePicker.openSelectDialog(newConfig, successCallback, cancelCallback); + return ImagePicker.openSelectDialog( + newConfig, + successCallback, + cancelCallback, + ); }, }; diff --git a/src/api/IntentAndroid.js b/src/api/IntentAndroid.js index 23fa450..f77c40e 100644 --- a/src/api/IntentAndroid.js +++ b/src/api/IntentAndroid.js @@ -2,7 +2,6 @@ import invariant from 'invariant'; import Linking from './Linking'; class IntentAndroid { - /** * Starts a corresponding external activity for the given URL. * @@ -21,7 +20,7 @@ class IntentAndroid { */ static openURL(url) { console.warn( - '"IntentAndroid" is deprecated. Use the promise based "Linking" instead.' + '"IntentAndroid" is deprecated. Use the promise based "Linking" instead.', ); Linking.openURL(url); } @@ -41,7 +40,7 @@ class IntentAndroid { static canOpenURL(url, callback) { invariant( typeof callback === 'function', - 'A valid callback function is required' + 'A valid callback function is required', ); Linking.canOpenURL(url).then(callback); } @@ -57,7 +56,7 @@ class IntentAndroid { static getInitialURL(callback) { invariant( typeof callback === 'function', - 'A valid callback function is required' + 'A valid callback function is required', ); Linking.getInitialURL().then(callback); } diff --git a/src/api/InteractionManager.js b/src/api/InteractionManager.js index 21c2371..e9c712f 100644 --- a/src/api/InteractionManager.js +++ b/src/api/InteractionManager.js @@ -1,7 +1,7 @@ import keyMirror from 'keymirror'; import invariant from 'invariant'; -const { EventEmitter } = require('events'); +const {EventEmitter} = require('events'); const _emitter = new EventEmitter(); @@ -44,10 +44,7 @@ const InteractionManager = { * Notify manager that an interaction has completed. */ clearInteractionHandle(handle) { - invariant( - !!handle, - 'Must provide a handle to clear.' - ); + invariant(!!handle, 'Must provide a handle to clear.'); // TODO(lmr): // _scheduleUpdate(); // _addInteractionSet.delete(handle); diff --git a/src/api/Keyboard.js b/src/api/Keyboard.js index af21cf5..06a9afa 100644 --- a/src/api/Keyboard.js +++ b/src/api/Keyboard.js @@ -1,12 +1,12 @@ const Keyboard = { addListener(eventname, handler) { return { - remove: () => {} + remove: () => {}, }; }, removeListener: () => {}, removeAllListeners: () => {}, - dismiss: () => {} + dismiss: () => {}, }; module.exports = Keyboard; diff --git a/src/api/LayoutAnimation.js b/src/api/LayoutAnimation.js index 6789451..1729092 100644 --- a/src/api/LayoutAnimation.js +++ b/src/api/LayoutAnimation.js @@ -25,11 +25,10 @@ const animChecker = PropTypes.shape({ delay: PropTypes.number, springDamping: PropTypes.number, initialVelocity: PropTypes.number, - type: PropTypes.oneOf( - Object.keys(Types) - ), - property: PropTypes.oneOf( // Only applies to create/delete - Object.keys(Properties) + type: PropTypes.oneOf(Object.keys(Types)), + property: PropTypes.oneOf( + // Only applies to create/delete + Object.keys(Properties), ), }); @@ -43,11 +42,7 @@ const configChecker = PropTypes.shape({ const nop = () => {}; function configureNext(config, onAnimationDidEnd) { - UIManager.configureNextLayoutAnimation( - config, - onAnimationDidEnd || nop, - nop - ); + UIManager.configureNextLayoutAnimation(config, onAnimationDidEnd || nop, nop); } function create(duration, type, creationProp) { @@ -64,12 +59,8 @@ function create(duration, type, creationProp) { } const Presets = { - easeInEaseOut: create( - 300, Types.easeInEaseOut, Properties.opacity - ), - linear: create( - 500, Types.linear, Properties.opacity - ), + easeInEaseOut: create(300, Types.easeInEaseOut, Properties.opacity), + linear: create(500, Types.linear, Properties.opacity), spring: { duration: 700, create: { @@ -107,15 +98,9 @@ const LayoutAnimation = { Properties, configChecker, Presets, - easeInEaseOut: configureNext.bind( - null, Presets.easeInEaseOut - ), - linear: configureNext.bind( - null, Presets.linear - ), - spring: configureNext.bind( - null, Presets.spring - ), + easeInEaseOut: configureNext.bind(null, Presets.easeInEaseOut), + linear: configureNext.bind(null, Presets.linear), + spring: configureNext.bind(null, Presets.spring), }; module.exports = LayoutAnimation; diff --git a/src/api/Linking.js b/src/api/Linking.js index d01f726..ab39e60 100644 --- a/src/api/Linking.js +++ b/src/api/Linking.js @@ -19,17 +19,12 @@ class Linking { */ static addEventListener(type, handler) { if (Platform.OS === 'android') { - console.warn( - 'Linking.addEventListener is not supported on Android' - ); + console.warn('Linking.addEventListener is not supported on Android'); } else { - invariant( - type === 'url', - 'Linking only supports `url` events' - ); + invariant(type === 'url', 'Linking only supports `url` events'); const listener = DeviceEventEmitter.addListener( DEVICE_NOTIF_EVENT, - handler + handler, ); _notifHandlers.set(handler, listener); } @@ -42,22 +37,14 @@ class Linking { */ static removeEventListener(type, handler) { if (Platform.OS === 'android') { - console.warn( - 'Linking.removeEventListener is not supported on Android' - ); + console.warn('Linking.removeEventListener is not supported on Android'); } else { - invariant( - type === 'url', - 'Linking only supports `url` events' - ); + invariant(type === 'url', 'Linking only supports `url` events'); const listener = _notifHandlers.get(handler); if (!listener) { return; } - listener.removeListener( - DEVICE_NOTIF_EVENT, - handler - ); + listener.removeListener(DEVICE_NOTIF_EVENT, handler); _notifHandlers.delete(handler); } } @@ -109,12 +96,9 @@ class Linking { static _validateURL(url) { invariant( typeof url === 'string', - `Invalid URL: should be a string. Was: ${url}` - ); - invariant( - url, - 'Invalid URL: cannot be empty' + `Invalid URL: should be a string. Was: ${url}`, ); + invariant(url, 'Invalid URL: cannot be empty'); } } diff --git a/src/api/LinkingIOS.js b/src/api/LinkingIOS.js index 49fae0b..5d95c27 100644 --- a/src/api/LinkingIOS.js +++ b/src/api/LinkingIOS.js @@ -13,7 +13,7 @@ class LinkingIOS { */ static addEventListener(type, handler) { console.warn( - '"LinkingIOS.addEventListener" is deprecated. Use "Linking.addEventListener" instead.' + '"LinkingIOS.addEventListener" is deprecated. Use "Linking.addEventListener" instead.', ); Linking.addEventListener(type, handler); } @@ -25,7 +25,7 @@ class LinkingIOS { */ static removeEventListener(type, handler) { console.warn( - '"LinkingIOS.removeEventListener" is deprecated. Use "Linking.removeEventListener" instead.' + '"LinkingIOS.removeEventListener" is deprecated. Use "Linking.removeEventListener" instead.', ); Linking.removeEventListener(type, handler); } @@ -37,7 +37,7 @@ class LinkingIOS { */ static openURL(url) { console.warn( - '"LinkingIOS.openURL" is deprecated. Use the promise based "Linking.openURL" instead.' + '"LinkingIOS.openURL" is deprecated. Use the promise based "Linking.openURL" instead.', ); Linking.openURL(url); } @@ -53,11 +53,11 @@ class LinkingIOS { */ static canOpenURL(url, callback) { console.warn( - '"LinkingIOS.canOpenURL" is deprecated. Use the promise based "Linking.canOpenURL" instead.' + '"LinkingIOS.canOpenURL" is deprecated. Use the promise based "Linking.canOpenURL" instead.', ); invariant( typeof callback === 'function', - 'A valid callback function is required' + 'A valid callback function is required', ); Linking.canOpenURL(url).then(callback); } diff --git a/src/api/ListViewDataSource.js b/src/api/ListViewDataSource.js index 46d28e0..d6fc334 100644 --- a/src/api/ListViewDataSource.js +++ b/src/api/ListViewDataSource.js @@ -1,13 +1,9 @@ - - class ListViewDataSource { constructor() { this._dataBlob = null; } - getRowCount() { - - } + getRowCount() {} cloneWithRows(data) { const newSource = new ListViewDataSource(); diff --git a/src/api/NetInfo.js b/src/api/NetInfo.js index e6761b5..ac90395 100644 --- a/src/api/NetInfo.js +++ b/src/api/NetInfo.js @@ -9,19 +9,18 @@ const _subscriptions = new Map(); let isExpensive = false; let networkInfo = { - connected: true + connected: true, }; let connectionInfo = { type: 'wifi', - effectiveType: 'unknown' + effectiveType: 'unknown', }; - const NetInfo = { addEventListener(eventname, handler) { const listener = DeviceEventEmitter.addListener( DEVICE_CONNECTIVITY_EVENT, - ({ network_info }) => handler(network_info) + ({network_info}) => handler(network_info), ); _subscriptions.set(handler, listener); }, @@ -40,13 +39,9 @@ const NetInfo = { }, isConnected: { - addEventListener(eventname, handler) { - - }, + addEventListener(eventname, handler) {}, - removeEventListener(eventName, handler) { - - }, + removeEventListener(eventName, handler) {}, fetch() { return NetInfo.fetch().then(info => info.connected); }, @@ -68,7 +63,7 @@ const NetInfo = { isExpensive = expensive; }, __setIsConnected(connected) { - networkInfo = Object.assign({}, networkInfo, { connected }); + networkInfo = Object.assign({}, networkInfo, {connected}); }, __setConnectionInfo(properties) { connectionInfo = Object.assign({}, connectionInfo, properties); @@ -76,7 +71,7 @@ const NetInfo = { getConnectionInfo() { return Promise.resolve(connectionInfo); - } + }, }; module.exports = NetInfo; diff --git a/src/api/PanResponder.js b/src/api/PanResponder.js index d344162..9324203 100644 --- a/src/api/PanResponder.js +++ b/src/api/PanResponder.js @@ -107,7 +107,6 @@ const currentCentroidY = TouchHistoryMath.currentCentroidY; */ const PanResponder = { - /** * * A graphical explanation of the touch data flow: @@ -214,23 +213,29 @@ const PanResponder = { newGestureState.numberActiveTouches = touchHistory.numberActiveTouches; newGestureState.moveX = currentCentroidXOfTouchesChangedAfter( touchHistory, - newGestureState._accountsForMovesUpTo + newGestureState._accountsForMovesUpTo, ); newGestureState.moveY = currentCentroidYOfTouchesChangedAfter( touchHistory, - newGestureState._accountsForMovesUpTo + newGestureState._accountsForMovesUpTo, ); const movedAfter = newGestureState._accountsForMovesUpTo; - const prevX = previousCentroidXOfTouchesChangedAfter(touchHistory, movedAfter); + const prevX = previousCentroidXOfTouchesChangedAfter( + touchHistory, + movedAfter, + ); const x = currentCentroidXOfTouchesChangedAfter(touchHistory, movedAfter); - const prevY = previousCentroidYOfTouchesChangedAfter(touchHistory, movedAfter); + const prevY = previousCentroidYOfTouchesChangedAfter( + touchHistory, + movedAfter, + ); const y = currentCentroidYOfTouchesChangedAfter(touchHistory, movedAfter); const nextDX = newGestureState.dx + (x - prevX); const nextDY = newGestureState.dy + (y - prevY); // TODO: This must be filtered intelligently. const dt = - (touchHistory.mostRecentTimeStamp - newGestureState._accountsForMovesUpTo); + touchHistory.mostRecentTimeStamp - newGestureState._accountsForMovesUpTo; newGestureState.vx = (nextDX - newGestureState.dx) / dt; newGestureState.vy = (nextDY - newGestureState.dy) / dt; @@ -279,12 +284,14 @@ const PanResponder = { PanResponder._initializeGestureState(gestureState); const panHandlers = { onStartShouldSetResponder(e) { - return config.onStartShouldSetPanResponder === undefined ? false : - config.onStartShouldSetPanResponder(e, gestureState); + return config.onStartShouldSetPanResponder === undefined + ? false + : config.onStartShouldSetPanResponder(e, gestureState); }, onMoveShouldSetResponder(e) { - return config.onMoveShouldSetPanResponder === undefined ? false : - config.onMoveShouldSetPanResponder(e, gestureState); + return config.onMoveShouldSetPanResponder === undefined + ? false + : config.onMoveShouldSetPanResponder(e, gestureState); }, onStartShouldSetResponderCapture(e) { // TODO: Actually, we should reinitialize the state any time @@ -293,8 +300,9 @@ const PanResponder = { PanResponder._initializeGestureState(gestureState); } gestureState.numberActiveTouches = e.touchHistory.numberActiveTouches; - return config.onStartShouldSetPanResponderCapture !== undefined ? - config.onStartShouldSetPanResponderCapture(e, gestureState) : false; + return config.onStartShouldSetPanResponderCapture !== undefined + ? config.onStartShouldSetPanResponderCapture(e, gestureState) + : false; }, onMoveShouldSetResponderCapture(e) { @@ -302,12 +310,16 @@ const PanResponder = { // Responder system incorrectly dispatches should* to current responder // Filter out any touch moves past the first one - we would have // already processed multi-touch geometry during the first event. - if (gestureState._accountsForMovesUpTo === touchHistory.mostRecentTimeStamp) { + if ( + gestureState._accountsForMovesUpTo === + touchHistory.mostRecentTimeStamp + ) { return false; } PanResponder._updateGestureStateOnMove(gestureState, touchHistory); - return config.onMoveShouldSetPanResponderCapture ? - config.onMoveShouldSetPanResponderCapture(e, gestureState) : false; + return config.onMoveShouldSetPanResponderCapture + ? config.onMoveShouldSetPanResponderCapture(e, gestureState) + : false; }, onResponderGrant(e) { @@ -319,8 +331,9 @@ const PanResponder = { config.onPanResponderGrant(e, gestureState); } // TODO: t7467124 investigate if this can be removed - return config.onShouldBlockNativeResponder === undefined ? true : - config.onShouldBlockNativeResponder(); + return config.onShouldBlockNativeResponder === undefined + ? true + : config.onShouldBlockNativeResponder(); }, onResponderReject(e) { @@ -348,7 +361,10 @@ const PanResponder = { const touchHistory = e.touchHistory; // Guard against the dispatch of two touch moves when there are two // simultaneously changed touches. - if (gestureState._accountsForMovesUpTo === touchHistory.mostRecentTimeStamp) { + if ( + gestureState._accountsForMovesUpTo === + touchHistory.mostRecentTimeStamp + ) { return; } // Filter out any touch moves past the first one - we would have @@ -375,11 +391,12 @@ const PanResponder = { }, onResponderTerminationRequest(e) { - return config.onPanResponderTerminationRequest === undefined ? true : - config.onPanResponderTerminationRequest(e, gestureState); + return config.onPanResponderTerminationRequest === undefined + ? true + : config.onPanResponderTerminationRequest(e, gestureState); }, }; - return { panHandlers }; + return {panHandlers}; }, }; diff --git a/src/api/PixelRatio.js b/src/api/PixelRatio.js index 3978a31..7552117 100644 --- a/src/api/PixelRatio.js +++ b/src/api/PixelRatio.js @@ -15,9 +15,7 @@ const PixelRatio = { const ratio = PixelRatio.get(); return Math.round(layoutSize * ratio) / ratio; }, - startDetecting() { - - }, + startDetecting() {}, }; module.exports = PixelRatio; diff --git a/src/api/PushNotificationIOS.js b/src/api/PushNotificationIOS.js index 9884e12..064d2cd 100644 --- a/src/api/PushNotificationIOS.js +++ b/src/api/PushNotificationIOS.js @@ -17,9 +17,7 @@ class PushNotificationIOS { * - `soundName` : The sound played when the notification is fired (optional). * */ - static presentLocalNotification(details) { - - } + static presentLocalNotification(details) {} /** * Schedules the localNotification for future presentation. @@ -31,30 +29,22 @@ class PushNotificationIOS { * - `soundName` : The sound played when the notification is fired (optional). * */ - static scheduleLocalNotification(details) { - - } + static scheduleLocalNotification(details) {} /** * Cancels all scheduled localNotifications */ - static cancelAllLocalNotifications() { - - } + static cancelAllLocalNotifications() {} /** * Sets the badge number for the app icon on the home screen */ - static setApplicationIconBadgeNumber(number) { - - } + static setApplicationIconBadgeNumber(number) {} /** * Gets the current badge number for the app icon on the home screen */ - static getApplicationIconBadgeNumber(callback) { - - } + static getApplicationIconBadgeNumber(callback) {} /** * Attaches a listener to remote notification events while the app is running @@ -70,22 +60,22 @@ class PushNotificationIOS { static addEventListener(type, handler) { invariant( type === 'notification' || type === 'register', - 'PushNotificationIOS only supports `notification` and `register` events' + 'PushNotificationIOS only supports `notification` and `register` events', ); let listener; if (type === 'notification') { listener = DeviceEventEmitter.addListener( DEVICE_NOTIF_EVENT, - (notifData) => { + notifData => { handler(new PushNotificationIOS(notifData)); - } + }, ); } else if (type === 'register') { listener = DeviceEventEmitter.addListener( NOTIF_REGISTER_EVENT, - (registrationInfo) => { + registrationInfo => { handler(registrationInfo.deviceToken); - } + }, ); } _notifHandlers.set(handler, listener); @@ -105,9 +95,7 @@ class PushNotificationIOS { * If a map is provided to the method, only the permissions with truthy values * will be requested. */ - static requestPermissions(permissions) { - - } + static requestPermissions(permissions) {} /** * Unregister for all remote notifications received via Apple Push Notification service. @@ -117,9 +105,7 @@ class PushNotificationIOS { * prevent apps from receiving remote notifications through the Notifications section of * the Settings app. Apps unregistered through this method can always re-register. */ - static abandonPermissions() { - - } + static abandonPermissions() {} /** * See what push permissions are currently enabled. `callback` will be @@ -130,10 +116,7 @@ class PushNotificationIOS { * - `sound` :boolean */ static checkPermissions(callback) { - invariant( - typeof callback === 'function', - 'Must provide a valid callback' - ); + invariant(typeof callback === 'function', 'Must provide a valid callback'); } /** @@ -143,7 +126,7 @@ class PushNotificationIOS { static removeEventListener(type, handler) { invariant( type === 'notification' || type === 'register', - 'PushNotificationIOS only supports `notification` and `register` events' + 'PushNotificationIOS only supports `notification` and `register` events', ); const listener = _notifHandlers.get(handler); if (!listener) { @@ -161,8 +144,8 @@ class PushNotificationIOS { * notification object, or `null`. Subsequent invocations will return null. */ static popInitialNotification() { - const initialNotification = _initialNotification && - new PushNotificationIOS(_initialNotification); + const initialNotification = + _initialNotification && new PushNotificationIOS(_initialNotification); _initialNotification = null; return initialNotification; } @@ -179,7 +162,7 @@ class PushNotificationIOS { // https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html - Object.keys(nativeNotif).forEach((notifKey) => { + Object.keys(nativeNotif).forEach(notifKey => { const notifVal = nativeNotif[notifKey]; if (notifKey === 'aps') { this._alert = notifVal.alert; diff --git a/src/api/Settings.js b/src/api/Settings.js index 02e924a..a063cf3 100644 --- a/src/api/Settings.js +++ b/src/api/Settings.js @@ -22,11 +22,11 @@ const Settings = { invariant( Array.isArray(newKeys), - 'keys should be a string or array of strings' + 'keys should be a string or array of strings', ); const sid = subscriptions.length; - subscriptions.push({ keys: newKeys, callback }); + subscriptions.push({keys: newKeys, callback}); return sid; }, @@ -40,13 +40,13 @@ const Settings = { }, _sendObservations(body) { - Object.keys(body).forEach((key) => { + Object.keys(body).forEach(key => { const newValue = body[key]; const didChange = this._settings[key] !== newValue; this._settings[key] = newValue; if (didChange) { - subscriptions.forEach((sub) => { + subscriptions.forEach(sub => { if (sub.keys.indexOf(key) !== -1 && sub.callback) { sub.callback(); } @@ -62,7 +62,7 @@ const Settings = { DeviceEventEmitter.addListener( 'settingsUpdated', - Settings._sendObservations.bind(Settings) + Settings._sendObservations.bind(Settings), ); module.exports = Settings; diff --git a/src/api/StatusBarIOS.js b/src/api/StatusBarIOS.js index 7410329..d831a34 100644 --- a/src/api/StatusBarIOS.js +++ b/src/api/StatusBarIOS.js @@ -3,7 +3,6 @@ let _hidden = false; let _networkActivityIndicatorVisible = true; const StatusBarIOS = { - setStyle(style, animated) { _style = style; }, diff --git a/src/api/StyleSheet.js b/src/api/StyleSheet.js index aef5363..a68e127 100644 --- a/src/api/StyleSheet.js +++ b/src/api/StyleSheet.js @@ -11,7 +11,7 @@ const StyleSheet = { } return styles; - } + }, }; module.exports = StyleSheet; diff --git a/src/api/TextInputState.js b/src/api/TextInputState.js index fd9a4de..5425fc6 100644 --- a/src/api/TextInputState.js +++ b/src/api/TextInputState.js @@ -1,4 +1,3 @@ - const TextInputState = { /** * Internal state @@ -33,7 +32,7 @@ const TextInputState = { if (this._currentlyFocusedID === textFieldID && textFieldID !== null) { this._currentlyFocusedID = null; } - } + }, }; module.exports = TextInputState; diff --git a/src/api/TimePickerAndroid.js b/src/api/TimePickerAndroid.js index cfe9644..9b2a337 100644 --- a/src/api/TimePickerAndroid.js +++ b/src/api/TimePickerAndroid.js @@ -21,7 +21,6 @@ import TimePickerModule from '../NativeModules/TimePickerAndroid'; * ``` */ class TimePickerAndroid { - /** * Opens the standard Android time picker dialog. * @@ -44,11 +43,15 @@ class TimePickerAndroid { /** * A time has been selected. */ - static get timeSetAction() { return 'timeSetAction'; } + static get timeSetAction() { + return 'timeSetAction'; + } /** * The dialog has been dismissed. */ - static get dismissedAction() { return 'dismissedAction'; } + static get dismissedAction() { + return 'dismissedAction'; + } } module.exports = TimePickerAndroid; diff --git a/src/api/TouchHistoryMath.js b/src/api/TouchHistoryMath.js index a8f8b19..6752573 100644 --- a/src/api/TouchHistoryMath.js +++ b/src/api/TouchHistoryMath.js @@ -20,27 +20,37 @@ const TouchHistoryMath = { let total = 0; let count = 0; - const oneTouchData = touchHistory.numberActiveTouches === 1 ? - touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch] : null; + const oneTouchData = + touchHistory.numberActiveTouches === 1 + ? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch] + : null; if (oneTouchData !== null) { - if (oneTouchData.touchActive && oneTouchData.currentTimeStamp > touchesChangedAfter) { + if ( + oneTouchData.touchActive && + oneTouchData.currentTimeStamp > touchesChangedAfter + ) { // FIXME: DONT USE TERNARIES!!!! total += - ofCurrent && isXAxis ? oneTouchData.currentPageX : // eslint-disable-line - ofCurrent && !isXAxis ? oneTouchData.currentPageY : // eslint-disable-line - !ofCurrent && isXAxis ? oneTouchData.previousPageX : - oneTouchData.previousPageY; + ofCurrent && isXAxis // eslint-disable-line + ? oneTouchData.currentPageX + : ofCurrent && !isXAxis // eslint-disable-line + ? oneTouchData.currentPageY + : !ofCurrent && isXAxis + ? oneTouchData.previousPageX + : oneTouchData.previousPageY; count = 1; } } else { for (let i = 0; i < touchBank.length; i++) { const touchTrack = touchBank[i]; - if (touchTrack !== null && + if ( + touchTrack !== null && touchTrack !== undefined && touchTrack.touchActive && - touchTrack.currentTimeStamp >= touchesChangedAfter) { - let toAdd; // Yuck, program temporarily in invalid state. + touchTrack.currentTimeStamp >= touchesChangedAfter + ) { + let toAdd; // Yuck, program temporarily in invalid state. if (ofCurrent && isXAxis) { toAdd = touchTrack.currentPageX; } else if (ofCurrent && !isXAxis) { @@ -62,8 +72,8 @@ const TouchHistoryMath = { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, - true, // isXAxis - true // ofCurrent + true, // isXAxis + true, // ofCurrent ); }, @@ -71,8 +81,8 @@ const TouchHistoryMath = { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, - false, // isXAxis - true // ofCurrent + false, // isXAxis + true, // ofCurrent ); }, @@ -80,8 +90,8 @@ const TouchHistoryMath = { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, - true, // isXAxis - false // ofCurrent + true, // isXAxis + false, // ofCurrent ); }, @@ -89,26 +99,26 @@ const TouchHistoryMath = { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, - false, // isXAxis - false // ofCurrent + false, // isXAxis + false, // ofCurrent ); }, currentCentroidX(touchHistory) { return TouchHistoryMath.centroidDimension( touchHistory, - 0, // touchesChangedAfter - true, // isXAxis - true // ofCurrent + 0, // touchesChangedAfter + true, // isXAxis + true, // ofCurrent ); }, currentCentroidY(touchHistory) { return TouchHistoryMath.centroidDimension( touchHistory, - 0, // touchesChangedAfter - false, // isXAxis - true // ofCurrent + 0, // touchesChangedAfter + false, // isXAxis + true, // ofCurrent ); }, diff --git a/src/api/VibrationIOS.js b/src/api/VibrationIOS.js index 12165fe..93fabd5 100644 --- a/src/api/VibrationIOS.js +++ b/src/api/VibrationIOS.js @@ -14,12 +14,9 @@ import invariant from 'invariant'; const Vibration = { vibrate() { - invariant( - arguments[0] === undefined, - 'Vibration patterns not supported.' - ); + invariant(arguments[0] === undefined, 'Vibration patterns not supported.'); NativeVibration.vibrate(); - } + }, }; module.exports = Vibration; diff --git a/src/components/ART/Path.js b/src/components/ART/Path.js index 56017b3..f27e441 100644 --- a/src/components/ART/Path.js +++ b/src/components/ART/Path.js @@ -2,7 +2,7 @@ const className = require('art/core/class.js'); const Path = require('art/core/path.js'); const SerializablePath = className(Path, { - initialize: (path) => {}, + initialize: path => {}, onReset: () => {}, onMove: (sx, sy, x, y) => {}, onLine: (sx, sy, x, y) => {}, diff --git a/src/components/ART/Transform.js b/src/components/ART/Transform.js index e41a615..c49d721 100644 --- a/src/components/ART/Transform.js +++ b/src/components/ART/Transform.js @@ -1,4 +1,3 @@ - class Transform { constructor() { this.xx = 0; diff --git a/src/components/ActivityIndicator.js b/src/components/ActivityIndicator.js index 068ddad..a12f577 100644 --- a/src/components/ActivityIndicator.js +++ b/src/components/ActivityIndicator.js @@ -27,10 +27,7 @@ const ActivityIndicator = createReactClass({ /** * Size of the indicator. Small has a height of 20, large has a height of 36. */ - size: PropTypes.oneOf([ - 'small', - 'large', - ]), + size: PropTypes.oneOf(['small', 'large']), /** * Invoked on mount and layout changes with * diff --git a/src/components/ActivityIndicatorIOS.js b/src/components/ActivityIndicatorIOS.js index 80d8667..28af379 100644 --- a/src/components/ActivityIndicatorIOS.js +++ b/src/components/ActivityIndicatorIOS.js @@ -26,10 +26,7 @@ const ActivityIndicatorIOS = createReactClass({ /** * Size of the indicator. Small has a height of 20, large has a height of 36. */ - size: PropTypes.oneOf([ - 'small', - 'large', - ]), + size: PropTypes.oneOf(['small', 'large']), /** * Invoked on mount and layout changes with * diff --git a/src/components/DrawerLayoutAndroid.js b/src/components/DrawerLayoutAndroid.js index 6fac89d..8f13796 100644 --- a/src/components/DrawerLayoutAndroid.js +++ b/src/components/DrawerLayoutAndroid.js @@ -42,7 +42,7 @@ const DrawerLayoutAndroid = createReactClass({ */ drawerPosition: ReactPropTypes.oneOf([ DrawerConsts.DrawerPosition.Left, - DrawerConsts.DrawerPosition.Right + DrawerConsts.DrawerPosition.Right, ]), /** * Specifies the width of the drawer, more precisely the width of the view that be pulled in @@ -59,7 +59,7 @@ const DrawerLayoutAndroid = createReactClass({ drawerLockMode: ReactPropTypes.oneOf([ 'unlocked', 'locked-closed', - 'locked-open' + 'locked-open', ]), /** * Function called whenever there is an interaction with the navigation view. @@ -97,7 +97,7 @@ const DrawerLayoutAndroid = createReactClass({ mixins: [NativeMethodsMixin], statics: { - positions: DrawerConsts.DrawerPosition + positions: DrawerConsts.DrawerPosition, }, openDrawer() { @@ -110,8 +110,7 @@ const DrawerLayoutAndroid = createReactClass({ render() { return React.createElement('react-native-mock', null, this.props.children); - } - + }, }); module.exports = DrawerLayoutAndroid; diff --git a/src/components/FlatList.js b/src/components/FlatList.js index d99d614..fe5bf8d 100644 --- a/src/components/FlatList.js +++ b/src/components/FlatList.js @@ -10,82 +10,70 @@ const stylePropType = styleSheetPropType(ViewStylePropTypes); const SCROLLVIEW_REF = 'flatlistscroll'; - const FlatList = createReactClass({ displayName: 'FlatList', propTypes: { ...VirtualizedList.propTypes, /** - * Takes an item from data and renders it into the list. - * Provides additional metadata like index if you need it, as well as a more generic - * separators.updateProps function which let you set whatever props you want to change - * the rendering of either the leading separator or trailing separator in case the more - * common highlight and unhighlight (which set the highlighted: boolean prop) are - * insufficient for your use case. - */ + * Takes an item from data and renders it into the list. + * Provides additional metadata like index if you need it, as well as a more generic + * separators.updateProps function which let you set whatever props you want to change + * the rendering of either the leading separator or trailing separator in case the more + * common highlight and unhighlight (which set the highlighted: boolean prop) are + * insufficient for your use case. + */ renderItem: PropTypes.func, /** - * For simplicity, data is just a plain array. If you want to use something else, - * like an immutable list, use the underlying VirtualizedList directly. - */ + * For simplicity, data is just a plain array. If you want to use something else, + * like an immutable list, use the underlying VirtualizedList directly. + */ data: PropTypes.array, /** - * Rendered in between each item, but not at the top or bottom. By default, - * highlighted and leadingItem props are provided. renderItem provides - * separators.highlight/unhighlight which will update the highlighted prop, - * but you can also add custom props with separators.updateProps. - */ + * Rendered in between each item, but not at the top or bottom. By default, + * highlighted and leadingItem props are provided. renderItem provides + * separators.highlight/unhighlight which will update the highlighted prop, + * but you can also add custom props with separators.updateProps. + */ ItemSeparatorComponent: PropTypes.element, /** - * Optional custom style for multi-item rows generated when numColumns > 1. - */ + * Optional custom style for multi-item rows generated when numColumns > 1. + */ columnWrapperStyle: stylePropType, /** - * Multiple columns can only be rendered with horizontal={false} and will zig-zag - * like a flexWrap layout. Items should all be the same height - masonry layouts are not supported. - */ + * Multiple columns can only be rendered with horizontal={false} and will zig-zag + * like a flexWrap layout. Items should all be the same height - masonry layouts are not supported. + */ numColumns: PropTypes.number, /** - * May not have full feature parity and is meant for debugging and performance comparison. - */ + * May not have full feature parity and is meant for debugging and performance comparison. + */ legacyImplementation: PropTypes.bool, }, - scrollToEnd() { - - }, - - scrollToIndex() { + scrollToEnd() {}, - }, - - scrollToItem() { + scrollToIndex() {}, - }, + scrollToItem() {}, /** - * Scroll to a specific content pixel offset in the list. - * Param offset expects the offset to scroll to. In case of horizontal is true, - * the offset is the x-value, in any other case the offset is the y-value. - * Param animated (true by default) defines whether the list should do an animation while scrolling. - */ - scrollToOffset() { - - }, - - recordInteraction() { - - }, + * Scroll to a specific content pixel offset in the list. + * Param offset expects the offset to scroll to. In case of horizontal is true, + * the offset is the x-value, in any other case the offset is the y-value. + * Param animated (true by default) defines whether the list should do an animation while scrolling. + */ + scrollToOffset() {}, - flashScrollIndicators() { + recordInteraction() {}, - }, + flashScrollIndicators() {}, /** * Exports some data, e.g. for perf investigations or analytics. */ - getMetrics() { // eslint-disable-line react/sort-comp + getMetrics() { + // eslint-disable-line react/sort-comp // It's fixed, but the linter doesnt want to recognise it... return { contentLength: this.scrollProperties.contentLength, @@ -104,9 +92,11 @@ const FlatList = createReactClass({ * such as scrollTo. */ getScrollResponder() { - return this.refs[SCROLLVIEW_REF] && + return ( + this.refs[SCROLLVIEW_REF] && this.refs[SCROLLVIEW_REF].getScrollResponder && - this.refs[SCROLLVIEW_REF].getScrollResponder(); + this.refs[SCROLLVIEW_REF].getScrollResponder() + ); }, setNativeProps(props) { @@ -115,7 +105,7 @@ const FlatList = createReactClass({ getDefaultProps() { return { - renderScrollComponent: (props) => + renderScrollComponent: props => , }; }, @@ -133,12 +123,16 @@ const FlatList = createReactClass({ unhighlight: () => {}, updateProps: () => {}, }, - }) + }), ); }, render() { - return React.createElement('react-native-mock', null, this._renderChildren()); + return React.createElement( + 'react-native-mock', + null, + this._renderChildren(), + ); }, }); diff --git a/src/components/Image.js b/src/components/Image.js index 2693a35..dd3594d 100644 --- a/src/components/Image.js +++ b/src/components/Image.js @@ -109,17 +109,13 @@ const Image = createReactClass({ * Invoked when load either succeeds or fails */ onLoadEnd: PropTypes.func, - children: PropTypes.node + children: PropTypes.node, }, mixins: [NativeMethodsMixin], statics: { resizeMode: ImageResizeMode, - getSize(uri, success, failure) { - - }, - prefetch(uri) { - - } + getSize(uri, success, failure) {}, + prefetch(uri) {}, }, render() { return React.createElement('react-native-mock', null, this.props.children); diff --git a/src/components/ImageBackground.js b/src/components/ImageBackground.js index 84a046a..30f59be 100644 --- a/src/components/ImageBackground.js +++ b/src/components/ImageBackground.js @@ -109,17 +109,13 @@ const ImageBackground = createReactClass({ * Invoked when load either succeeds or fails */ onLoadEnd: PropTypes.func, - children: PropTypes.node + children: PropTypes.node, }, mixins: [NativeMethodsMixin], statics: { resizeMode: ImageResizeMode, - getSize(uri, success, failure) { - - }, - prefetch(uri) { - - } + getSize(uri, success, failure) {}, + prefetch(uri) {}, }, render() { return React.createElement('react-native-mock', null, this.props.children); diff --git a/src/components/ListView.js b/src/components/ListView.js index 14bf16e..8dd2622 100644 --- a/src/components/ListView.js +++ b/src/components/ListView.js @@ -8,7 +8,6 @@ import ListViewDataSource from '../api/ListViewDataSource'; const SCROLLVIEW_REF = 'listviewscroll'; - const ListView = createReactClass({ displayName: 'ListView', propTypes: { @@ -123,7 +122,8 @@ const ListView = createReactClass({ /** * Exports some data, e.g. for perf investigations or analytics. */ - getMetrics() { // eslint-disable-line react/sort-comp + getMetrics() { + // eslint-disable-line react/sort-comp // It's fixed, but the linter doesnt want to recognise it... return { contentLength: this.scrollProperties.contentLength, @@ -142,9 +142,11 @@ const ListView = createReactClass({ * such as scrollTo. */ getScrollResponder() { - return this.refs[SCROLLVIEW_REF] && + return ( + this.refs[SCROLLVIEW_REF] && this.refs[SCROLLVIEW_REF].getScrollResponder && - this.refs[SCROLLVIEW_REF].getScrollResponder(); + this.refs[SCROLLVIEW_REF].getScrollResponder() + ); }, setNativeProps(props) { @@ -153,7 +155,7 @@ const ListView = createReactClass({ getDefaultProps() { return { - renderScrollComponent: (props) => + renderScrollComponent: props => , }; }, diff --git a/src/components/Navigator.js b/src/components/Navigator.js index 6fa9e39..7bb0447 100644 --- a/src/components/Navigator.js +++ b/src/components/Navigator.js @@ -22,7 +22,7 @@ const NavigatorSceneConfigs = { HorizontalSwipeJump: NavigatorSceneConfigType, HorizontalSwipeJumpFromRight: NavigatorSceneConfigType, VerticalUpSwipeJump: NavigatorSceneConfigType, - VerticalDownSwipeJump: NavigatorSceneConfigType + VerticalDownSwipeJump: NavigatorSceneConfigType, }; const Navigator = createReactClass({ @@ -92,17 +92,19 @@ const Navigator = createReactClass({ */ sceneStyle: View.propTypes.style, - children: PropTypes.node + children: PropTypes.node, }, statics: { - BreadcrumbNavigationBar: createMockComponent('NavigatorBreadcrumbNavigationBar'), + BreadcrumbNavigationBar: createMockComponent( + 'NavigatorBreadcrumbNavigationBar', + ), NavigationBar: createMockComponent('NavigatorNavigationBar'), SceneConfigs: NavigatorSceneConfigs, }, render() { return React.createElement('react-native-mock', null, this.props.children); - } + }, }); module.exports = Navigator; diff --git a/src/components/Picker.js b/src/components/Picker.js index b6bd314..0b2cc73 100644 --- a/src/components/Picker.js +++ b/src/components/Picker.js @@ -7,14 +7,14 @@ import createMockComponent from './createMockComponent'; const Picker = createReactClass({ displayName: 'Picker', propTypes: { - children: PropTypes.node + children: PropTypes.node, }, statics: { - Item: createMockComponent('Picker.Item') + Item: createMockComponent('Picker.Item'), }, render() { return React.createElement('react-native-mock', null, this.props.children); - } + }, }); module.exports = Picker; diff --git a/src/components/ScrollView.js b/src/components/ScrollView.js index 9dec52f..02149d4 100644 --- a/src/components/ScrollView.js +++ b/src/components/ScrollView.js @@ -156,7 +156,13 @@ const ScrollView = createReactClass({ * - false, deprecated, use 'never' instead * - true, deprecated, use 'always' instead */ - keyboardShouldPersistTaps: PropTypes.oneOf(['always', 'never', 'handled', false, true]), + keyboardShouldPersistTaps: PropTypes.oneOf([ + 'always', + 'never', + 'handled', + false, + true, + ]), /** * The maximum allowed zoom scale. The default value is 1.0. * @platform ios @@ -308,9 +314,7 @@ const ScrollView = createReactClass({ }, endRefreshin() { - ScrollViewManager.endRefreshing( - React.findNodeHandle(this) - ); + ScrollViewManager.endRefreshing(React.findNodeHandle(this)); }, scrollTo(object) { diff --git a/src/components/StatusBar.js b/src/components/StatusBar.js index 1c6cdd7..ee01802 100644 --- a/src/components/StatusBar.js +++ b/src/components/StatusBar.js @@ -6,7 +6,6 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import ColorPropType from '../propTypes/ColorPropType'; - let _backgroundColor = ''; let _barStyle = {}; let _hidden = false; @@ -23,7 +22,7 @@ const StatusBar = createReactClass({ networkActivityIndicatorVisible: PropTypes.bool, showHideTransition: PropTypes.oneOf(['fade', 'slide']), translucent: PropTypes.bool, - children: PropTypes.node + children: PropTypes.node, }, statics: { @@ -65,12 +64,12 @@ const StatusBar = createReactClass({ __getTranslucent() { return _translucent; - } + }, }, render() { return React.createElement('react-native-mock', null, this.props.children); - } + }, }); module.exports = StatusBar; diff --git a/src/components/TabBarIOS.js b/src/components/TabBarIOS.js index f351035..ff293e3 100644 --- a/src/components/TabBarIOS.js +++ b/src/components/TabBarIOS.js @@ -6,14 +6,14 @@ import createMockComponent from './createMockComponent'; const TabBarIOS = createReactClass({ displayName: 'TabBarIOS', propTypes: { - children: PropTypes.node + children: PropTypes.node, }, statics: { - Item: createMockComponent('TabBarIOS.Item') + Item: createMockComponent('TabBarIOS.Item'), }, render() { return React.createElement('react-native-mock', null, this.props.children); - } + }, }); module.exports = TabBarIOS; diff --git a/src/components/Text.js b/src/components/Text.js index 86108e0..2884449 100644 --- a/src/components/Text.js +++ b/src/components/Text.js @@ -45,7 +45,7 @@ const Text = createReactClass({ * @platform ios */ allowFontScaling: PropTypes.bool, - children: PropTypes.node + children: PropTypes.node, }, mixins: [NativeMethodsMixin], diff --git a/src/components/TextInput.js b/src/components/TextInput.js index 4b3e712..fd15054 100644 --- a/src/components/TextInput.js +++ b/src/components/TextInput.js @@ -66,11 +66,7 @@ const TextInput = createReactClass({ * Determines the color of the keyboard. * @platform ios */ - keyboardAppearance: PropTypes.oneOf([ - 'default', - 'light', - 'dark', - ]), + keyboardAppearance: PropTypes.oneOf(['default', 'light', 'dark']), /** * Determines how the return key should look. * @platform ios @@ -236,12 +232,12 @@ const TextInput = createReactClass({ }, isFocused() { // TODO(lmr): React.findNodeHandle - return TextInputState.currentlyFocusedField() === - React.findNodeHandle(this.refs.input); - }, - clear() { - + return ( + TextInputState.currentlyFocusedField() === + React.findNodeHandle(this.refs.input) + ); }, + clear() {}, render() { return React.createElement('react-native-mock', null, this.props.children); }, diff --git a/src/components/TouchableNativeFeedback.js b/src/components/TouchableNativeFeedback.js index fdcdf80..f60466a 100644 --- a/src/components/TouchableNativeFeedback.js +++ b/src/components/TouchableNativeFeedback.js @@ -10,16 +10,16 @@ const TouchableNativeFeedback = createReactClass({ ...TouchableWithoutFeedback.propTypes, background: PropTypes.object, - children: PropTypes.node + children: PropTypes.node, }, statics: { SelectableBackground() {}, SelectableBackgroundBorderless() {}, - Ripple(color, borderless) {} + Ripple(color, borderless) {}, }, render() { return React.createElement('react-native-mock', null, this.props.children); - } + }, }); module.exports = TouchableNativeFeedback; diff --git a/src/components/TouchableWithoutFeedback.js b/src/components/TouchableWithoutFeedback.js index 038460c..d20d02c 100644 --- a/src/components/TouchableWithoutFeedback.js +++ b/src/components/TouchableWithoutFeedback.js @@ -11,7 +11,9 @@ const TouchableWithoutFeedback = createReactClass({ displayName: 'TouchableWithoutFeedback', propTypes: { accessible: PropTypes.bool, - accessibilityComponentType: PropTypes.oneOf(View.AccessibilityComponentType), + accessibilityComponentType: PropTypes.oneOf( + View.AccessibilityComponentType, + ), accessibilityTraits: PropTypes.oneOfType([ PropTypes.oneOf(View.AccessibilityTraits), PropTypes.arrayOf(PropTypes.oneOf(View.AccessibilityTraits)), @@ -65,7 +67,7 @@ const TouchableWithoutFeedback = createReactClass({ * views. */ hitSlop: EdgeInsetsPropType, - children: PropTypes.node + children: PropTypes.node, }, render() { return React.createElement('react-native-mock', null, this.props.children); diff --git a/src/components/View.js b/src/components/View.js index 8573b5d..5e2bafd 100644 --- a/src/components/View.js +++ b/src/components/View.js @@ -80,11 +80,7 @@ const View = createReactClass({ * for references. * @platform android */ - accessibilityLiveRegion: PropTypes.oneOf([ - 'none', - 'polite', - 'assertive', - ]), + accessibilityLiveRegion: PropTypes.oneOf(['none', 'polite', 'assertive']), /** * Controls how view is important for accessibility which is if it @@ -194,12 +190,7 @@ const View = createReactClass({ * implement it as a `className` anyways. Using `style` or not is an * implementation detail of the platform. */ - pointerEvents: PropTypes.oneOf([ - 'box-none', - 'none', - 'box-only', - 'auto', - ]), + pointerEvents: PropTypes.oneOf(['box-none', 'none', 'box-only', 'auto']), style: stylePropType, /** @@ -274,7 +265,7 @@ const View = createReactClass({ */ needsOffscreenAlphaCompositing: PropTypes.bool, - children: PropTypes.node + children: PropTypes.node, }, mixins: [NativeMethodsMixin], diff --git a/src/components/VirtualizedList.js b/src/components/VirtualizedList.js index f73aaad..e9b81da 100644 --- a/src/components/VirtualizedList.js +++ b/src/components/VirtualizedList.js @@ -7,222 +7,212 @@ import ViewabilityConfigCallbackPair from '../propTypes/ViewabilityConfigCallbac const SCROLLVIEW_REF = 'virtualizedviewscroll'; - const VirtualizedList = createReactClass({ displayName: 'VirtualizedList', propTypes: { ...ScrollView.propTypes, /** - * Takes an item from data and renders it into the list - */ + * Takes an item from data and renders it into the list + */ renderItem: PropTypes.func, /** - * The default accessor functions assume this is an array - * of objects with shape {key: string} but you can override - * getItem, getItemCount, and keyExtractor to handle any type of index-based data. - */ + * The default accessor functions assume this is an array + * of objects with shape {key: string} but you can override + * getItem, getItemCount, and keyExtractor to handle any type of index-based data. + */ data: PropTypes.any, /** - * A generic accessor for extracting an item from any sort of data blob. - */ + * A generic accessor for extracting an item from any sort of data blob. + */ getItem: PropTypes.func, /** - * Determines how many items are in the data blob. - */ + * Determines how many items are in the data blob. + */ getItemCount: PropTypes.func, /** - * debug will turn on extra logging and visual overlays to aid - * with debugging both usage and implementation, but with a significant perf hit. - */ + * debug will turn on extra logging and visual overlays to aid + * with debugging both usage and implementation, but with a significant perf hit. + */ debug: PropTypes.bool, /** - * A marker property for telling the list to re-render (since it implements PureComponent). - * If any of your renderItem, Header, Footer, etc. functions depend on - * anything outside of the data prop, stick it here and treat it immutably. - */ + * A marker property for telling the list to re-render (since it implements PureComponent). + * If any of your renderItem, Header, Footer, etc. functions depend on + * anything outside of the data prop, stick it here and treat it immutably. + */ extraData: PropTypes.any, /** - * getItemLayout is an optional optimization that let us skip measurement of dynamic - * content if you know the height of items a priori. getItemLayout is the most efficient, - * and is easy to use if you have fixed height items, for example: - * getItemLayout={(data, index) => ( - * {length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index, index} - * )} - * Adding getItemLayout can be a great performance boost for lists of several hundred items. - * Remember to include separator length (height or width) in your offset calculation if you - * specify ItemSeparatorComponent. - */ + * getItemLayout is an optional optimization that let us skip measurement of dynamic + * content if you know the height of items a priori. getItemLayout is the most efficient, + * and is easy to use if you have fixed height items, for example: + * getItemLayout={(data, index) => ( + * {length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index, index} + * )} + * Adding getItemLayout can be a great performance boost for lists of several hundred items. + * Remember to include separator length (height or width) in your offset calculation if you + * specify ItemSeparatorComponent. + */ getItemLayout: PropTypes.func, /** - * Instead of starting at the top with the first item, start at initialScrollIndex. - * This disables the "scroll to top" optimization that keeps the first - * initialNumToRender items always rendered and immediately renders the items - * starting at this initial index. Requires getItemLayout to be implemented. - */ + * Instead of starting at the top with the first item, start at initialScrollIndex. + * This disables the "scroll to top" optimization that keeps the first + * initialNumToRender items always rendered and immediately renders the items + * starting at this initial index. Requires getItemLayout to be implemented. + */ initialScrollIndex: PropTypes.number, /** - * Reverses the direction of scroll. Uses scale transforms of -1. - */ + * Reverses the direction of scroll. Uses scale transforms of -1. + */ inverted: PropTypes.bool, /** - * Each cell is rendered using this element. Can be a React Component Class,or a - * render function. Defaults to using View. - */ + * Each cell is rendered using this element. Can be a React Component Class,or a + * render function. Defaults to using View. + */ CellRendererComponent: PropTypes.oneOfType([ PropTypes.element, PropTypes.func, ]), /** - * Rendered when the list is empty. Can be a React Component Class, - * a render function, or a rendered element. - */ + * Rendered when the list is empty. Can be a React Component Class, + * a render function, or a rendered element. + */ ListEmptyComponent: PropTypes.oneOfType([ PropTypes.element, PropTypes.func, ]), /** - * Rendered at the bottom of all the items. Can be a React Component - * Class, a render function, or a rendered element. - */ + * Rendered at the bottom of all the items. Can be a React Component + * Class, a render function, or a rendered element. + */ ListFooterComponent: PropTypes.oneOfType([ PropTypes.element, PropTypes.func, ]), /** - * Rendered at the top of all the items. Can be a React Component Class, - * a render function, or a rendered element. - */ + * Rendered at the top of all the items. Can be a React Component Class, + * a render function, or a rendered element. + */ ListHeaderComponent: PropTypes.oneOfType([ PropTypes.element, PropTypes.func, ]), onLayout: PropTypes.func, /** - * If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. - * Make sure to also set the refreshing prop correctly. - */ + * If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. + * Make sure to also set the refreshing prop correctly. + */ onRefresh: PropTypes.func, /** - * Used to handle failures when scrolling to an index that has not been measured yet. - * Recommended action is to either compute your own offset and scrollTo it, - * or scroll as far as possible and then try again after more items have been rendered. - */ + * Used to handle failures when scrolling to an index that has not been measured yet. + * Recommended action is to either compute your own offset and scrollTo it, + * or scroll as far as possible and then try again after more items have been rendered. + */ onScrollToIndexFailed: PropTypes.func, /** - * Called when the viewability of rows changes, as defined by the viewabilityConfig prop. - */ + * Called when the viewability of rows changes, as defined by the viewabilityConfig prop. + */ onViewableItemsChanged: PropTypes.func, /** - * Set this true while waiting for new data from a refresh. - */ + * Set this true while waiting for new data from a refresh. + */ refreshing: PropTypes.bool, /** - * This may improve scroll performance for large lists. - */ + * This may improve scroll performance for large lists. + */ removeClippedSubviews: PropTypes.bool, /** - * Render a custom scroll component, e.g. with a differently styled RefreshControl. - */ + * Render a custom scroll component, e.g. with a differently styled RefreshControl. + */ renderScrollComponent: PropTypes.func, /** - * See ViewabilityHelper.js for flow type and further documentation. - */ + * See ViewabilityHelper.js for flow type and further documentation. + */ viewabilityConfig: ViewabilityConfig, /** - * List of ViewabilityConfig/onViewableItemsChanged pairs. A specific onViewableItemsChanged - * will be called when its corresponding ViewabilityConfig's conditions are met. - * See ViewabilityHelper.js for flow type and further documentation. - */ - viewabilityConfigCallbackPairs: PropTypes.arrayOf(ViewabilityConfigCallbackPair), + * List of ViewabilityConfig/onViewableItemsChanged pairs. A specific onViewableItemsChanged + * will be called when its corresponding ViewabilityConfig's conditions are met. + * See ViewabilityHelper.js for flow type and further documentation. + */ + viewabilityConfigCallbackPairs: PropTypes.arrayOf( + ViewabilityConfigCallbackPair, + ), /** - * If true, renders items next to each other horizontally instead of stacked vertically. - */ + * If true, renders items next to each other horizontally instead of stacked vertically. + */ horizontal: PropTypes.bool, /** - * How many items to render in the initial batch. This should be enough to fill - * the screen but not much more. Note these items will never be unmounted as - * part of the windowed rendering in order to improve perceived performance of scroll-to-top actions. - */ + * How many items to render in the initial batch. This should be enough to fill + * the screen but not much more. Note these items will never be unmounted as + * part of the windowed rendering in order to improve perceived performance of scroll-to-top actions. + */ initialNumToRender: PropTypes.number, /** - * Used to extract a unique key for a given item at the specified index. - * Key is used for caching and as the react key to track item re-ordering. - * The default extractor checks item.key, then falls back to using the index, like React does. - */ + * Used to extract a unique key for a given item at the specified index. + * Key is used for caching and as the react key to track item re-ordering. + * The default extractor checks item.key, then falls back to using the index, like React does. + */ keyExtractor: PropTypes.func, /** - * The maximum number of items to render in each incremental render batch. - * The more rendered at once, the better the fill rate, but responsiveness - * my suffer because rendering content may interfere with responding to - * button taps or other interactions. - */ + * The maximum number of items to render in each incremental render batch. + * The more rendered at once, the better the fill rate, but responsiveness + * my suffer because rendering content may interfere with responding to + * button taps or other interactions. + */ maxToRenderPerBatch: PropTypes.number, /** - * Called once when the scroll position gets within onEndReachedThreshold of the rendered content. - */ + * Called once when the scroll position gets within onEndReachedThreshold of the rendered content. + */ onEndReached: PropTypes.func, /** - * How far from the end (in units of visible length of the list) the bottom edge - * of the list must be from the end of the content to trigger the onEndReached callback. - * Thus a value of 0.5 will trigger onEndReached when the end of the content is - * within half the visible length of the list. - */ + * How far from the end (in units of visible length of the list) the bottom edge + * of the list must be from the end of the content to trigger the onEndReached callback. + * Thus a value of 0.5 will trigger onEndReached when the end of the content is + * within half the visible length of the list. + */ onEndReachedThreshold: PropTypes.number, /** - * Amount of time between low-pri item render batches, e.g. for rendering - * items quite a ways off screen. Similar fill rate/responsiveness tradeoff as maxToRenderPerBatch. - */ + * Amount of time between low-pri item render batches, e.g. for rendering + * items quite a ways off screen. Similar fill rate/responsiveness tradeoff as maxToRenderPerBatch. + */ updateCellsBatchingPeriod: PropTypes.number, /** - * Determines the maximum number of items rendered outside of the visible area, - * in units of visible lengths. So if your list fills the screen, then windowSize={21} - * (the default) will render the visible screen area plus up to 10 screens above and - * 10 below the viewport. Reducing this number will reduce memory consumption and may - * improve performance, but will increase the chance that fast scrolling may - * reveal momentary blank areas of unrendered content. - */ + * Determines the maximum number of items rendered outside of the visible area, + * in units of visible lengths. So if your list fills the screen, then windowSize={21} + * (the default) will render the visible screen area plus up to 10 screens above and + * 10 below the viewport. Reducing this number will reduce memory consumption and may + * improve performance, but will increase the chance that fast scrolling may + * reveal momentary blank areas of unrendered content. + */ windowSize: PropTypes.number, /** - * Set this when offset is needed for the loading indicator to show correctly. - */ + * Set this when offset is needed for the loading indicator to show correctly. + */ progressViewOffset: PropTypes.number, }, - scrollToEnd() { - - }, - - scrollToIndex() { + scrollToEnd() {}, - }, - - scrollToItem() { + scrollToIndex() {}, - }, + scrollToItem() {}, /** - * Scroll to a specific content pixel offset in the list. - * Param offset expects the offset to scroll to. In case of horizontal is true, - * the offset is the x-value, in any other case the offset is the y-value. - * Param animated (true by default) defines whether the list should do an animation while scrolling. - */ - scrollToOffset() { - - }, - - recordInteraction() { - - }, + * Scroll to a specific content pixel offset in the list. + * Param offset expects the offset to scroll to. In case of horizontal is true, + * the offset is the x-value, in any other case the offset is the y-value. + * Param animated (true by default) defines whether the list should do an animation while scrolling. + */ + scrollToOffset() {}, - flashScrollIndicators() { + recordInteraction() {}, - }, + flashScrollIndicators() {}, /** * Exports some data, e.g. for perf investigations or analytics. */ - getMetrics() { // eslint-disable-line react/sort-comp + getMetrics() { + // eslint-disable-line react/sort-comp // It's fixed, but the linter doesnt want to recognise it... return { contentLength: this.scrollProperties.contentLength, @@ -241,9 +231,11 @@ const VirtualizedList = createReactClass({ * such as scrollTo. */ getScrollResponder() { - return this.refs[SCROLLVIEW_REF] && + return ( + this.refs[SCROLLVIEW_REF] && this.refs[SCROLLVIEW_REF].getScrollResponder && - this.refs[SCROLLVIEW_REF].getScrollResponder(); + this.refs[SCROLLVIEW_REF].getScrollResponder() + ); }, setNativeProps(props) { @@ -252,7 +244,7 @@ const VirtualizedList = createReactClass({ getDefaultProps() { return { - renderScrollComponent: (props) => + renderScrollComponent: props => , }; }, @@ -270,12 +262,16 @@ const VirtualizedList = createReactClass({ unhighlight: () => {}, updateProps: () => {}, }, - }) + }), ); }, render() { - return React.createElement('react-native-mock', null, this._renderChildren()); + return React.createElement( + 'react-native-mock', + null, + this._renderChildren(), + ); }, }); diff --git a/src/components/createMockComponent.js b/src/components/createMockComponent.js index 6bad9c8..735881f 100644 --- a/src/components/createMockComponent.js +++ b/src/components/createMockComponent.js @@ -6,10 +6,14 @@ function createMockComponent(displayName) { return createReactClass({ displayName, propTypes: { - children: PropTypes.node + children: PropTypes.node, }, render() { - return React.createElement('react-native-mock', null, this.props.children); + return React.createElement( + 'react-native-mock', + null, + this.props.children, + ); }, }); } diff --git a/src/mixins/NativeMethodsMixin.js b/src/mixins/NativeMethodsMixin.js index e237055..2e0d5a8 100644 --- a/src/mixins/NativeMethodsMixin.js +++ b/src/mixins/NativeMethodsMixin.js @@ -2,21 +2,11 @@ * https://github.com/facebook/react-native/blob/master/Libraries/ReactIOS/NativeMethodsMixin.js */ module.exports = { - measure(callback) { - - }, - measureLayout(relativeToNativeNode, onSuccess, onFail) { - - }, - setNativeProps(nativeProps) { - - }, - focus() { - - }, - blur() { - - }, + measure(callback) {}, + measureLayout(relativeToNativeNode, onSuccess, onFail) {}, + setNativeProps(nativeProps) {}, + focus() {}, + blur() {}, measureInWindow(callback) { callback(10, 10, 10, 10); }, diff --git a/src/mixins/ScrollResponder.js b/src/mixins/ScrollResponder.js index afea6ef..62602b1 100644 --- a/src/mixins/ScrollResponder.js +++ b/src/mixins/ScrollResponder.js @@ -157,9 +157,11 @@ const ScrollResponderMixin = { scrollResponderHandleStartShouldSetResponderCapture(e) { // First see if we want to eat taps while the keyboard is up const currentlyFocusedTextInput = TextInputState.currentlyFocusedField(); - if (!this.props.keyboardShouldPersistTaps && + if ( + !this.props.keyboardShouldPersistTaps && currentlyFocusedTextInput != null && - e.target !== currentlyFocusedTextInput) { + e.target !== currentlyFocusedTextInput + ) { return true; } return this.scrollResponderIsAnimating(); @@ -222,11 +224,13 @@ const ScrollResponderMixin = { // By default scroll views will unfocus a textField // if another touch occurs outside of it const currentlyFocusedTextInput = TextInputState.currentlyFocusedField(); - if (!this.props.keyboardShouldPersistTaps && + if ( + !this.props.keyboardShouldPersistTaps && currentlyFocusedTextInput != null && e.target !== currentlyFocusedTextInput && !this.state.observedScrollSinceBecomingResponder && - !this.state.becameResponderWhileAnimating) { + !this.state.becameResponderWhileAnimating + ) { if (this.props.onScrollResponderKeyboardDismissed) { this.props.onScrollResponderKeyboardDismissed(e); } @@ -336,9 +340,12 @@ const ScrollResponderMixin = { */ scrollResponderIsAnimating() { const now = Date.now(); - const timeSinceLastMomentumScrollEnd = now - this.state.lastMomentumScrollEndTime; - const isAnimating = timeSinceLastMomentumScrollEnd < IS_ANIMATING_TOUCH_START_THRESHOLD_MS || - this.state.lastMomentumScrollEndTime < this.state.lastMomentumScrollBeginTime; + const timeSinceLastMomentumScrollEnd = + now - this.state.lastMomentumScrollEndTime; + const isAnimating = + timeSinceLastMomentumScrollEnd < IS_ANIMATING_TOUCH_START_THRESHOLD_MS || + this.state.lastMomentumScrollEndTime < + this.state.lastMomentumScrollBeginTime; return isAnimating; }, @@ -347,9 +354,7 @@ const ScrollResponderMixin = { * This is currently used to help focus on child textviews, but this * can also be used to quickly scroll to any element we want to focus */ - scrollResponderScrollTo(offsetX, offsetY, animated = true) { - - }, + scrollResponderScrollTo(offsetX, offsetY, animated = true) {}, /** * A helper function to zoom to a specific rect in the scrollview. @@ -377,14 +382,15 @@ const ScrollResponderMixin = { scrollResponderScrollNativeHandleToKeyboard( nodeHandle, additionalOffset, - preventNegativeScrollOffset) { + preventNegativeScrollOffset, + ) { this.additionalScrollOffset = additionalOffset || 0; this.preventNegativeScrollOffset = !!preventNegativeScrollOffset; UIManager.measureLayout( nodeHandle, React.findNodeHandle(this.getInnerViewNode()), this.scrollResponderTextInputFocusError, - this.scrollResponderInputMeasureAndScrollToKeyboard + this.scrollResponderInputMeasureAndScrollToKeyboard, ); }, @@ -403,7 +409,8 @@ const ScrollResponderMixin = { if (this.keyboardWillOpenTo) { keyboardScreenY = this.keyboardWillOpenTo.endCoordinates.screenY; } - let scrollOffsetY = top - keyboardScreenY + height + this.additionalScrollOffset; + let scrollOffsetY = + top - keyboardScreenY + height + this.additionalScrollOffset; // By default, this can scroll with negative offset, pulling the content // down so that the target component's bottom meets the keyboard's top. @@ -432,13 +439,25 @@ const ScrollResponderMixin = { this.keyboardWillOpenTo = null; this.additionalScrollOffset = 0; this.addListenerOn( - DeviceEventEmitter, 'keyboardWillShow', this.scrollResponderKeyboardWillShow + DeviceEventEmitter, + 'keyboardWillShow', + this.scrollResponderKeyboardWillShow, + ); + this.addListenerOn( + DeviceEventEmitter, + 'keyboardWillHide', + this.scrollResponderKeyboardWillHide, ); this.addListenerOn( - DeviceEventEmitter, 'keyboardWillHide', this.scrollResponderKeyboardWillHide + DeviceEventEmitter, + 'keyboardDidShow', + this.scrollResponderKeyboardDidShow, + ); + this.addListenerOn( + DeviceEventEmitter, + 'keyboardDidHide', + this.scrollResponderKeyboardDidHide, ); - this.addListenerOn(DeviceEventEmitter, 'keyboardDidShow', this.scrollResponderKeyboardDidShow); - this.addListenerOn(DeviceEventEmitter, 'keyboardDidHide', this.scrollResponderKeyboardDidHide); }, /** @@ -499,7 +518,7 @@ const ScrollResponderMixin = { if (this.props.onKeyboardDidHide) { this.props.onKeyboardDidHide(e); } - } + }, }; const ScrollResponder = { diff --git a/src/mixins/Subscribable.js b/src/mixins/Subscribable.js index fb218dd..a1ceb4e 100644 --- a/src/mixins/Subscribable.js +++ b/src/mixins/Subscribable.js @@ -1,20 +1,22 @@ - const SubscribableMixin = { componentWillMount() { this._subscriptions = []; }, componentWillUnmount() { - this._subscriptions.forEach( - (subscription) => subscription.eventEmitter.removeListener(subscription.eventType, subscription.listener) + this._subscriptions.forEach(subscription => + subscription.eventEmitter.removeListener( + subscription.eventType, + subscription.listener, + ), ); this._subscriptions = null; }, addListenerOn(eventEmitter, eventType, listener, context) { eventEmitter.addListener(eventType, listener, context); - this._subscriptions.push({ eventEmitter, eventType, listener }); - } + this._subscriptions.push({eventEmitter, eventType, listener}); + }, }; const Subscribable = { diff --git a/src/propTypes/ColorPropType.js b/src/propTypes/ColorPropType.js index 6a0e1fb..5a55fc6 100644 --- a/src/propTypes/ColorPropType.js +++ b/src/propTypes/ColorPropType.js @@ -1,7 +1,7 @@ /** * https://github.com/facebook/react-native/blob/master/Libraries/StyleSheet/ColorPropType.js */ -const ColorPropType = function (props, propName) { +const ColorPropType = function(props, propName) { const color = props[propName]; if (color === undefined || color === null) { // return; diff --git a/src/propTypes/ImageResizeMode.js b/src/propTypes/ImageResizeMode.js index 055321c..658efe9 100644 --- a/src/propTypes/ImageResizeMode.js +++ b/src/propTypes/ImageResizeMode.js @@ -1,10 +1,6 @@ import Platfrom from '../plugins/Platform'; -const resizePropTypes = [ - 'contain', - 'cover', - 'stretch', -]; +const resizePropTypes = ['contain', 'cover', 'stretch']; if (Platfrom.OS === 'ios') { resizePropTypes.push('repeat', 'center'); diff --git a/src/propTypes/LayoutPropTypes.js b/src/propTypes/LayoutPropTypes.js index ce31b68..c697eab 100644 --- a/src/propTypes/LayoutPropTypes.js +++ b/src/propTypes/LayoutPropTypes.js @@ -16,126 +16,48 @@ import PropTypes from 'prop-types'; * algorithm and affect the positioning and sizing of views. */ const LayoutPropTypes = { - width: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - height: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - top: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - left: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - right: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - bottom: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - minWidth: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - maxWidth: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - minHeight: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - maxHeight: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - margin: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - marginVertical: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - marginHorizontal: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - marginTop: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - marginBottom: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - marginLeft: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - marginRight: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - padding: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - paddingVertical: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - paddingHorizontal: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - paddingTop: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - paddingBottom: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - paddingLeft: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - paddingRight: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), + width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + top: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + left: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + right: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + bottom: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + minWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + maxWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + minHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + maxHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + margin: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + marginVertical: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + marginHorizontal: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + marginTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + marginBottom: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + marginLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + marginRight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + padding: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + paddingVertical: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + paddingHorizontal: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + paddingTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + paddingBottom: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + paddingLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + paddingRight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), borderWidth: PropTypes.number, borderTopWidth: PropTypes.number, borderRightWidth: PropTypes.number, borderBottomWidth: PropTypes.number, borderLeftWidth: PropTypes.number, - position: PropTypes.oneOf([ - 'absolute', - 'relative' - ]), + position: PropTypes.oneOf(['absolute', 'relative']), // https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction flexDirection: PropTypes.oneOf([ 'row', 'column', 'row-reverse', - 'column-reverse' + 'column-reverse', ]), // https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap - flexWrap: PropTypes.oneOf([ - 'wrap', - 'nowrap' - ]), + flexWrap: PropTypes.oneOf(['wrap', 'nowrap']), // How to align children in the main direction // https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content @@ -144,7 +66,7 @@ const LayoutPropTypes = { 'flex-end', 'center', 'space-between', - 'space-around' + 'space-around', ]), // How to align children in the cross direction @@ -154,7 +76,7 @@ const LayoutPropTypes = { 'flex-end', 'center', 'stretch', - 'baseline' + 'baseline', ]), // How to align the element in the cross direction @@ -165,23 +87,16 @@ const LayoutPropTypes = { 'flex-end', 'center', 'stretch', - 'baseline' + 'baseline', ]), - overflow: PropTypes.oneOf([ - 'visible', - 'hidden', - 'scroll' - ]), + overflow: PropTypes.oneOf(['visible', 'hidden', 'scroll']), // https://developer.mozilla.org/en-US/docs/Web/CSS/flex flex: PropTypes.number, flexGrow: PropTypes.number, flexShrink: PropTypes.number, - flexBasis: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), + flexBasis: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), aspectRatio: PropTypes.number, diff --git a/src/propTypes/StyleSheetPropType.js b/src/propTypes/StyleSheetPropType.js index ecc9cc3..8a8bd2f 100644 --- a/src/propTypes/StyleSheetPropType.js +++ b/src/propTypes/StyleSheetPropType.js @@ -6,7 +6,7 @@ import flattenStyle from './flattenStyle'; function StyleSheetPropType(shape) { const shapePropType = PropTypes.shape(shape); - return function (props, propName, componentName, ...rest) { + return function(props, propName, componentName, ...rest) { let newProps = props; if (props[propName]) { // Just make a dummy prop object with only the flattened style diff --git a/src/propTypes/TextStylePropTypes.js b/src/propTypes/TextStylePropTypes.js index ae9b07e..23740dc 100644 --- a/src/propTypes/TextStylePropTypes.js +++ b/src/propTypes/TextStylePropTypes.js @@ -16,10 +16,19 @@ const TextStylePropTypes = Object.assign(Object.create(ViewStylePropTypes), { * most fonts. Not all fonts have a variant for each of the numeric values, * in that case the closest one is chosen. */ - fontWeight: PropTypes.oneOf( - ['normal', 'bold', - '100', '200', '300', '400', '500', '600', '700', '800', '900'] - ), + fontWeight: PropTypes.oneOf([ + 'normal', + 'bold', + '100', + '200', + '300', + '400', + '500', + '600', + '700', + '800', + '900', + ]), /** * @platform ios */ @@ -30,14 +39,12 @@ const TextStylePropTypes = Object.assign(Object.create(ViewStylePropTypes), { 'lining-nums', 'tabular-nums', 'proportional-nums', - ]) - ), - textShadowOffset: PropTypes.shape( - { - width: PropTypes.number, - height: PropTypes.number - } + ]), ), + textShadowOffset: PropTypes.shape({ + width: PropTypes.number, + height: PropTypes.number, + }), textShadowRadius: PropTypes.number, textShadowColor: ColorPropType, /** @@ -48,27 +55,24 @@ const TextStylePropTypes = Object.assign(Object.create(ViewStylePropTypes), { /** * Specifies text alignment. The value 'justify' is only supported on iOS. */ - textAlign: PropTypes.oneOf( - ['auto', 'left', 'right', 'center', 'justify'] - ), + textAlign: PropTypes.oneOf(['auto', 'left', 'right', 'center', 'justify']), /** * @platform android */ - textAlignVertical: PropTypes.oneOf( - ['auto', 'top', 'bottom', 'center'] - ), + textAlignVertical: PropTypes.oneOf(['auto', 'top', 'bottom', 'center']), /** * @platform ios */ - textDecorationLine: PropTypes.oneOf( - ['none', 'underline', 'line-through', 'underline line-through'] - ), + textDecorationLine: PropTypes.oneOf([ + 'none', + 'underline', + 'line-through', + 'underline line-through', + ]), /** * @platform ios */ - textDecorationStyle: PropTypes.oneOf( - ['solid', 'double', 'dotted', 'dashed'] - ), + textDecorationStyle: PropTypes.oneOf(['solid', 'double', 'dotted', 'dashed']), /** * @platform ios */ @@ -76,9 +80,7 @@ const TextStylePropTypes = Object.assign(Object.create(ViewStylePropTypes), { /** * @platform ios */ - writingDirection: PropTypes.oneOf( - ['auto', 'ltr', 'rtl'] - ), + writingDirection: PropTypes.oneOf(['auto', 'ltr', 'rtl']), }); module.exports = TextStylePropTypes; diff --git a/src/propTypes/TransformPropTypes.js b/src/propTypes/TransformPropTypes.js index 1096460..408b209 100644 --- a/src/propTypes/TransformPropTypes.js +++ b/src/propTypes/TransformPropTypes.js @@ -5,11 +5,16 @@ import PropTypes from 'prop-types'; const arrayOfNumberPropType = PropTypes.arrayOf(PropTypes.number); -const transformMatrixPropType = function (props, propName, componentName, ...rest) { +const transformMatrixPropType = function( + props, + propName, + componentName, + ...rest +) { if (props.transform && props.transformMatrix) { return new Error( 'transformMatrix and transform styles cannot be used on the same ' + - 'component' + 'component', ); } return arrayOfNumberPropType(props, propName, componentName, ...rest); @@ -18,19 +23,19 @@ const transformMatrixPropType = function (props, propName, componentName, ...res const transformPropTypes = { transform: PropTypes.arrayOf( PropTypes.oneOfType([ - PropTypes.shape({ perspective: PropTypes.number }), - PropTypes.shape({ rotate: PropTypes.string }), - PropTypes.shape({ rotateX: PropTypes.string }), - PropTypes.shape({ rotateY: PropTypes.string }), - PropTypes.shape({ rotateZ: PropTypes.string }), - PropTypes.shape({ scale: PropTypes.number }), - PropTypes.shape({ scaleX: PropTypes.number }), - PropTypes.shape({ scaleY: PropTypes.number }), - PropTypes.shape({ translateX: PropTypes.number }), - PropTypes.shape({ translateY: PropTypes.number }), - PropTypes.shape({ skewX: PropTypes.string }), - PropTypes.shape({ skewY: PropTypes.string }), - ]) + PropTypes.shape({perspective: PropTypes.number}), + PropTypes.shape({rotate: PropTypes.string}), + PropTypes.shape({rotateX: PropTypes.string}), + PropTypes.shape({rotateY: PropTypes.string}), + PropTypes.shape({rotateZ: PropTypes.string}), + PropTypes.shape({scale: PropTypes.number}), + PropTypes.shape({scaleX: PropTypes.number}), + PropTypes.shape({scaleY: PropTypes.number}), + PropTypes.shape({translateX: PropTypes.number}), + PropTypes.shape({translateY: PropTypes.number}), + PropTypes.shape({skewX: PropTypes.string}), + PropTypes.shape({skewY: PropTypes.string}), + ]), ), transformMatrix: transformMatrixPropType, }; diff --git a/src/propTypes/ViewPropTypes.js b/src/propTypes/ViewPropTypes.js index 5518a2f..a6dbdc2 100644 --- a/src/propTypes/ViewPropTypes.js +++ b/src/propTypes/ViewPropTypes.js @@ -5,7 +5,10 @@ import EdgeInsetsPropType from './EdgeInsetsPropType'; import styleSheetPropType from './StyleSheetPropType'; import ViewStylePropTypes from './ViewStylePropTypes'; -import { AccessibilityComponentTypes, AccessibilityTraits } from '../components/ViewAccessibility'; +import { + AccessibilityComponentTypes, + AccessibilityTraits, +} from '../components/ViewAccessibility'; import PropTypes from 'prop-types'; const stylePropType = styleSheetPropType(ViewStylePropTypes); @@ -53,11 +56,7 @@ const ViewPropTypes = { * * @platform android */ - accessibilityLiveRegion: PropTypes.oneOf([ - 'none', - 'polite', - 'assertive', - ]), + accessibilityLiveRegion: PropTypes.oneOf(['none', 'polite', 'assertive']), /** * Controls how view is important for accessibility which is if it @@ -313,12 +312,7 @@ const ViewPropTypes = { * > implement it as a `className` anyways. Using `style` or not is an * > implementation detail of the platform. */ - pointerEvents: PropTypes.oneOf([ - 'box-none', - 'none', - 'box-only', - 'auto', - ]), + pointerEvents: PropTypes.oneOf(['box-none', 'none', 'box-only', 'auto']), style: stylePropType, /** diff --git a/src/react-native.js b/src/react-native.js index 78329a1..a955dfd 100644 --- a/src/react-native.js +++ b/src/react-native.js @@ -30,7 +30,9 @@ const ReactNative = { ProgressBarAndroid: createMockComponent('ProgressBarAndroid'), ProgressViewIOS: createMockComponent('ProgressViewIOS'), PullToRefreshViewAndroid: createMockComponent('PullToRefreshViewAndroid'), - RecyclerViewBackedScrollView: createMockComponent('RecyclerViewBackedScrollView'), + RecyclerViewBackedScrollView: createMockComponent( + 'RecyclerViewBackedScrollView', + ), RefreshControl: createMockComponent('RefreshControl'), SafeAreaView: createMockComponent('SafeAreaView'), ScrollView: require('./components/ScrollView'), @@ -109,7 +111,6 @@ const ReactNative = { ViewPropTypes: require('./propTypes/ViewPropTypes'), }; - // See http://facebook.github.io/react/docs/addons.html const ReactNativeAddons = { // LinkedStateMixin: require('react-addons-linked-state-mixin') deprecated, @@ -121,6 +122,6 @@ const ReactNativeAddons = { // update: require('react-addons-update'), }; -Object.assign(ReactNative, React, { addons: ReactNativeAddons }); +Object.assign(ReactNative, React, {addons: ReactNativeAddons}); module.exports = ReactNative; diff --git a/src/requireLibrary.js b/src/requireLibrary.js index e94a286..9831ba6 100644 --- a/src/requireLibrary.js +++ b/src/requireLibrary.js @@ -8,7 +8,6 @@ const absolutePathToRN = require.resolve('react-native'); const relativePathToRN = path.relative(__filename, absolutePathToRN); const pathToLibraries = path.join(relativePathToRN, '../../'); - function requireLibrary(lib) { const relPath = path.join(pathToLibraries, lib); const absPath = path.resolve(__filename, relPath); diff --git a/test/StyleSheet.js b/test/StyleSheet.js index fef8bc7..b507a82 100644 --- a/test/StyleSheet.js +++ b/test/StyleSheet.js @@ -1,23 +1,22 @@ -import { StyleSheet } from '../src/react-native'; -import { expect } from 'chai'; - +import {StyleSheet} from '../src/react-native'; +import {expect} from 'chai'; describe('StyleSheet', () => { let styles; - beforeEach(function () { + beforeEach(function() { styles = StyleSheet.create({ listItem: { flex: 1, fontSize: 16, - color: 'white' + color: 'white', }, selectedListItem: { - color: 'green' + color: 'green', }, headerItem: { - fontWeight: 'bold' - } + fontWeight: 'bold', + }, }); }); @@ -26,30 +25,34 @@ describe('StyleSheet', () => { const expectedResult = { flex: 1, fontSize: 16, - color: 'white' + color: 'white', }; expect(result).to.deep.equal(expectedResult); }); it('flatten with array', () => { - const result = StyleSheet.flatten([styles.listItem, styles.selectedListItem]); + const result = StyleSheet.flatten([ + styles.listItem, + styles.selectedListItem, + ]); const expectedResult = { flex: 1, fontSize: 16, - color: 'green' + color: 'green', }; expect(result).to.deep.equal(expectedResult); }); it('flatten with nested array', () => { - const result = StyleSheet.flatten( - [styles.listItem, [styles.headerItem, styles.selectedListItem]] - ); + const result = StyleSheet.flatten([ + styles.listItem, + [styles.headerItem, styles.selectedListItem], + ]); const expectedResult = { flex: 1, fontSize: 16, color: 'green', - fontWeight: 'bold' + fontWeight: 'bold', }; expect(result).to.deep.equal(expectedResult); }); diff --git a/test/api/Animated.js b/test/api/Animated.js index 33ba7db..0e743ca 100644 --- a/test/api/Animated.js +++ b/test/api/Animated.js @@ -1,7 +1,7 @@ import React from 'react'; import View from '../../src/components/View.js'; -import { expect } from 'chai'; -import { mount } from 'enzyme'; +import {expect} from 'chai'; +import {mount} from 'enzyme'; import Animated from '../../src/api/Animated'; describe('Animated.View', () => { @@ -11,12 +11,14 @@ describe('Animated.View', () => { wrapper = mount( - + , ); }); it('renders its children', () => { - expect(wrapper.findWhere((n) => n.props().testID === 'child-view')).to.have.length(1); + expect( + wrapper.findWhere(n => n.props().testID === 'child-view'), + ).to.have.length(1); }); it('implements setNativeProps', () => { diff --git a/test/api/CameraRoll.js b/test/api/CameraRoll.js index 3745510..b4056a7 100644 --- a/test/api/CameraRoll.js +++ b/test/api/CameraRoll.js @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import {expect} from 'chai'; import CameraRoll from '../../src/api/CameraRoll'; describe('CameraRoll', () => { @@ -12,10 +12,10 @@ describe('CameraRoll', () => { image: { uri: 'content://media/external/images/media/1', height: 2448, - width: 3968 + width: 3968, }, - timestamp: 1528972673375 - } + timestamp: 1528972673375, + }, }, { node: { @@ -24,10 +24,10 @@ describe('CameraRoll', () => { image: { uri: 'content://media/external/images/media/2', height: 2448, - width: 3968 + width: 3968, }, - timestamp: 1528972673375 - } + timestamp: 1528972673375, + }, }, { node: { @@ -36,18 +36,20 @@ describe('CameraRoll', () => { image: { uri: 'content://media/external/images/media/3', height: 2448, - width: 3968 + width: 3968, }, - timestamp: 1528972673375 - } - } + timestamp: 1528972673375, + }, + }, ], page_info: { has_next_page: true, - end_cursor: '1528919312601' - } + end_cursor: '1528919312601', + }, }; - CameraRoll.getPhotos().then(photos => expect(photos).to.deep.equal(expectedResult)); + CameraRoll.getPhotos().then(photos => + expect(photos).to.deep.equal(expectedResult), + ); }); }); diff --git a/test/api/Dimensions.js b/test/api/Dimensions.js index 06b672c..0e6c3ca 100644 --- a/test/api/Dimensions.js +++ b/test/api/Dimensions.js @@ -1,5 +1,5 @@ import Dimensions from '../../src/api/Dimensions'; -import chai, { expect } from 'chai'; +import chai, {expect} from 'chai'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; @@ -30,8 +30,8 @@ describe('Dimensions', () => { changeListener = sinon.spy(); Dimensions.addEventListener('change', changeListener); newDimensions = Object.freeze({ - window: { width: 10, height: 20, scale: 1, fontScale: 3 }, - screen: { width: 10, height: 18, scale: 1, fontScale: 3 } + window: {width: 10, height: 20, scale: 1, fontScale: 3}, + screen: {width: 10, height: 18, scale: 1, fontScale: 3}, }); Dimensions.set(newDimensions); }); @@ -56,8 +56,8 @@ describe('Dimensions', () => { }); it('Does not invoke event listeners on change any more', () => { const otherDimensions = Object.freeze({ - window: { width: 100, height: 30, scale: 3, fontScale: 1 }, - screen: { width: 100, height: 30, scale: 3, fontScale: 1 } + window: {width: 100, height: 30, scale: 3, fontScale: 1}, + screen: {width: 100, height: 30, scale: 3, fontScale: 1}, }); Dimensions.set(otherDimensions); expect(changeListener).not.to.have.been.calledWith(otherDimensions); diff --git a/test/api/NetInfo.js b/test/api/NetInfo.js index 0335754..8508b6a 100644 --- a/test/api/NetInfo.js +++ b/test/api/NetInfo.js @@ -1,12 +1,13 @@ -import { expect } from 'chai'; +import {expect} from 'chai'; import NetInfo from '../../src/api/NetInfo'; - describe('NetInfo', () => { it('getConnectionInfo', () => { - const expectedResult = { type: 'wifi', effectiveType: 'unknown' }; + const expectedResult = {type: 'wifi', effectiveType: 'unknown'}; - NetInfo.getConnectionInfo().then(info => expect(info).to.deep.equal(expectedResult)); + NetInfo.getConnectionInfo().then(info => + expect(info).to.deep.equal(expectedResult), + ); }); }); diff --git a/test/components/DrawerLayoutAndroid.js b/test/components/DrawerLayoutAndroid.js index 67ae4c9..7f38f62 100644 --- a/test/components/DrawerLayoutAndroid.js +++ b/test/components/DrawerLayoutAndroid.js @@ -1,12 +1,14 @@ /* eslint no-unused-expressions: 0 */ import React from 'react'; -import { DrawerLayoutAndroid } from '../../src/react-native'; -import { expect } from 'chai'; -import { mount } from 'enzyme'; +import {DrawerLayoutAndroid} from '../../src/react-native'; +import {expect} from 'chai'; +import {mount} from 'enzyme'; describe('DrawerLayoutAndroid', () => { it('should render an empty DrawerLayoutAndroid', () => { - const wrapper = mount( {}} />); + const wrapper = mount( + {}} />, + ); expect(wrapper.children()).to.be.have.length(1); }); diff --git a/test/components/Picker.js b/test/components/Picker.js index 21484d4..66d9371 100644 --- a/test/components/Picker.js +++ b/test/components/Picker.js @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import {expect} from 'chai'; import Picker from '../../src/components/Picker.js'; describe('Picker', () => { diff --git a/test/components/TabBarIOS.js b/test/components/TabBarIOS.js index 73498ad..8ed82a0 100644 --- a/test/components/TabBarIOS.js +++ b/test/components/TabBarIOS.js @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import {expect} from 'chai'; import TabBarIOS from '../../src/components/TabBarIOS.js'; describe('TabBarIOS', () => { diff --git a/test/components/View.js b/test/components/View.js index 1c7195b..2ffa0a1 100644 --- a/test/components/View.js +++ b/test/components/View.js @@ -1,7 +1,7 @@ import React from 'react'; import View from '../../src/components/View.js'; -import { expect } from 'chai'; -import { mount } from 'enzyme'; +import {expect} from 'chai'; +import {mount} from 'enzyme'; describe('View', () => { let wrapper; @@ -10,12 +10,14 @@ describe('View', () => { wrapper = mount( - + , ); }); it('renders its children', () => { - expect(wrapper.findWhere((n) => n.props().testID === 'child-view')).to.have.length(1); + expect( + wrapper.findWhere(n => n.props().testID === 'child-view'), + ).to.have.length(1); }); it('implements setNativeProps', () => { diff --git a/test/mixins/Subscribable.js b/test/mixins/Subscribable.js index dd3f19d..862f99b 100644 --- a/test/mixins/Subscribable.js +++ b/test/mixins/Subscribable.js @@ -1,5 +1,5 @@ import React from 'react'; /* eslint no-unused-vars:0 */ -import { expect } from 'chai'; +import {expect} from 'chai'; import Subscribable from '../../src/mixins/Subscribable.js'; import DeviceEventEmitter from '../../src/plugins/DeviceEventEmitter.js'; import createReactClass from 'create-react-class'; @@ -19,7 +19,11 @@ describe('Subscribable.Mixin', () => { expect(DeviceEventEmitter.listeners(existingEventType)).to.have.length(1); subscribableComponent.componentWillMount(); - subscribableComponent.addListenerOn(DeviceEventEmitter, 'Test Event Type', () => {}); + subscribableComponent.addListenerOn( + DeviceEventEmitter, + 'Test Event Type', + () => {}, + ); subscribableComponent.componentWillUnmount(); expect(DeviceEventEmitter.listeners(existingEventType)).to.have.length(1); diff --git a/test/react-native-test.js b/test/react-native-test.js index 7a321a1..e14e720 100644 --- a/test/react-native-test.js +++ b/test/react-native-test.js @@ -1,5 +1,5 @@ -import { expect } from 'chai'; -import { get } from 'lodash'; +import {expect} from 'chai'; +import {get} from 'lodash'; describe('react-native.js', () => { it('returns renderable types when expected', () => { @@ -65,7 +65,7 @@ describe('react-native.js', () => { 'WebView', ]; - renderableComponents.forEach((component) => { + renderableComponents.forEach(component => { expect(get(MockReactNative, component)).to.be.a('function'); }); }); diff --git a/test/setup-tests.js b/test/setup-tests.js index cad8de0..be5af84 100644 --- a/test/setup-tests.js +++ b/test/setup-tests.js @@ -1,12 +1,12 @@ -const { JSDOM } = require('jsdom'); +const {JSDOM} = require('jsdom'); const jsdom = new JSDOM(''); -const { window } = jsdom; +const {window} = jsdom; function copyProps(src, target) { const props = Object.getOwnPropertyNames(src) - .filter((prop) => typeof target[prop] === 'undefined') - .map((prop) => Object.getOwnPropertyDescriptor(src, prop)); + .filter(prop => typeof target[prop] === 'undefined') + .map(prop => Object.getOwnPropertyDescriptor(src, prop)); Object.defineProperties(target, props); } @@ -20,4 +20,4 @@ copyProps(window, global); const Enzyme = require('enzyme'); const Adapter = require('enzyme-adapter-react-16'); -Enzyme.configure({ adapter: new Adapter() }); +Enzyme.configure({adapter: new Adapter()}); diff --git a/yarn.lock b/yarn.lock index e6269e0..882cb58 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2074,6 +2074,12 @@ eslint-config-airbnb@9.0.1: dependencies: eslint-config-airbnb-base "^3.0.0" +eslint-config-prettier@2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-2.9.0.tgz#5ecd65174d486c22dff389fe036febf502d468a3" + dependencies: + get-stdin "^5.0.1" + eslint-import-resolver-node@^0.2.0: version "0.2.3" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.2.3.tgz#5add8106e8c928db2cba232bcd9efa846e3da16c" @@ -2559,6 +2565,10 @@ get-stdin@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" +get-stdin@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" + getpass@^0.1.1: version "0.1.6" resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.6.tgz#283ffd9fc1256840875311c1b60e8c40187110e6" @@ -4161,6 +4171,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier@1.14.2: + version "1.14.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.2.tgz#0ac1c6e1a90baa22a62925f41963c841983282f9" + pretty-format@^4.2.1: version "4.3.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-4.3.1.tgz#530be5c42b3c05b36414a7a2a4337aa80acd0e8d"