From 91d4a093ea6abbe00561d3024198c8b05b134db0 Mon Sep 17 00:00:00 2001 From: "glevi@fb.com" Date: Thu, 21 Apr 2016 19:46:36 -0700 Subject: [PATCH] Fix or suppress errors in react-native Reviewed By: jeffmo Differential Revision: D3209973 fb-gh-sync-id: bdc9b4afc0b187b1b16fa6bfb1c34adb4089ab81 fbshipit-source-id: bdc9b4afc0b187b1b16fa6bfb1c34adb4089ab81 --- .flowconfig | 2 -- Libraries/Components/MapView/MapView.js | 1 + .../NavigationCardStack.js | 12 +++++-- .../NavigationHeader.js | 10 +++--- Libraries/Experimental/Incremental.js | 30 +++++++++------- .../Experimental/IncrementalPresenter.js | 34 ++++++++++--------- Libraries/Experimental/WindowedListView.js | 27 ++++++++------- Libraries/Modal/Modal.js | 24 ++++++------- .../NavigationContainer.js | 2 +- .../NavigationRootContainer.js | 11 +++--- .../NavigationTypeDefinition.js | 1 - Libraries/ReactIOS/YellowBox.js | 1 + Libraries/react-native/react-native.js.flow | 1 - 13 files changed, 86 insertions(+), 70 deletions(-) diff --git a/.flowconfig b/.flowconfig index 08d02717adc..a9f7b422196 100644 --- a/.flowconfig +++ b/.flowconfig @@ -15,8 +15,6 @@ # Ignore react and fbjs where there are overlaps, but don't ignore # anything that react-native relies on .*/node_modules/fbjs/lib/Map.js -.*/node_modules/fbjs/lib/fetch.js -.*/node_modules/fbjs/lib/ExecutionEnvironment.js .*/node_modules/fbjs/lib/ErrorUtils.js # Flow has a built-in definition for the 'react' module which we prefer to use diff --git a/Libraries/Components/MapView/MapView.js b/Libraries/Components/MapView/MapView.js index e78a6d048f3..60c7515272f 100644 --- a/Libraries/Components/MapView/MapView.js +++ b/Libraries/Components/MapView/MapView.js @@ -351,6 +351,7 @@ const MapView = React.createClass({ } var viewIndex = children.length; children.push(React.cloneElement(view, { + // $FlowFixMe - An array of styles should be fine style: [styles.annotationView, view.props.style || {}] })); } diff --git a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js index 72978cebcd1..e7256899d3d 100644 --- a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js +++ b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js @@ -64,6 +64,11 @@ type Props = { renderScene: NavigationSceneRenderer, }; +type DefaultProps = { + direction: NavigationGestureDirection, + renderOverlay: ?NavigationSceneRenderer, +}; + /** * A controlled navigation view that renders a stack of cards. * @@ -78,7 +83,7 @@ type Props = { * +-+ | * +------------+ */ -class NavigationCardStack extends React.Component { +class NavigationCardStack extends React.Component { _renderScene : NavigationSceneRenderer; static propTypes = { @@ -88,7 +93,7 @@ class NavigationCardStack extends React.Component { renderScene: PropTypes.func.isRequired, }; - static defaultProps = { + static defaultProps: DefaultProps = { direction: Directions.HORIZONTAL, renderOverlay: emptyFunction.thatReturnsNull, }; @@ -101,7 +106,7 @@ class NavigationCardStack extends React.Component { this._renderScene = this._renderScene.bind(this); } - shouldComponentUpdate(nextProps: Object, nextState: Object): boolean { + shouldComponentUpdate(nextProps: Object, nextState: void): boolean { return ReactComponentWithPureRenderMixin.shouldComponentUpdate.call( this, nextProps, @@ -115,6 +120,7 @@ class NavigationCardStack extends React.Component { navigationState={this.props.navigationState} renderOverlay={this.props.renderOverlay} renderScene={this._renderScene} + // $FlowFixMe - style should be declared style={[styles.animatedView, this.props.style]} /> ); diff --git a/Libraries/CustomComponents/NavigationExperimental/NavigationHeader.js b/Libraries/CustomComponents/NavigationExperimental/NavigationHeader.js index a0b1e78a1ab..b1e58136ca3 100644 --- a/Libraries/CustomComponents/NavigationExperimental/NavigationHeader.js +++ b/Libraries/CustomComponents/NavigationExperimental/NavigationHeader.js @@ -244,10 +244,10 @@ const styles = StyleSheet.create({ }, }); -NavigationHeader = NavigationContainer.create(NavigationHeader); +const NavigationHeaderContainer = NavigationContainer.create(NavigationHeader); -NavigationHeader.HEIGHT = APPBAR_HEIGHT + STATUSBAR_HEIGHT; -NavigationHeader.Title = NavigationHeaderTitle; -NavigationHeader.BackButton = NavigationHeaderBackButton; +NavigationHeaderContainer.HEIGHT = APPBAR_HEIGHT + STATUSBAR_HEIGHT; +NavigationHeaderContainer.Title = NavigationHeaderTitle; +NavigationHeaderContainer.BackButton = NavigationHeaderBackButton; -module.exports = NavigationHeader; +module.exports = NavigationHeaderContainer; diff --git a/Libraries/Experimental/Incremental.js b/Libraries/Experimental/Incremental.js index ea47b323f0a..8345130b99c 100644 --- a/Libraries/Experimental/Incremental.js +++ b/Libraries/Experimental/Incremental.js @@ -87,18 +87,31 @@ export type Props = { * Tags instances and associated tasks for easier debugging. */ name: string; - children: any; + children?: any; }; -class Incremental extends React.Component { +type DefaultProps = { + name: string, +}; +type State = { + doIncrementalRender: boolean, +}; +class Incremental extends React.Component { props: Props; - state: { - doIncrementalRender: boolean; - }; + state: State; context: Context; _incrementId: number; _mounted: boolean; _rendered: boolean; + static defaultProps = { + name: '', + }; + + static contextTypes = { + incrementalGroup: React.PropTypes.object, + incrementalGroupEnabled: React.PropTypes.bool, + }; + constructor(props: Props, context: Context) { super(props, context); this._mounted = false; @@ -159,13 +172,6 @@ class Incremental extends React.Component { this._mounted = false; } } -Incremental.defaultProps = { - name: '', -}; -Incremental.contextTypes = { - incrementalGroup: React.PropTypes.object, - incrementalGroupEnabled: React.PropTypes.bool, -}; export type Context = { incrementalGroupEnabled: boolean; diff --git a/Libraries/Experimental/IncrementalPresenter.js b/Libraries/Experimental/IncrementalPresenter.js index 053b4f9a141..d9ff0ef5207 100644 --- a/Libraries/Experimental/IncrementalPresenter.js +++ b/Libraries/Experimental/IncrementalPresenter.js @@ -31,16 +31,29 @@ import type {Context} from 'Incremental'; */ type Props = { name: string; - disabled: boolean; - onDone: () => void; - onLayout: (event: Object) => void; - style: mixed; - children: any; + disabled?: boolean; + onDone?: () => void; + onLayout?: (event: Object) => void; + style?: mixed; + children?: any; } class IncrementalPresenter extends React.Component { props: Props; context: Context; _isDone: boolean; + + static propTypes = { + name: React.PropTypes.string, + disabled: React.PropTypes.bool, + onDone: React.PropTypes.func, + onLayout: React.PropTypes.func, + style: View.propTypes.style, + }; + static contextTypes = { + incrementalGroup: React.PropTypes.object, + incrementalGroupEnabled: React.PropTypes.bool, + }; + constructor(props: Props, context: Context) { super(props, context); this._isDone = false; @@ -80,16 +93,5 @@ class IncrementalPresenter extends React.Component { ); } } -IncrementalPresenter.propTypes = { - name: React.PropTypes.string, - disabled: React.PropTypes.bool, - onDone: React.PropTypes.func, - onLayout: React.PropTypes.func, - style: View.propTypes.style, -}; -IncrementalPresenter.contextTypes = { - incrementalGroup: React.PropTypes.object, - incrementalGroupEnabled: React.PropTypes.bool, -}; module.exports = IncrementalPresenter; diff --git a/Libraries/Experimental/WindowedListView.js b/Libraries/Experimental/WindowedListView.js index c76ec4430f2..23d87b69389 100644 --- a/Libraries/Experimental/WindowedListView.js +++ b/Libraries/Experimental/WindowedListView.js @@ -89,7 +89,7 @@ type Props = { * return a row. */ renderRow: ( - data: mixed, sectionIdx: number, rowIdx: number, key: string + data: mixed, sectionIdx: number, rowIdx: number, key?: string ) => ?ReactElement; /** * Rendered when the list is scrolled faster than rows can be rendered. @@ -160,16 +160,6 @@ type Props = { */ onMountedRowsWillChange: (firstIdx: number, count: number) => void; }; -const defaultProps = { - enableDangerousRecycling: false, - initialNumToRender: 10, - maxNumToRender: 30, - numToRenderAhead: 10, - viewablePercentThreshold: 50, - renderScrollComponent: (props) => , - disableIncrementalRendering: false, - recomputeRowsBatchingPeriod: 100, -}; class WindowedListView extends React.Component { props: Props; state: { @@ -189,6 +179,18 @@ class WindowedListView extends React.Component { _viewableRows: Array = []; _cellsInProgress: Set = new Set(); _scrollRef: ?Object; + + static defaultProps = { + enableDangerousRecycling: false, + initialNumToRender: 10, + maxNumToRender: 30, + numToRenderAhead: 10, + viewablePercentThreshold: 50, + renderScrollComponent: (props) => , + disableIncrementalRendering: false, + recomputeRowsBatchingPeriod: 100, + }; + constructor(props: Props) { super(props); invariant( @@ -495,7 +497,6 @@ class WindowedListView extends React.Component { ); } } -WindowedListView.defaultProps = defaultProps; // performance testing id, unique for each component mount cycle let g_perf_update_id = 0; @@ -530,7 +531,7 @@ type CellProps = { * Updates the parent with the latest layout. Only called when incremental rendering is done and triggers the parent * to re-render this row with includeInLayout true. */ - onNewLayout: (params: {rowIndex: number, layout: ?Object}) => void; + onNewLayout: (params: {rowIndex: number, layout: Object}) => void; /** * Used to track when rendering is in progress so the parent can avoid wastedful re-renders that are just going to be * invalidated once the cell finishes. diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index d6b2fc2beb0..1451caf861a 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -34,6 +34,18 @@ const RCTModalHostView = requireNativeComponent('RCTModalHostView', null); * configureScene property. */ class Modal extends React.Component { + static propTypes = { + animated: PropTypes.bool, + transparent: PropTypes.bool, + visible: PropTypes.bool, + onRequestClose: Platform.OS === 'android' ? PropTypes.func.isRequired : PropTypes.func, + onShow: PropTypes.func, + }; + + static defaultProps = { + visible: true, + }; + render(): ?ReactElement { if (this.props.visible === false) { return null; @@ -65,18 +77,6 @@ class Modal extends React.Component { } } -Modal.propTypes = { - animated: PropTypes.bool, - transparent: PropTypes.bool, - visible: PropTypes.bool, - onRequestClose: Platform.OS === 'android' ? PropTypes.func.isRequired : PropTypes.func, - onShow: PropTypes.func, -}; - -Modal.defaultProps = { - visible: true, -}; - const styles = StyleSheet.create({ modal: { position: 'absolute', diff --git a/Libraries/NavigationExperimental/NavigationContainer.js b/Libraries/NavigationExperimental/NavigationContainer.js index 9ebc8a925e3..bd17a636f1d 100644 --- a/Libraries/NavigationExperimental/NavigationContainer.js +++ b/Libraries/NavigationExperimental/NavigationContainer.js @@ -16,7 +16,7 @@ var NavigationRootContainer = require('NavigationRootContainer'); function createNavigationContainer( Component: ReactClass, -): ReactClass { +): ReactClass & Object { class NavigationComponent extends React.Component { render() { return ( diff --git a/Libraries/NavigationExperimental/NavigationRootContainer.js b/Libraries/NavigationExperimental/NavigationRootContainer.js index e15a7b9ea12..985a1fb32a8 100644 --- a/Libraries/NavigationExperimental/NavigationRootContainer.js +++ b/Libraries/NavigationExperimental/NavigationRootContainer.js @@ -95,6 +95,9 @@ class NavigationRootContainer extends React.Component { onNavigate: PropTypes.func, }; + + static getBackAction = getBackAction; + constructor(props: Props) { super(props); @@ -108,8 +111,8 @@ class NavigationRootContainer extends React.Component { } componentWillMount(): void { - this.handleNavigation = this.handleNavigation.bind(this); - this._handleOpenURLEvent = this._handleOpenURLEvent.bind(this); + (this: any).handleNavigation = this.handleNavigation.bind(this); + (this: any)._handleOpenURLEvent = this._handleOpenURLEvent.bind(this); } componentDidMount(): void { @@ -121,6 +124,7 @@ class NavigationRootContainer extends React.Component { AsyncStorage.getItem(this.props.persistenceKey, (err, storedString) => { if (err || !storedString) { this.setState({ + // $FlowFixMe - navState is missing properties :( navState: this.props.reducer(null, this.props.initialAction), }); return; @@ -164,6 +168,7 @@ class NavigationRootContainer extends React.Component { return false; } this.setState({ + // $FlowFixMe - navState is missing properties :( navState, }); @@ -183,6 +188,4 @@ class NavigationRootContainer extends React.Component { } } -NavigationRootContainer.getBackAction = getBackAction; - module.exports = NavigationRootContainer; diff --git a/Libraries/NavigationExperimental/NavigationTypeDefinition.js b/Libraries/NavigationExperimental/NavigationTypeDefinition.js index 08ccba47499..f0dff93ed9d 100644 --- a/Libraries/NavigationExperimental/NavigationTypeDefinition.js +++ b/Libraries/NavigationExperimental/NavigationTypeDefinition.js @@ -112,4 +112,3 @@ export type NavigationSceneRenderer = ( export type NavigationStyleInterpolator = ( props: NavigationSceneRendererProps, ) => Object; - diff --git a/Libraries/ReactIOS/YellowBox.js b/Libraries/ReactIOS/YellowBox.js index e1dddc14541..3aa51d537c8 100644 --- a/Libraries/ReactIOS/YellowBox.js +++ b/Libraries/ReactIOS/YellowBox.js @@ -180,6 +180,7 @@ class YellowBox extends React.Component { warningMap: Map; }; _listener: ?EmitterSubscription; + dismissWarning: (warning: ?string) => void; constructor(props: mixed, context: mixed) { super(props, context); diff --git a/Libraries/react-native/react-native.js.flow b/Libraries/react-native/react-native.js.flow index 53fc31e636f..ae9db08d147 100644 --- a/Libraries/react-native/react-native.js.flow +++ b/Libraries/react-native/react-native.js.flow @@ -123,7 +123,6 @@ var ReactNative = Object.assign(Object.create(require('react')), { TestModule: require('NativeModules').TestModule, TestUtils: undefined, batchedUpdates: require('ReactUpdates').batchedUpdates, - cloneWithProps: require('cloneWithProps'), createFragment: require('ReactFragment').create, update: require('update'), },