From b4a4c71a680bb6f42fe81aa5479eb42b78c1cfd3 Mon Sep 17 00:00:00 2001 From: Basil Hosmer Date: Thu, 16 Jun 2016 15:34:51 -0700 Subject: [PATCH] update flowification of react-native Reviewed By: frantic, gabelevi Differential Revision: D3436342 fbshipit-source-id: 7630eac4601d0768f57dc9fc945595039067eceb --- .flowconfig | 62 +------------------ .../NavigationCardStack.js | 2 +- Libraries/react-native/react-native.js.flow | 31 +++++++--- 3 files changed, 27 insertions(+), 68 deletions(-) diff --git a/.flowconfig b/.flowconfig index f018dae7d..0bbb11213 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,71 +1,13 @@ [ignore] # We fork some components by platform. -.*/*.web.js .*/*.android.js -# Some modules have their own node_modules with overlap -.*/node_modules/node-haste/.* - -# Ugh -.*/node_modules/babel.* -.*/node_modules/babylon.* -.*/node_modules/invariant.* - -# 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/ErrorUtils.js - -# Flow has a built-in definition for the 'react' module which we prefer to use -# over the currently-untyped source -.*/node_modules/react/react.js -.*/node_modules/react/lib/React.js -.*/node_modules/react/lib/ReactDOM.js - -.*/__mocks__/.* -.*/__tests__/.* - -.*/commoner/test/source/widget/share.js - -# Ignore commoner tests -.*/node_modules/commoner/test/.* - -# See https://github.com/facebook/flow/issues/442 -.*/react-tools/node_modules/commoner/lib/reader.js - -# Ignore jest -.*/node_modules/jest-cli/.* - -# Ignore Website -.*/website/.* - -# Ignore generators +# Ignore templates with `@flow` in header .*/local-cli/generator.* -# Ignore BUCK generated folders -.*\.buckd/ - -# Ignore RNPM -.*/local-cli/rnpm/.* - -.*/node_modules/is-my-json-valid/test/.*\.json -.*/node_modules/iconv-lite/encodings/tables/.*\.json +# Ignore malformed json .*/node_modules/y18n/test/.*\.json -.*/node_modules/spdx-license-ids/spdx-license-ids.json -.*/node_modules/spdx-exceptions/index.json -.*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json -.*/node_modules/resolve/lib/core.json -.*/node_modules/jsonparse/samplejson/.*\.json -.*/node_modules/json5/test/.*\.json -.*/node_modules/ua-parser-js/test/.*\.json -.*/node_modules/builtin-modules/builtin-modules.json -.*/node_modules/binary-extensions/binary-extensions.json -.*/node_modules/url-regex/tlds.json -.*/node_modules/joi/.*\.json -.*/node_modules/isemail/.*\.json -.*/node_modules/tr46/.*\.json - [include] diff --git a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js index 78cb1001e..a4a50c298 100644 --- a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js +++ b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js @@ -59,7 +59,7 @@ import type { type Props = { direction: NavigationGestureDirection, navigationState: NavigationState, - onNavigateBack: ?Function, + onNavigateBack?: Function, renderOverlay: ?NavigationSceneRenderer, renderScene: NavigationSceneRenderer, style: any, diff --git a/Libraries/react-native/react-native.js.flow b/Libraries/react-native/react-native.js.flow index b63a57cb5..7d608a643 100644 --- a/Libraries/react-native/react-native.js.flow +++ b/Libraries/react-native/react-native.js.flow @@ -16,14 +16,31 @@ */ 'use strict'; -// Export ReactNative, plus some native additions. +// Export some ReactNative properties, plus native additions. // -// The use of Object.create/assign is to work around a Flow bug (#6560135). -// Once that is fixed, change this back to + +// Our ReactNative.js has had its types stripped, so here we +// need to enumerate and type the properties we need access to. // -// var ReactNative = {...require('React'), /* additions */} -// -var ReactNative = Object.assign(Object.create(require('ReactNative')), { +var ReactNativeInternal = (require('ReactNative'): { + // render + render: ( + element: ReactElement, + mountInto: number, + callback?: ?(() => void) + ) => ?ReactComponent, + // findNodeHandle + findNodeHandle: (componentOrHandle: any) => ?number, + // NativeMethodsMixin + NativeMethodsMixin: Object +}); + +// export +var ReactNative = { + // from ReactNative internal + findNodeHandle: ReactNativeInternal.findNodeHandle, + render: ReactNativeInternal.render, + NativeMethodsMixin: ReactNativeInternal.NativeMethodsMixin, // Components ActivityIndicator: require('ActivityIndicator'), ActivityIndicatorIOS: require('ActivityIndicatorIOS'), @@ -118,6 +135,6 @@ var ReactNative = Object.assign(Object.create(require('ReactNative')), { ColorPropType: require('ColorPropType'), EdgeInsetsPropType: require('EdgeInsetsPropType'), PointPropType: require('PointPropType'), -}); +}; module.exports = ReactNative;