From 892dd5b86ab6e90337ccfb3f78e5ac5a4ef17839 Mon Sep 17 00:00:00 2001 From: Gabe Levi Date: Tue, 1 Dec 2015 19:09:01 -0800 Subject: [PATCH] Fix errors uncovered by v0.19.0 Reviewed By: mroch Differential Revision: D2706663 fb-gh-sync-id: 017c91bab849bf18767cacd2ebe32d1a1b10c715 --- Examples/UIExplorer/GeolocationExample.js | 12 ++- Examples/UIExplorer/ImageExample.js | 1 + Examples/UIExplorer/LayoutEventsExample.js | 25 ++++-- Examples/UIExplorer/MapViewExample.js | 87 ++++++++++++++++--- Examples/UIExplorer/PanResponderExample.js | 8 +- Examples/UIExplorer/PickerIOSExample.js | 2 +- Examples/UIExplorer/UIExplorerListBase.js | 2 +- Examples/UIExplorer/XHRExampleHeaders.js | 3 +- IntegrationTests/AppEventsTest.js | 9 +- IntegrationTests/IntegrationTestsApp.js | 4 +- IntegrationTests/LayoutEventsTest.js | 33 +++++-- .../Components/Navigation/NavigatorIOS.ios.js | 4 +- .../Components/TabBarIOS/TabBarItemIOS.ios.js | 1 + Libraries/Components/TextInput/TextInput.js | 8 +- .../ToastAndroid/ToastAndroid.ios.js | 1 + .../Components/Touchable/TouchableBounce.js | 1 + .../Touchable/TouchableHighlight.js | 1 + .../Components/Touchable/TouchableOpacity.js | 1 + .../Navigator/Navigation/NavigationContext.js | 1 + Libraries/ReactIOS/renderApplication.ios.js | 1 + Libraries/Storage/AsyncStorage.js | 1 + Libraries/Utilities/MatrixMath.js | 1 + .../vendor/emitter/EmitterSubscription.js | 1 + Libraries/vendor/emitter/EventEmitter.js | 1 + 24 files changed, 168 insertions(+), 41 deletions(-) diff --git a/Examples/UIExplorer/GeolocationExample.js b/Examples/UIExplorer/GeolocationExample.js index d9dd4e842b74a1..61d7d3778bda63 100644 --- a/Examples/UIExplorer/GeolocationExample.js +++ b/Examples/UIExplorer/GeolocationExample.js @@ -49,11 +49,15 @@ var GeolocationExample = React.createClass({ componentDidMount: function() { navigator.geolocation.getCurrentPosition( - (initialPosition) => this.setState({initialPosition}), + (position) => { + var initialPosition = JSON.stringify(position); + this.setState({initialPosition}); + }, (error) => alert(error.message), {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000} ); - this.watchID = navigator.geolocation.watchPosition((lastPosition) => { + this.watchID = navigator.geolocation.watchPosition((position) => { + var lastPosition = JSON.stringify(position); this.setState({lastPosition}); }); }, @@ -67,11 +71,11 @@ var GeolocationExample = React.createClass({ Initial position: - {JSON.stringify(this.state.initialPosition)} + {this.state.initialPosition} Current position: - {JSON.stringify(this.state.lastPosition)} + {this.state.lastPosition} ); diff --git a/Examples/UIExplorer/ImageExample.js b/Examples/UIExplorer/ImageExample.js index 68b16b2d103ef4..50c96ffd285e40 100644 --- a/Examples/UIExplorer/ImageExample.js +++ b/Examples/UIExplorer/ImageExample.js @@ -32,6 +32,7 @@ var NetworkImageCallbackExample = React.createClass({ getInitialState: function() { return { events: [], + mountTime: new Date(), }; }, diff --git a/Examples/UIExplorer/LayoutEventsExample.js b/Examples/UIExplorer/LayoutEventsExample.js index bcbb5cbb7f937f..a6b0cea89c0f93 100644 --- a/Examples/UIExplorer/LayoutEventsExample.js +++ b/Examples/UIExplorer/LayoutEventsExample.js @@ -24,19 +24,30 @@ var { View, } = React; +type Layout = { + x: number; + y: number; + width: number; + height: number; +}; + type LayoutEvent = { nativeEvent: { - layout: { - x: number; - y: number; - width: number; - height: number; - }; + layout: Layout, }; }; +type State = { + containerStyle?: { width: number }, + extraText?: string, + imageLayout?: Layout, + textLayout?: Layout, + viewLayout?: Layout, + viewStyle: { margin: number }, +}; + var LayoutEventExample = React.createClass({ - getInitialState: function() { + getInitialState(): State { return { viewStyle: { margin: 20, diff --git a/Examples/UIExplorer/MapViewExample.js b/Examples/UIExplorer/MapViewExample.js index 863187edab61cf..44142a4af160fe 100644 --- a/Examples/UIExplorer/MapViewExample.js +++ b/Examples/UIExplorer/MapViewExample.js @@ -31,6 +31,17 @@ var regionText = { longitudeDelta: '0', }; +type MapRegion = { + latitude: number, + longitude: number, + latitudeDelta: number, + longitudeDelta: number, +}; + +type MapRegionInputState = { + region: MapRegion, +}; + var MapRegionInput = React.createClass({ propTypes: { @@ -43,7 +54,7 @@ var MapRegionInput = React.createClass({ onChange: React.PropTypes.func.isRequired, }, - getInitialState: function() { + getInitialState(): MapRegionInputState { return { region: { latitude: 0, @@ -135,19 +146,42 @@ var MapRegionInput = React.createClass({ _change: function() { this.setState({ - latitude: parseFloat(regionText.latitude), - longitude: parseFloat(regionText.longitude), - latitudeDelta: parseFloat(regionText.latitudeDelta), - longitudeDelta: parseFloat(regionText.longitudeDelta), + region: { + latitude: parseFloat(regionText.latitude), + longitude: parseFloat(regionText.longitude), + latitudeDelta: parseFloat(regionText.latitudeDelta), + longitudeDelta: parseFloat(regionText.longitudeDelta), + }, }); this.props.onChange(this.state.region); }, }); +type Annotations = Array<{ + animateDrop?: boolean, + latitude: number, + longitude: number, + title?: string, + subtitle?: string, + hasLeftCallout?: boolean, + hasRightCallout?: boolean, + onLeftCalloutPress?: Function, + onRightCalloutPress?: Function, + tintColor?: string, + image?: any, + id?: string, +}>; +type MapViewExampleState = { + isFirstLoad: boolean, + mapRegion?: MapRegion, + mapRegionInput?: MapRegion, + annotations?: Annotations, +}; + var MapViewExample = React.createClass({ - getInitialState() { + getInitialState(): MapViewExampleState { return { isFirstLoad: true, }; @@ -171,7 +205,7 @@ var MapViewExample = React.createClass({ ); }, - _getAnnotations(region) { + _getAnnotations(region): Annotations { return [{ longitude: region.longitude, latitude: region.latitude, @@ -205,9 +239,14 @@ var MapViewExample = React.createClass({ }); +type CalloutMapViewExampleState = { + isFirstLoad: boolean, + annotations?: Annotations, + mapRegion?: MapRegion, +}; var CalloutMapViewExample = React.createClass({ - getInitialState() { + getInitialState(): CalloutMapViewExampleState { return { isFirstLoad: true, }; @@ -243,9 +282,14 @@ var CalloutMapViewExample = React.createClass({ }); +type CustomPinColorMapViewExampleState = { + isFirstLoad: boolean, + annotations?: Annotations, + mapRegion?: MapRegion, +}; var CustomPinColorMapViewExample = React.createClass({ - getInitialState() { + getInitialState(): CustomPinColorMapViewExampleState { return { isFirstLoad: true, }; @@ -278,9 +322,14 @@ var CustomPinColorMapViewExample = React.createClass({ }); +type CustomPinImageMapViewExampleState = { + isFirstLoad: boolean, + annotations?: Annotations, + mapRegion?: MapRegion, +}; var CustomPinImageMapViewExample = React.createClass({ - getInitialState() { + getInitialState(): CustomPinImageMapViewExampleState { return { isFirstLoad: true, }; @@ -313,9 +362,25 @@ var CustomPinImageMapViewExample = React.createClass({ }); +type Overlays = Array<{ + coordinates?: Array<{ + latitude: number, + longitude: number, + }>, + lineWidth?: number, + strokeColor?: string, + fillColor?: string, + id?: string, +}>; +type CustomOverlayMapViewExampleState = { + isFirstLoad: boolean, + overlays?: Overlays, + annotations?: Annotations, + mapRegion?: MapRegion, +}; var CustomOverlayMapViewExample = React.createClass({ - getInitialState() { + getInitialState(): CustomOverlayMapViewExampleState { return { isFirstLoad: true, }; diff --git a/Examples/UIExplorer/PanResponderExample.js b/Examples/UIExplorer/PanResponderExample.js index c2e6a667ce0da8..47833af3f5a8fe 100644 --- a/Examples/UIExplorer/PanResponderExample.js +++ b/Examples/UIExplorer/PanResponderExample.js @@ -11,7 +11,7 @@ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - * @flow-weak + * @flow weak */ 'use strict'; @@ -79,7 +79,8 @@ var PanResponderExample = React.createClass({ }, _highlight: function() { - this.circle && this.circle.setNativeProps({ + const circle = this.circle; + circle && circle.setNativeProps({ style: { backgroundColor: processColor(CIRCLE_HIGHLIGHT_COLOR) } @@ -87,7 +88,8 @@ var PanResponderExample = React.createClass({ }, _unHighlight: function() { - this.circle && this.circle.setNativeProps({ + const circle = this.circle; + circle && circle.setNativeProps({ style: { backgroundColor: processColor(CIRCLE_COLOR) } diff --git a/Examples/UIExplorer/PickerIOSExample.js b/Examples/UIExplorer/PickerIOSExample.js index 31c81ccccdad5c..b0cc5cb9729d68 100644 --- a/Examples/UIExplorer/PickerIOSExample.js +++ b/Examples/UIExplorer/PickerIOSExample.js @@ -99,7 +99,7 @@ var PickerExample = React.createClass({ {CAR_MAKES_AND_MODELS[this.state.carMake].models.map( (modelName, modelIndex) => ( diff --git a/Examples/UIExplorer/UIExplorerListBase.js b/Examples/UIExplorer/UIExplorerListBase.js index 4b26a6976dc6c6..c4b55f6d0ab37d 100644 --- a/Examples/UIExplorer/UIExplorerListBase.js +++ b/Examples/UIExplorer/UIExplorerListBase.js @@ -116,7 +116,7 @@ class UIExplorerListBase extends React.Component { search(text: mixed): void { this.props.search && this.props.search(text); - var regex = new RegExp(text, 'i'); + var regex = new RegExp(String(text), 'i'); var filter = (component) => regex.test(component.title); this.setState({ diff --git a/Examples/UIExplorer/XHRExampleHeaders.js b/Examples/UIExplorer/XHRExampleHeaders.js index e9f5e2c4c974fa..e83c1b071d951f 100644 --- a/Examples/UIExplorer/XHRExampleHeaders.js +++ b/Examples/UIExplorer/XHRExampleHeaders.js @@ -11,6 +11,7 @@ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * @noflow */ 'use strict'; @@ -113,4 +114,4 @@ var styles = StyleSheet.create({ }, }); -module.exports = XHRExampleHeaders; \ No newline at end of file +module.exports = XHRExampleHeaders; diff --git a/IntegrationTests/AppEventsTest.js b/IntegrationTests/AppEventsTest.js index 7362072ffd4829..c003b014d1eab8 100644 --- a/IntegrationTests/AppEventsTest.js +++ b/IntegrationTests/AppEventsTest.js @@ -24,8 +24,15 @@ var deepDiffer = require('deepDiffer'); var TEST_PAYLOAD = {foo: 'bar'}; +type AppEvent = { data: Object, ts: number, }; +type State = { + sent: 'none' | AppEvent, + received: 'none' | AppEvent, + elapsed?: string, +}; + var AppEventsTest = React.createClass({ - getInitialState: function() { + getInitialState(): State { return {sent: 'none', received: 'none'}; }, componentDidMount: function() { diff --git a/IntegrationTests/IntegrationTestsApp.js b/IntegrationTests/IntegrationTestsApp.js index ce136f7fd6fafc..54fca9a4bd4908 100644 --- a/IntegrationTests/IntegrationTestsApp.js +++ b/IntegrationTests/IntegrationTestsApp.js @@ -39,10 +39,12 @@ TESTS.forEach( // Modules required for integration tests require('LoggingTestModule'); +type Test = any; + var IntegrationTestsApp = React.createClass({ getInitialState: function() { return { - test: null, + test: (null: ?Test), }; }, render: function() { diff --git a/IntegrationTests/LayoutEventsTest.js b/IntegrationTests/LayoutEventsTest.js index 9f7eb7d54b3560..2cfe13f9b9dd78 100644 --- a/IntegrationTests/LayoutEventsTest.js +++ b/IntegrationTests/LayoutEventsTest.js @@ -27,19 +27,38 @@ function debug() { // console.log.apply(null, arguments); } +type Layout = { + x: number; + y: number; + width: number; + height: number; +}; type LayoutEvent = { nativeEvent: { - layout: { - x: number; - y: number; - width: number; - height: number; - }; + layout: Layout; }; }; +type Style = { + margin?: number, + padding?: number, + borderColor?: string, + borderWidth?: number, + backgroundColor?: string, + width?: number, +}; + +type State = { + didAnimation: boolean, + extraText?: string, + imageLayout?: Layout, + textLayout?: Layout, + viewLayout?: Layout, + viewStyle?: Style, + containerStyle?: Style, +}; var LayoutEventsTest = React.createClass({ - getInitialState: function() { + getInitialState(): State { return { didAnimation: false, }; diff --git a/Libraries/Components/Navigation/NavigatorIOS.ios.js b/Libraries/Components/Navigation/NavigatorIOS.ios.js index a0f2199b295d59..6d86930b7a6fdf 100644 --- a/Libraries/Components/Navigation/NavigatorIOS.ios.js +++ b/Libraries/Components/Navigation/NavigatorIOS.ios.js @@ -74,7 +74,7 @@ type State = { fromIndex: number; toIndex: number; makingNavigatorRequest: boolean; - updatingAllIndicesAtOrBeyond: number; + updatingAllIndicesAtOrBeyond: ?number; } type Event = Object; @@ -592,7 +592,7 @@ var NavigatorIOS = React.createClass({ _routeToStackItem: function(route: Route, i: number) { var Component = route.component; - var shouldUpdateChild = this.state.updatingAllIndicesAtOrBeyond !== null && + var shouldUpdateChild = this.state.updatingAllIndicesAtOrBeyond != null && this.state.updatingAllIndicesAtOrBeyond >= i; return ( diff --git a/Libraries/Components/TabBarIOS/TabBarItemIOS.ios.js b/Libraries/Components/TabBarIOS/TabBarItemIOS.ios.js index a4c883bc900e16..f220249c76c7ca 100644 --- a/Libraries/Components/TabBarIOS/TabBarItemIOS.ios.js +++ b/Libraries/Components/TabBarIOS/TabBarItemIOS.ios.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule TabBarItemIOS + * @noflow */ 'use strict'; diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index e7416e833bf001..e7049d2e07d9ba 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -335,8 +335,12 @@ var TextInput = React.createClass({ */ mixins: [NativeMethodsMixin, TimerMixin], - viewConfig: ((Platform.OS === 'ios' ? RCTTextField.viewConfig : - (Platform.OS === 'android' ? AndroidTextInput.viewConfig : {})) : Object), + viewConfig: + ((Platform.OS === 'ios' && RCTTextField ? + RCTTextField.viewConfig : + (Platform.OS === 'android' && AndroidTextInput ? + AndroidTextInput.viewConfig : + {})) : Object), isFocused: function(): boolean { return TextInputState.currentlyFocusedField() === diff --git a/Libraries/Components/ToastAndroid/ToastAndroid.ios.js b/Libraries/Components/ToastAndroid/ToastAndroid.ios.js index bf42aae640e81a..087786e0893784 100644 --- a/Libraries/Components/ToastAndroid/ToastAndroid.ios.js +++ b/Libraries/Components/ToastAndroid/ToastAndroid.ios.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ToastAndroid + * @noflow */ 'use strict'; diff --git a/Libraries/Components/Touchable/TouchableBounce.js b/Libraries/Components/Touchable/TouchableBounce.js index 0b7d91152c764a..d3c1696769e8cc 100644 --- a/Libraries/Components/Touchable/TouchableBounce.js +++ b/Libraries/Components/Touchable/TouchableBounce.js @@ -21,6 +21,7 @@ type Event = Object; type State = { animationID: ?number; + scale: Animated.Value; }; var PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; diff --git a/Libraries/Components/Touchable/TouchableHighlight.js b/Libraries/Components/Touchable/TouchableHighlight.js index b7dc706eb6a071..67c1e55a0b8588 100644 --- a/Libraries/Components/Touchable/TouchableHighlight.js +++ b/Libraries/Components/Touchable/TouchableHighlight.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule TouchableHighlight + * @noflow */ 'use strict'; diff --git a/Libraries/Components/Touchable/TouchableOpacity.js b/Libraries/Components/Touchable/TouchableOpacity.js index 5d7d8f3fbb2802..627dd1205bd6e0 100644 --- a/Libraries/Components/Touchable/TouchableOpacity.js +++ b/Libraries/Components/Touchable/TouchableOpacity.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule TouchableOpacity + * @noflow */ 'use strict'; diff --git a/Libraries/CustomComponents/Navigator/Navigation/NavigationContext.js b/Libraries/CustomComponents/Navigator/Navigation/NavigationContext.js index 5a0c35f37e0782..6d17fe1256dfe2 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/NavigationContext.js +++ b/Libraries/CustomComponents/Navigator/Navigation/NavigationContext.js @@ -23,6 +23,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @providesModule NavigationContext + * @noflow */ 'use strict'; diff --git a/Libraries/ReactIOS/renderApplication.ios.js b/Libraries/ReactIOS/renderApplication.ios.js index 0b0f306d6be33a..ad000f64305183 100644 --- a/Libraries/ReactIOS/renderApplication.ios.js +++ b/Libraries/ReactIOS/renderApplication.ios.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule renderApplication + * @noflow */ 'use strict'; diff --git a/Libraries/Storage/AsyncStorage.js b/Libraries/Storage/AsyncStorage.js index c5be992e2abaf0..9135088f616381 100644 --- a/Libraries/Storage/AsyncStorage.js +++ b/Libraries/Storage/AsyncStorage.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule AsyncStorage + * @noflow * @flow-weak */ 'use strict'; diff --git a/Libraries/Utilities/MatrixMath.js b/Libraries/Utilities/MatrixMath.js index 23db73811f1896..e248ba75dc8756 100755 --- a/Libraries/Utilities/MatrixMath.js +++ b/Libraries/Utilities/MatrixMath.js @@ -2,6 +2,7 @@ * Copyright 2004-present Facebook. All Rights Reserved. * * @providesModule MatrixMath + * @noflow */ /* eslint-disable space-infix-ops */ 'use strict'; diff --git a/Libraries/vendor/emitter/EmitterSubscription.js b/Libraries/vendor/emitter/EmitterSubscription.js index a4d52a802ee58b..bbd1d414c431cc 100644 --- a/Libraries/vendor/emitter/EmitterSubscription.js +++ b/Libraries/vendor/emitter/EmitterSubscription.js @@ -13,6 +13,7 @@ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * * @providesModule EmitterSubscription + * @noflow * @typechecks */ 'use strict'; diff --git a/Libraries/vendor/emitter/EventEmitter.js b/Libraries/vendor/emitter/EventEmitter.js index cb3725ebb98920..b5c14a66a7c7a9 100644 --- a/Libraries/vendor/emitter/EventEmitter.js +++ b/Libraries/vendor/emitter/EventEmitter.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule EventEmitter + * @noflow * @typechecks */