From b6333f79e1194e2fa59709d6e32e9f080124fac7 Mon Sep 17 00:00:00 2001 From: Logan Daniels Date: Fri, 23 Aug 2019 08:43:08 -0700 Subject: [PATCH] Final fixes and seal xplat/js/react-native-github Reviewed By: panagosg7 Differential Revision: D16946423 fbshipit-source-id: 89ca82c955e99a23a14984d51f3c97346c363afd --- .flowconfig | 2 +- .flowconfig.android | 2 +- Libraries/BugReporting/NativeBugReporting.js | 4 +- .../AccessibilityInfo.android.js | 6 +- .../DrawerLayoutAndroid.android.js | 11 +- .../ToastAndroid/ToastAndroid.android.js | 10 +- .../TouchableNativeFeedback.android.js | 4 +- .../View/ReactNativeStyleAttributes.js | 38 ++++- .../Components/View/ViewNativeComponent.js | 2 +- .../DeprecatedTextInputPropTypes.js | 134 +++++++++++++++--- Libraries/Image/Image.android.js | 39 +++-- Libraries/Image/NativeImageLoader.js | 2 +- .../Interaction/NativeFrameRateLogger.js | 4 +- Libraries/Network/RCTNetworking.android.js | 5 +- Libraries/Utilities/Platform.android.js | 19 ++- RNTester/js/RNTesterApp.android.js | 19 +-- .../ProgressBarAndroidExample.android.js | 7 +- .../js/examples/Text/TextExample.android.js | 7 +- .../TextInput/TextInputExample.android.js | 39 ++--- .../ToastAndroidExample.android.js | 8 +- RNTester/js/utils/RNTesterList.android.js | 2 +- .../components/ObjectPropsNativeComponent.js | 9 +- .../modules/NativeNullableTurboModule.js | 4 +- .../src/generators/components/CppHelpers.js | 2 +- .../src/parsers/flow/components/props.js | 6 +- 25 files changed, 280 insertions(+), 105 deletions(-) diff --git a/.flowconfig b/.flowconfig index e9022018546bd1..62e3d599588fb6 100644 --- a/.flowconfig +++ b/.flowconfig @@ -54,7 +54,7 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]* suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError experimental.well_formed_exports=true -experimental.well_formed_exports.whitelist=/Libraries/react-native/react-native-implementation.js +experimental.well_formed_exports.whitelist= [lints] sketchy-null-number=warn diff --git a/.flowconfig.android b/.flowconfig.android index e01244558487c2..66467e11e850ba 100644 --- a/.flowconfig.android +++ b/.flowconfig.android @@ -54,7 +54,7 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]* suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError experimental.well_formed_exports=true -experimental.well_formed_exports.whitelist=/Libraries/react-native/react-native-implementation.js +experimental.well_formed_exports.whitelist= [lints] sketchy-null-number=warn diff --git a/Libraries/BugReporting/NativeBugReporting.js b/Libraries/BugReporting/NativeBugReporting.js index 236b34e17a93b6..02ff311cc50f3c 100644 --- a/Libraries/BugReporting/NativeBugReporting.js +++ b/Libraries/BugReporting/NativeBugReporting.js @@ -8,8 +8,8 @@ * @flow */ -import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; import type {TurboModule} from '../TurboModule/RCTExport'; +import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; export interface Spec extends TurboModule { +startReportAProblemFlow: () => void; @@ -17,4 +17,4 @@ export interface Spec extends TurboModule { +setCategoryID: (categoryID: string) => void; } -export default TurboModuleRegistry.get('BugReporting'); +export default (TurboModuleRegistry.get('BugReporting'): ?Spec); diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js index 5c9ab848d2ecff..b44c2a6fb220bb 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js @@ -10,11 +10,11 @@ 'use strict'; -import NativeAccessibilityInfo from './NativeAccessibilityInfo'; - const RCTDeviceEventEmitter = require('../../EventEmitter/RCTDeviceEventEmitter'); const UIManager = require('../../ReactNative/UIManager'); +import NativeAccessibilityInfo from './NativeAccessibilityInfo'; + const REDUCE_MOTION_EVENT = 'reduceMotionDidChange'; const TOUCH_EXPLORATION_EVENT = 'touchExplorationDidChange'; @@ -90,7 +90,7 @@ const AccessibilityInfo = { * * Same as `isScreenReaderEnabled` */ - get fetch() { + get fetch(): () => Promise { return this.isScreenReaderEnabled; }, diff --git a/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js b/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js index 2575e982bbbd30..0ce582734e730d 100644 --- a/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +++ b/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js @@ -15,9 +15,10 @@ const React = require('react'); const StatusBar = require('../StatusBar/StatusBar'); const StyleSheet = require('../../StyleSheet/StyleSheet'); const View = require('../View/View'); -const nullthrows = require('nullthrows'); const dismissKeyboard = require('../../Utilities/dismissKeyboard'); +const nullthrows = require('nullthrows'); + import AndroidDrawerLayoutNativeComponent, { Commands, } from './AndroidDrawerLayoutNativeComponent'; @@ -163,15 +164,17 @@ class DrawerLayoutAndroid extends React.Component { return {Left: 'left', Right: 'right'}; } - static defaultProps = { + static defaultProps: {| + drawerBackgroundColor: 'white', + |} = { drawerBackgroundColor: 'white', }; _nativeRef = React.createRef(); - state = {statusBarBackgroundColor: null}; + state: State = {statusBarBackgroundColor: null}; - render() { + render(): React.Node { const { onDrawerStateChanged, renderNavigationView, diff --git a/Libraries/Components/ToastAndroid/ToastAndroid.android.js b/Libraries/Components/ToastAndroid/ToastAndroid.android.js index ff1db3cf90bf88..9ff5182491a229 100644 --- a/Libraries/Components/ToastAndroid/ToastAndroid.android.js +++ b/Libraries/Components/ToastAndroid/ToastAndroid.android.js @@ -34,12 +34,12 @@ import NativeToastAndroid from './NativeToastAndroid'; const ToastAndroid = { // Toast duration constants - SHORT: NativeToastAndroid.getConstants().SHORT, - LONG: NativeToastAndroid.getConstants().LONG, + SHORT: (NativeToastAndroid.getConstants().SHORT: number), + LONG: (NativeToastAndroid.getConstants().LONG: number), // Toast gravity constants - TOP: NativeToastAndroid.getConstants().TOP, - BOTTOM: NativeToastAndroid.getConstants().BOTTOM, - CENTER: NativeToastAndroid.getConstants().CENTER, + TOP: (NativeToastAndroid.getConstants().TOP: number), + BOTTOM: (NativeToastAndroid.getConstants().BOTTOM: number), + CENTER: (NativeToastAndroid.getConstants().CENTER: number), show: function(message: string, duration: number): void { NativeToastAndroid.show(message, duration); diff --git a/Libraries/Components/Touchable/TouchableNativeFeedback.android.js b/Libraries/Components/Touchable/TouchableNativeFeedback.android.js index 4ccbb7570b831d..a4edef82dbf377 100644 --- a/Libraries/Components/Touchable/TouchableNativeFeedback.android.js +++ b/Libraries/Components/Touchable/TouchableNativeFeedback.android.js @@ -11,8 +11,8 @@ 'use strict'; const Platform = require('../../Utilities/Platform'); -const React = require('react'); const PropTypes = require('prop-types'); +const React = require('react'); const Touchable = require('./Touchable'); const TouchableWithoutFeedback = require('./TouchableWithoutFeedback'); const View = require('../View/View'); @@ -345,4 +345,4 @@ const TouchableNativeFeedback = createReactClass({ }, }); -module.exports = TouchableNativeFeedback; +module.exports = (TouchableNativeFeedback: $FlowFixMe); diff --git a/Libraries/Components/View/ReactNativeStyleAttributes.js b/Libraries/Components/View/ReactNativeStyleAttributes.js index c1126c724e554b..f80746cd447b09 100644 --- a/Libraries/Components/View/ReactNativeStyleAttributes.js +++ b/Libraries/Components/View/ReactNativeStyleAttributes.js @@ -18,7 +18,43 @@ const processColor = require('../../StyleSheet/processColor'); const processTransform = require('../../StyleSheet/processTransform'); const sizesDiffer = require('../../Utilities/differ/sizesDiffer'); -const ReactNativeStyleAttributes = {}; +type ReturnBoolType = (V) => true; +type BoolifiedDeprecatedViewStylePropTypes = $ObjMap< + typeof DeprecatedViewStylePropTypes, + ReturnBoolType, +>; +type BoolifiedDeprecatedTextStylePropTypes = $ObjMapi< + typeof DeprecatedTextStylePropTypes, + ReturnBoolType, +>; +type BoolifiedDeprecatedImageStylePropTypes = $ObjMapi< + typeof DeprecatedImageStylePropTypes, + ReturnBoolType, +>; + +type StyleAttributesType = { + ...BoolifiedDeprecatedViewStylePropTypes, + ...BoolifiedDeprecatedTextStylePropTypes, + ...BoolifiedDeprecatedImageStylePropTypes, + transform: $ReadOnly<{|process: typeof processTransform|}> | true, + shadowOffset: $ReadOnly<{|diff: typeof sizesDiffer|}> | true, + backgroundColor: typeof colorAttributes | true, + borderBottomColor: typeof colorAttributes | true, + borderColor: typeof colorAttributes | true, + borderLeftColor: typeof colorAttributes | true, + borderRightColor: typeof colorAttributes | true, + borderTopColor: typeof colorAttributes | true, + borderStartColor: typeof colorAttributes | true, + borderEndColor: typeof colorAttributes | true, + color: typeof colorAttributes | true, + shadowColor: typeof colorAttributes | true, + textDecorationColor: typeof colorAttributes | true, + tintColor: typeof colorAttributes | true, + textShadowColor: typeof colorAttributes | true, + overlayColor: typeof colorAttributes | true, +}; + +const ReactNativeStyleAttributes: StyleAttributesType = {}; for (const attributeName of Object.keys({ ...DeprecatedViewStylePropTypes, diff --git a/Libraries/Components/View/ViewNativeComponent.js b/Libraries/Components/View/ViewNativeComponent.js index 8b58086b83ccf8..276bbbb2e9c5ff 100644 --- a/Libraries/Components/View/ViewNativeComponent.js +++ b/Libraries/Components/View/ViewNativeComponent.js @@ -83,7 +83,7 @@ interface NativeCommands { ) => void; } -export const Commands = codegenNativeCommands({ +export const Commands: NativeCommands = codegenNativeCommands({ supportedCommands: ['hotspotUpdate', 'setPressed'], }); diff --git a/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js b/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js index 5748999e57fe3b..9288b0f01d1271 100644 --- a/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js +++ b/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js @@ -10,10 +10,10 @@ 'use strict'; -const PropTypes = require('prop-types'); const DeprecatedColorPropType = require('./DeprecatedColorPropType'); const DeprecatedViewPropTypes = require('./DeprecatedViewPropTypes'); const DocumentSelectionState = require('../vendor/document/selection/DocumentSelectionState'); +const PropTypes = require('prop-types'); const Text = require('../Text/Text'); const DataDetectorTypes = [ @@ -35,7 +35,12 @@ module.exports = { * - `sentences`: first letter of each sentence (*default*). * - `none`: don't auto capitalize anything. */ - autoCapitalize: PropTypes.oneOf(['none', 'sentences', 'words', 'characters']), + autoCapitalize: (PropTypes.oneOf([ + 'none', + 'sentences', + 'words', + 'characters', + ]): React$PropType$Primitive<'none' | 'sentences' | 'words' | 'characters'>), /** * Determines which content to suggest on auto complete, e.g.`username`. * To disable auto complete, use `off`. @@ -60,7 +65,7 @@ module.exports = { * * @platform android */ - autoCompleteType: PropTypes.oneOf([ + autoCompleteType: (PropTypes.oneOf([ 'cc-csc', 'cc-exp', 'cc-exp-month', @@ -74,7 +79,21 @@ module.exports = { 'tel', 'username', 'off', - ]), + ]): React$PropType$Primitive< + | 'cc-csc' + | 'cc-exp' + | 'cc-exp-month' + | 'cc-exp-year' + | 'cc-number' + | 'email' + | 'name' + | 'password' + | 'postal-code' + | 'street-address' + | 'tel' + | 'username' + | 'off', + >), /** * If `false`, disables auto-correct. The default value is `true`. */ @@ -136,7 +155,7 @@ module.exports = { * * - `visible-password` */ - keyboardType: PropTypes.oneOf([ + keyboardType: (PropTypes.oneOf([ // Cross-platform 'default', 'email-address', @@ -153,12 +172,30 @@ module.exports = { 'web-search', // Android-only 'visible-password', - ]), + ]): React$PropType$Primitive< + | 'default' + | 'email-address' + | 'numeric' + | 'phone-pad' + | 'number-pad' + | 'ascii-capable' + | 'numbers-and-punctuation' + | 'url' + | 'name-phone-pad' + | 'decimal-pad' + | 'twitter' + | 'web-search' + | 'visible-password', + >), /** * Determines the color of the keyboard. * @platform ios */ - keyboardAppearance: PropTypes.oneOf(['default', 'light', 'dark']), + keyboardAppearance: (PropTypes.oneOf([ + 'default', + 'light', + 'dark', + ]): React$PropType$Primitive<'default' | 'light' | 'dark'>), /** * Determines how the return key should look. On Android you can also use * `returnKeyLabel`. @@ -191,7 +228,7 @@ module.exports = { * - `route` * - `yahoo` */ - returnKeyType: PropTypes.oneOf([ + returnKeyType: (PropTypes.oneOf([ // Cross-platform 'done', 'go', @@ -208,7 +245,21 @@ module.exports = { 'join', 'route', 'yahoo', - ]), + ]): React$PropType$Primitive< + | 'done' + | 'go' + | 'next' + | 'search' + | 'send' + | 'none' + | 'previous' + | 'default' + | 'emergency-call' + | 'google' + | 'join' + | 'route' + | 'yahoo', + >), /** * Sets the return key to the label. Use it instead of `returnKeyType`. * @platform android @@ -250,7 +301,11 @@ module.exports = { * The default value is `simple`. * @platform android */ - textBreakStrategy: PropTypes.oneOf(['simple', 'highQuality', 'balanced']), + textBreakStrategy: (PropTypes.oneOf([ + 'simple', + 'highQuality', + 'balanced', + ]): React$PropType$Primitive<'simple' | 'highQuality' | 'balanced'>), /** * Callback that is called when the text input is blurred. */ @@ -348,15 +403,15 @@ module.exports = { * * @platform ios */ - selectionState: PropTypes.instanceOf(DocumentSelectionState), + selectionState: (PropTypes.instanceOf(DocumentSelectionState): void), /** * The start and end of the text input's selection. Set start and end to * the same value to position the cursor. */ - selection: PropTypes.shape({ + selection: (PropTypes.shape({ start: PropTypes.number.isRequired, end: PropTypes.number, - }), + }): React$PropType$Primitive<{end?: number, start: number}>), /** * The value to show for the text input. `TextInput` is a controlled * component, which means the native value will be forced to match this @@ -378,12 +433,14 @@ module.exports = { * This property is supported only for single-line TextInput component. * @platform ios */ - clearButtonMode: PropTypes.oneOf([ + clearButtonMode: (PropTypes.oneOf([ 'never', 'while-editing', 'unless-editing', 'always', - ]), + ]): React$PropType$Primitive< + 'never' | 'while-editing' | 'unless-editing' | 'always', + >), /** * If `true`, clears the text field automatically when editing begins. * @platform ios @@ -471,10 +528,20 @@ module.exports = { * * @platform ios */ - dataDetectorTypes: PropTypes.oneOfType([ + dataDetectorTypes: (PropTypes.oneOfType([ PropTypes.oneOf(DataDetectorTypes), PropTypes.arrayOf(PropTypes.oneOf(DataDetectorTypes)), - ]), + ]): React$PropType$Primitive< + | 'phoneNumber' + | 'link' + | 'address' + | 'calendarEvent' + | 'none' + | 'all' + | Array< + 'phoneNumber' | 'link' | 'address' | 'calendarEvent' | 'none' | 'all', + >, + >), /** * If `true`, caret is hidden. The default value is `false`. * This property is supported only for single-line TextInput component on iOS. @@ -496,7 +563,7 @@ module.exports = { * expected semantic meaning for the content that users enter. * @platform ios */ - textContentType: PropTypes.oneOf([ + textContentType: (PropTypes.oneOf([ 'none', 'URL', 'addressCity', @@ -525,7 +592,36 @@ module.exports = { 'password', 'newPassword', 'oneTimeCode', - ]), + ]): React$PropType$Primitive< + | 'none' + | 'URL' + | 'addressCity' + | 'addressCityAndState' + | 'addressState' + | 'countryName' + | 'creditCardNumber' + | 'emailAddress' + | 'familyName' + | 'fullStreetAddress' + | 'givenName' + | 'jobTitle' + | 'location' + | 'middleName' + | 'name' + | 'namePrefix' + | 'nameSuffix' + | 'nickname' + | 'organizationName' + | 'postalCode' + | 'streetAddressLine1' + | 'streetAddressLine2' + | 'sublocality' + | 'telephoneNumber' + | 'username' + | 'password' + | 'newPassword' + | 'oneTimeCode', + >), /** * When `false`, it will prevent the soft keyboard from showing when the field is focused. * Defaults to `true`. diff --git a/Libraries/Image/Image.android.js b/Libraries/Image/Image.android.js index c6f9d9e5eb5255..4c9d13d5e5bd4c 100644 --- a/Libraries/Image/Image.android.js +++ b/Libraries/Image/Image.android.js @@ -38,11 +38,13 @@ function generateRequestId() { const ImageProps = { ...DeprecatedViewPropTypes, - style: DeprecatedStyleSheetPropType(DeprecatedImageStylePropTypes), + style: (DeprecatedStyleSheetPropType( + DeprecatedImageStylePropTypes, + ): ReactPropsCheckType), /** * See https://facebook.github.io/react-native/docs/image.html#source */ - source: PropTypes.oneOfType([ + source: (PropTypes.oneOfType([ PropTypes.shape({ uri: PropTypes.string, headers: PropTypes.objectOf(PropTypes.string), @@ -58,7 +60,16 @@ const ImageProps = { headers: PropTypes.objectOf(PropTypes.string), }), ), - ]), + ]): React$PropType$Primitive< + | {headers?: {[string]: string}, uri?: string} + | number + | Array<{ + headers?: {[string]: string}, + height?: number, + uri?: string, + width?: number, + }>, + >), /** * blurRadius: the blur radius of the blur filter added to the image * @@ -72,13 +83,13 @@ const ImageProps = { /** * See https://facebook.github.io/react-native/docs/image.html#loadingindicatorsource */ - loadingIndicatorSource: PropTypes.oneOfType([ + loadingIndicatorSource: (PropTypes.oneOfType([ PropTypes.shape({ uri: PropTypes.string, }), // Opaque type returned by require('./image.jpg') PropTypes.number, - ]), + ]): React$PropType$Primitive<{uri?: string} | number>), progressiveRenderingEnabled: PropTypes.bool, fadeDuration: PropTypes.number, /** @@ -107,20 +118,26 @@ const ImageProps = { * * See https://facebook.github.io/react-native/docs/image.html#resizemethod */ - resizeMethod: PropTypes.oneOf(['auto', 'resize', 'scale']), + resizeMethod: (PropTypes.oneOf([ + 'auto', + 'resize', + 'scale', + ]): React$PropType$Primitive<'auto' | 'resize' | 'scale'>), /** * Determines how to resize the image when the frame doesn't match the raw * image dimensions. * * See https://facebook.github.io/react-native/docs/image.html#resizemode */ - resizeMode: PropTypes.oneOf([ + resizeMode: (PropTypes.oneOf([ 'cover', 'contain', 'stretch', 'repeat', 'center', - ]), + ]): React$PropType$Primitive< + 'cover' | 'contain' | 'stretch' | 'repeat' | 'center', + >), }; /** @@ -132,7 +149,7 @@ function getSize( url: string, success: (width: number, height: number) => void, failure?: (error: any) => void, -) { +): any { return ImageLoader.getSize(url) .then(function(sizes) { success(sizes.width, sizes.height); @@ -156,7 +173,7 @@ function getSizeWithHeaders( headers: {[string]: string}, success: (width: number, height: number) => void, failure?: (error: any) => void, -) { +): any { return ImageLoader.getSizeWithHeaders(url, headers) .then(function(sizes) { success(sizes.width, sizes.height); @@ -169,7 +186,7 @@ function getSizeWithHeaders( ); } -function prefetch(url: string, callback: ?Function) { +function prefetch(url: string, callback: ?Function): any { const requestId = generateRequestId(); callback && callback(requestId); return ImageLoader.prefetchImage(url, requestId); diff --git a/Libraries/Image/NativeImageLoader.js b/Libraries/Image/NativeImageLoader.js index 4c36ba7533d2d4..ae84cfe71fab96 100644 --- a/Libraries/Image/NativeImageLoader.js +++ b/Libraries/Image/NativeImageLoader.js @@ -17,4 +17,4 @@ export interface Spec extends TurboModule { +getConstants: () => {||}; } -export default TurboModuleRegistry.getEnforcing('ImageLoader'); +export default (TurboModuleRegistry.getEnforcing('ImageLoader'): Spec); diff --git a/Libraries/Interaction/NativeFrameRateLogger.js b/Libraries/Interaction/NativeFrameRateLogger.js index 9780519c171ac0..d1829065f47c68 100644 --- a/Libraries/Interaction/NativeFrameRateLogger.js +++ b/Libraries/Interaction/NativeFrameRateLogger.js @@ -8,8 +8,8 @@ * @flow */ -import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; import type {TurboModule} from '../TurboModule/RCTExport'; +import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; export interface Spec extends TurboModule { +setGlobalOptions: (options: {| @@ -21,4 +21,4 @@ export interface Spec extends TurboModule { +endScroll: () => void; } -export default TurboModuleRegistry.get('FrameRateLogger'); +export default (TurboModuleRegistry.get('FrameRateLogger'): ?Spec); diff --git a/Libraries/Network/RCTNetworking.android.js b/Libraries/Network/RCTNetworking.android.js index c809b8dcdd3a18..b1577a078fc12b 100644 --- a/Libraries/Network/RCTNetworking.android.js +++ b/Libraries/Network/RCTNetworking.android.js @@ -13,9 +13,10 @@ // Do not require the native RCTNetworking module directly! Use this wrapper module instead. // It will add the necessary requestId, so that you don't have to generate it yourself. const NativeEventEmitter = require('../EventEmitter/NativeEventEmitter'); -import NativeNetworkingAndroid from './NativeNetworkingAndroid'; + const convertRequestBody = require('./convertRequestBody'); +import NativeNetworkingAndroid from './NativeNetworkingAndroid'; import type {RequestBody} from './convertRequestBody'; type Header = [string, string]; @@ -87,4 +88,4 @@ class RCTNetworking extends NativeEventEmitter { } } -module.exports = new RCTNetworking(); +module.exports = (new RCTNetworking(): RCTNetworking); diff --git a/Libraries/Utilities/Platform.android.js b/Libraries/Utilities/Platform.android.js index e228adc98d2744..fd0cb70d49be6a 100644 --- a/Libraries/Utilities/Platform.android.js +++ b/Libraries/Utilities/Platform.android.js @@ -20,10 +20,25 @@ export type PlatformSelectSpec = { const Platform = { __constants: null, OS: 'android', - get Version() { + get Version(): number { return this.constants.Version; }, - get constants() { + get constants(): {| + isTesting: boolean, + reactNativeVersion: {| + major: number, + minor: number, + patch: number, + prerelease: ?number, + |}, + Version: number, + Release: string, + Serial: string, + Fingerprint: string, + Model: string, + ServerHost: string, + uiMode: string, + |} { if (this.__constants == null) { this.__constants = NativePlatformConstantsAndroid.getConstants(); } diff --git a/RNTester/js/RNTesterApp.android.js b/RNTester/js/RNTesterApp.android.js index bd5201d86af322..047522f8e3941c 100644 --- a/RNTester/js/RNTesterApp.android.js +++ b/RNTester/js/RNTesterApp.android.js @@ -10,7 +10,16 @@ 'use strict'; +const RNTesterActions = require('./utils/RNTesterActions'); +const RNTesterExampleContainer = require('./components/RNTesterExampleContainer'); +const RNTesterExampleList = require('./components/RNTesterExampleList'); +const RNTesterList = require('./utils/RNTesterList'); +const RNTesterNavigationReducer = require('./utils/RNTesterNavigationReducer'); const React = require('react'); +const URIActionMap = require('./utils/URIActionMap'); + +const nativeImageSource = require('../../Libraries/Image/nativeImageSource'); + const { AppRegistry, AsyncStorage, @@ -26,14 +35,6 @@ const { UIManager, View, } = require('react-native'); -const RNTesterActions = require('./utils/RNTesterActions'); -const RNTesterExampleContainer = require('./components/RNTesterExampleContainer'); -const RNTesterExampleList = require('./components/RNTesterExampleList'); -const RNTesterList = require('./utils/RNTesterList'); -const RNTesterNavigationReducer = require('./utils/RNTesterNavigationReducer'); -const URIActionMap = require('./utils/URIActionMap'); - -const nativeImageSource = require('../../Libraries/Image/nativeImageSource'); import type {RNTesterNavigationState} from './utils/RNTesterNavigationReducer'; @@ -99,7 +100,7 @@ class RNTesterApp extends React.Component { }); } - render() { + render(): React.Node { if (!this.state) { return null; } diff --git a/RNTester/js/examples/ProgressBarAndroid/ProgressBarAndroidExample.android.js b/RNTester/js/examples/ProgressBarAndroid/ProgressBarAndroidExample.android.js index 86a6bd662c5515..5024f2970d5685 100644 --- a/RNTester/js/examples/ProgressBarAndroid/ProgressBarAndroidExample.android.js +++ b/RNTester/js/examples/ProgressBarAndroid/ProgressBarAndroidExample.android.js @@ -10,10 +10,11 @@ 'use strict'; -const React = require('react'); -const {ProgressBarAndroid: ProgressBar} = require('react-native'); const RNTesterBlock = require('../../components/RNTesterBlock'); const RNTesterPage = require('../../components/RNTesterPage'); +const React = require('react'); + +const {ProgressBarAndroid: ProgressBar} = require('react-native'); import type {ProgressBarAndroidProps} from '../../../../Libraries/Components/ProgressBarAndroid/ProgressBarAndroid'; @@ -57,7 +58,7 @@ class MovingBar extends React.Component { } class ProgressBarAndroidExample extends React.Component<{}> { - render() { + render(): React.Node { return ( diff --git a/RNTester/js/examples/Text/TextExample.android.js b/RNTester/js/examples/Text/TextExample.android.js index dbded71f36ac3e..ae3aa5c81179da 100644 --- a/RNTester/js/examples/Text/TextExample.android.js +++ b/RNTester/js/examples/Text/TextExample.android.js @@ -10,13 +10,14 @@ 'use strict'; -const React = require('react'); -const {StyleSheet, Text, View} = require('react-native'); const RNTesterBlock = require('../../components/RNTesterBlock'); const RNTesterPage = require('../../components/RNTesterPage'); +const React = require('react'); const TextInlineView = require('../../components/TextInlineView'); const TextLegend = require('../../components/TextLegend'); +const {StyleSheet, Text, View} = require('react-native'); + class Entity extends React.Component<{|children: React.Node|}> { render() { return ( @@ -70,7 +71,7 @@ class AttributeToggler extends React.Component<{}, $FlowFixMeState> { } class TextExample extends React.Component<{}> { - render() { + render(): React.Node { return ( diff --git a/RNTester/js/examples/TextInput/TextInputExample.android.js b/RNTester/js/examples/TextInput/TextInputExample.android.js index edeb83eb6092f5..091b89dbf9f791 100644 --- a/RNTester/js/examples/TextInput/TextInputExample.android.js +++ b/RNTester/js/examples/TextInput/TextInputExample.android.js @@ -11,6 +11,7 @@ 'use strict'; const React = require('react'); + const { Text, TextInput, @@ -450,7 +451,7 @@ exports.description = 'Single and multi-line text inputs.'; exports.examples = [ { title: 'Auto-focus', - render: function() { + render: function(): React.Node { return ( -> '_')", - render: function() { + render: function(): React.Node { return ; }, }, { title: 'Auto-capitalize', - render: function() { + render: function(): React.Node { const autoCapitalizeTypes = ['none', 'sentences', 'words', 'characters']; const examples = autoCapitalizeTypes.map(type => { return ( @@ -488,7 +489,7 @@ exports.examples = [ }, { title: 'Auto-correct', - render: function() { + render: function(): React.Node { return ( ; }, }, { title: 'Return key', - render: function() { + render: function(): React.Node { const returnKeyTypes = [ 'none', 'go', @@ -822,7 +823,7 @@ exports.examples = [ }, { title: 'Inline Images', - render: function() { + render: function(): React.Node { return ( { + render: function(): React.Node { return ; }, }, { title: 'Text selection & cursor placement', - render: function() { + render: function(): React.Node { return ( ; class ToastExample extends React.Component { - render() { + render(): React.Node { return ( diff --git a/RNTester/js/utils/RNTesterList.android.js b/RNTester/js/utils/RNTesterList.android.js index 1307335996de32..238fca68defba2 100644 --- a/RNTester/js/utils/RNTesterList.android.js +++ b/RNTester/js/utils/RNTesterList.android.js @@ -226,7 +226,7 @@ const APIExamples: Array = [ }, ]; -const Modules = {}; +const Modules: any = {}; APIExamples.concat(ComponentExamples).forEach(Example => { Modules[Example.key] = Example.module; diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/ObjectPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/ObjectPropsNativeComponent.js index ad166c74ca4350..460b8f4f47cf30 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/ObjectPropsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/ObjectPropsNativeComponent.js @@ -10,18 +10,19 @@ 'use strict'; +import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; +import type {ImageSource} from '../../../../../Libraries/Image/ImageSource'; import type { PointValue, ColorValue, } from '../../../../../Libraries/StyleSheet/StyleSheetTypes'; -import type {ImageSource} from '../../../../../Libraries/Image/ImageSource'; import type { Int32, Float, WithDefault, } from '../../../../../Libraries/Types/CodegenTypes'; -import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent'; +import type {NativeComponentType} from '../../../../../Libraries/Utilities/codegenNativeComponent'; type ObjectArrayPropType = $ReadOnly<{| array: $ReadOnlyArray, @@ -46,6 +47,6 @@ type NativeProps = $ReadOnly<{| |}>, |}>; -export default codegenNativeComponent( +export default (codegenNativeComponent( 'ObjectPropsNativeComponent', -); +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeNullableTurboModule.js b/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeNullableTurboModule.js index a9c631a30e9fbc..3ccc8876b45df4 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeNullableTurboModule.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeNullableTurboModule.js @@ -22,4 +22,6 @@ export interface Spec extends TurboModule { +getValueWithPromise: () => ?Promise; } -export default TurboModuleRegistry.getEnforcing('SampleTurboModule'); +export default (TurboModuleRegistry.getEnforcing( + 'SampleTurboModule', +): Spec); diff --git a/packages/react-native-codegen/src/generators/components/CppHelpers.js b/packages/react-native-codegen/src/generators/components/CppHelpers.js index b05293598b0a19..14363e71b0610a 100644 --- a/packages/react-native-codegen/src/generators/components/CppHelpers.js +++ b/packages/react-native-codegen/src/generators/components/CppHelpers.js @@ -91,7 +91,7 @@ function getImports(properties: $ReadOnlyArray): Set { function generateStructName( componentName: string, parts: $ReadOnlyArray = [], -) { +): string { const additional = parts.map(toSafeCppString).join(''); return `${componentName}${additional}Struct`; } diff --git a/packages/react-native-codegen/src/parsers/flow/components/props.js b/packages/react-native-codegen/src/parsers/flow/components/props.js index 3bd8591d9f41c7..0d13e710783652 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/props.js +++ b/packages/react-native-codegen/src/parsers/flow/components/props.js @@ -10,12 +10,12 @@ 'use strict'; +const {getValueFromTypes} = require('../utils.js'); + import type {PropTypeShape} from '../../../CodegenSchema.js'; import type {TypeMap} from '../utils.js'; -const {getValueFromTypes} = require('../utils.js'); - -function getPropProperties(propsTypeName: string, types: TypeMap) { +function getPropProperties(propsTypeName: string, types: TypeMap): $FlowFixMe { const typeAlias = types[propsTypeName]; try { return typeAlias.right.typeParameters.params[0].properties;