From 9127fb51fc94a94c4a9f957c3e421a1667a9a20a Mon Sep 17 00:00:00 2001 From: Logan Daniels Date: Fri, 9 Aug 2019 10:06:53 -0700 Subject: [PATCH] Manual fixes for xplat/js/react-native-github Summary: Need to add explicit type annotations in these areas to unblock types-first architecture for Flow. These are locations the codemod could not automatically handle. I'll call out areas I need a close eye on in the comments. Reviewed By: panagosg7 Differential Revision: D16659053 fbshipit-source-id: 167dd2abe093019b128676426374c1c62cf71e7f --- Libraries/Animated/src/Animated.js | 23 +++--- Libraries/Animated/src/AnimatedMock.js | 2 +- .../src/nodes/AnimatedInterpolation.js | 6 +- .../ActivityIndicatorViewNativeComponent.js | 5 +- Libraries/Components/Button.js | 2 +- .../RCTMaskedViewNativeComponent.js | 5 +- .../ProgressBarAndroidNativeComponent.js | 5 +- .../RCTProgressViewNativeComponent.js | 5 +- ...ndroidSwipeRefreshLayoutNativeComponent.js | 5 +- .../PullToRefreshViewNativeComponent.js | 5 +- .../RefreshControl/RefreshControl.js | 10 +-- .../RCTSafeAreaViewNativeComponent.js | 5 +- .../RCTSegmentedControlNativeComponent.js | 5 +- .../Slider/SliderNativeComponent.js | 5 +- .../Switch/SwitchNativeComponent.js | 5 +- .../RCTInputAccessoryViewNativeComponent.js | 5 +- .../UnimplementedNativeViewNativeComponent.js | 5 +- .../View/ReactNativeViewAttributes.js | 13 ++-- Libraries/Components/View/View.js | 4 +- .../Components/View/ViewNativeComponent.js | 4 +- Libraries/Interaction/InteractionManager.js | 2 +- Libraries/Interaction/InteractionMixin.js | 7 +- Libraries/Lists/FillRateHelper.js | 20 ++--- Libraries/Lists/FlatList.js | 6 +- Libraries/Lists/SectionList.js | 4 +- Libraries/Lists/VirtualizedList.js | 77 ++++++++++++++++--- Libraries/Lists/VirtualizedSectionList.js | 7 +- .../Modal/RCTModalHostViewNativeComponent.js | 5 +- .../components/DebugInstructions.js | 5 +- Libraries/NewAppScreen/components/Header.js | 8 +- .../NewAppScreen/components/LearnMoreLinks.js | 10 +-- .../components/ReloadInstructions.js | 5 +- .../Utilities/GlobalPerformanceLogger.js | 5 +- Libraries/Utilities/codegenNativeComponent.js | 4 +- Libraries/Utilities/setAndForwardRef.js | 5 +- Libraries/YellowBox/YellowBox.js | 8 +- Libraries/vendor/emitter/EventValidator.js | 2 +- .../js/components/RNTesterSettingSwitchRow.js | 7 +- .../PanResponder/PanResponderExample.js | 2 +- .../examples/Snapshot/SnapshotViewIOS.ios.js | 7 +- .../components/ArrayPropsNativeComponent.js | 5 +- .../components/BooleanPropNativeComponent.js | 5 +- .../components/ColorPropNativeComponent.js | 5 +- .../components/EnumPropNativeComponent.js | 5 +- .../EventNestedObjectPropsNativeComponent.js | 5 +- .../components/EventPropsNativeComponent.js | 5 +- .../components/FloatPropsNativeComponent.js | 5 +- .../components/ImagePropNativeComponent.js | 5 +- .../components/IntegerPropNativeComponent.js | 5 +- .../InterfaceOnlyNativeComponent.js | 5 +- .../MultiNativePropNativeComponent.js | 5 +- .../NoPropsNoEventsNativeComponent.js | 5 +- .../components/PointPropNativeComponent.js | 5 +- .../components/StringPropNativeComponent.js | 5 +- template/App.js | 2 +- 55 files changed, 270 insertions(+), 122 deletions(-) diff --git a/Libraries/Animated/src/Animated.js b/Libraries/Animated/src/Animated.js index 594a1b82fc1451..a14bf98f4c9e44 100644 --- a/Libraries/Animated/src/Animated.js +++ b/Libraries/Animated/src/Animated.js @@ -12,28 +12,31 @@ import Platform from '../../Utilities/Platform'; -const AnimatedImplementation = Platform.isTesting - ? require('./AnimatedMock') - : require('./AnimatedImplementation'); +const AnimatedMock = require('./AnimatedMock'); +const AnimatedImplementation = require('./AnimatedImplementation'); + +const Animated = ((Platform.isTesting + ? AnimatedMock + : AnimatedImplementation): typeof AnimatedMock); module.exports = { - get FlatList() { + get FlatList(): any { return require('./components/AnimatedFlatList'); }, - get Image() { + get Image(): any { return require('./components/AnimatedImage'); }, - get ScrollView() { + get ScrollView(): any { return require('./components/AnimatedScrollView'); }, - get SectionList() { + get SectionList(): any { return require('./components/AnimatedSectionList'); }, - get Text() { + get Text(): any { return require('./components/AnimatedText'); }, - get View() { + get View(): any { return require('./components/AnimatedView'); }, - ...AnimatedImplementation, + ...Animated, }; diff --git a/Libraries/Animated/src/AnimatedMock.js b/Libraries/Animated/src/AnimatedMock.js index 2800560f5926b7..aed90a5ad05c19 100644 --- a/Libraries/Animated/src/AnimatedMock.js +++ b/Libraries/Animated/src/AnimatedMock.js @@ -110,7 +110,7 @@ const stagger = function( return emptyAnimation; }; -type LoopAnimationConfig = {iterations: number}; +type LoopAnimationConfig = {iterations: number, resetBeforeIteration?: boolean}; const loop = function( animation: CompositeAnimation, diff --git a/Libraries/Animated/src/nodes/AnimatedInterpolation.js b/Libraries/Animated/src/nodes/AnimatedInterpolation.js index 19387984ccf64b..25caa17e0d8bfe 100644 --- a/Libraries/Animated/src/nodes/AnimatedInterpolation.js +++ b/Libraries/Animated/src/nodes/AnimatedInterpolation.js @@ -307,7 +307,9 @@ function checkInfiniteRange(name: string, arr: Array) { class AnimatedInterpolation extends AnimatedWithChildren { // Export for testing. - static __createInterpolation = createInterpolation; + static __createInterpolation: ( + config: InterpolationConfigType, + ) => (input: number) => number | string = createInterpolation; _parent: AnimatedNode; _config: InterpolationConfigType; @@ -347,7 +349,7 @@ class AnimatedInterpolation extends AnimatedWithChildren { super.__detach(); } - __transformDataType(range: Array) { + __transformDataType(range: Array): Array { return range.map(NativeAnimatedHelper.transformDataType); } diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js b/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js index 47c8fa1692ade1..487f76d6196bcc 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js @@ -16,6 +16,7 @@ import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -50,6 +51,6 @@ type NativeProps = $ReadOnly<{| size?: WithDefault<'small' | 'large', 'small'>, |}>; -export default codegenNativeComponent('ActivityIndicatorView', { +export default (codegenNativeComponent('ActivityIndicatorView', { paperComponentName: 'RCTActivityIndicatorView', -}); +}): NativeComponentType); diff --git a/Libraries/Components/Button.js b/Libraries/Components/Button.js index 5105ee1badc3bc..6782862184053d 100644 --- a/Libraries/Components/Button.js +++ b/Libraries/Components/Button.js @@ -128,7 +128,7 @@ type ButtonProps = $ReadOnly<{| */ class Button extends React.Component { - render() { + render(): React.Node { const { accessibilityLabel, color, diff --git a/Libraries/Components/MaskedView/RCTMaskedViewNativeComponent.js b/Libraries/Components/MaskedView/RCTMaskedViewNativeComponent.js index 1b6ad607ca5591..f9c3de50ccdad1 100644 --- a/Libraries/Components/MaskedView/RCTMaskedViewNativeComponent.js +++ b/Libraries/Components/MaskedView/RCTMaskedViewNativeComponent.js @@ -10,9 +10,12 @@ import type {ViewProps} from '../View/ViewPropTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, |}>; -export default codegenNativeComponent('RCTMaskedView'); +export default (codegenNativeComponent( + 'RCTMaskedView', +): NativeComponentType); diff --git a/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidNativeComponent.js b/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidNativeComponent.js index 47af65b9f138b0..033d2637c32346 100644 --- a/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidNativeComponent.js +++ b/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidNativeComponent.js @@ -15,6 +15,7 @@ import type {ViewProps} from '../View/ViewPropTypes'; import type {Float, WithDefault} from '../../Types/CodegenTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -29,4 +30,6 @@ type NativeProps = $ReadOnly<{| testID?: WithDefault, |}>; -export default codegenNativeComponent('AndroidProgressBar'); +export default (codegenNativeComponent( + 'AndroidProgressBar', +): NativeComponentType); diff --git a/Libraries/Components/ProgressViewIOS/RCTProgressViewNativeComponent.js b/Libraries/Components/ProgressViewIOS/RCTProgressViewNativeComponent.js index ba8427354cbb05..42b436d2a70f62 100644 --- a/Libraries/Components/ProgressViewIOS/RCTProgressViewNativeComponent.js +++ b/Libraries/Components/ProgressViewIOS/RCTProgressViewNativeComponent.js @@ -16,6 +16,7 @@ import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -29,4 +30,6 @@ type NativeProps = $ReadOnly<{| trackImage?: ?ImageSource, |}>; -export default codegenNativeComponent('RCTProgressView'); +export default (codegenNativeComponent( + 'RCTProgressView', +): NativeComponentType); diff --git a/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js b/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js index 4109dae7f8225a..37fd4e67842e75 100644 --- a/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js +++ b/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js @@ -11,6 +11,7 @@ 'use strict'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; import type { DirectEventHandler, @@ -64,4 +65,6 @@ type NativeProps = $ReadOnly<{| refreshing: boolean, |}>; -export default codegenNativeComponent('AndroidSwipeRefreshLayout'); +export default (codegenNativeComponent( + 'AndroidSwipeRefreshLayout', +): NativeComponentType); diff --git a/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js b/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js index 87851403fa2123..24db172eb0c68f 100644 --- a/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js +++ b/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js @@ -15,6 +15,7 @@ import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -43,6 +44,6 @@ type NativeProps = $ReadOnly<{| refreshing: boolean, |}>; -export default codegenNativeComponent('PullToRefreshView', { +export default (codegenNativeComponent('PullToRefreshView', { paperComponentName: 'RCTRefreshControl', -}); +}): NativeComponentType); diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index 773d73d249079a..1313e8e4c12497 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -13,14 +13,14 @@ const Platform = require('../../Utilities/Platform'); const React = require('react'); -import AndroidSwipeRefreshLayoutNativeComponent from './AndroidSwipeRefreshLayoutNativeComponent'; -import PullToRefreshViewNativeComponent from './PullToRefreshViewNativeComponent'; const nullthrows = require('nullthrows'); import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; +import AndroidSwipeRefreshLayoutNativeComponent from './AndroidSwipeRefreshLayoutNativeComponent'; +import PullToRefreshViewNativeComponent from './PullToRefreshViewNativeComponent'; -let RefreshLayoutConsts; +let RefreshLayoutConsts: any; if (Platform.OS === 'android') { const AndroidSwipeRefreshLayout = require('../../ReactNative/UIManager').getViewManagerConfig( 'AndroidSwipeRefreshLayout', @@ -135,7 +135,7 @@ export type RefreshControlProps = $ReadOnly<{| * in the `onRefresh` function otherwise the refresh indicator will stop immediately. */ class RefreshControl extends React.Component { - static SIZE = RefreshLayoutConsts.SIZE; + static SIZE: any = RefreshLayoutConsts.SIZE; _setNativePropsOnRef: ?({refreshing: boolean}) => void; _lastNativeRefreshing = false; @@ -161,7 +161,7 @@ class RefreshControl extends React.Component { } } - render() { + render(): React.Node { const setRef = ref => (this._setNativePropsOnRef = ref ? ref.setNativeProps.bind(ref) : null); if (Platform.OS === 'ios') { diff --git a/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js b/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js index 6d51c187f606cc..bbf4c52307b768 100644 --- a/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js +++ b/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js @@ -14,6 +14,7 @@ import type {ViewProps} from '../View/ViewPropTypes'; import type {WithDefault} from '../../Types/CodegenTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -22,4 +23,6 @@ type NativeProps = $ReadOnly<{| emulateUnlessSupported?: WithDefault, |}>; -export default codegenNativeComponent('RCTSafeAreaView'); +export default (codegenNativeComponent( + 'RCTSafeAreaView', +): NativeComponentType); diff --git a/Libraries/Components/SegmentedControlIOS/RCTSegmentedControlNativeComponent.js b/Libraries/Components/SegmentedControlIOS/RCTSegmentedControlNativeComponent.js index b21f7148824928..4d45a02b363377 100644 --- a/Libraries/Components/SegmentedControlIOS/RCTSegmentedControlNativeComponent.js +++ b/Libraries/Components/SegmentedControlIOS/RCTSegmentedControlNativeComponent.js @@ -10,6 +10,7 @@ 'use strict'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; import type {ViewProps} from '../View/ViewPropTypes'; import type { BubblingEventHandler, @@ -37,4 +38,6 @@ type NativeProps = $ReadOnly<{| onChange?: ?BubblingEventHandler, |}>; -export default codegenNativeComponent('RCTSegmentedControl'); +export default (codegenNativeComponent( + 'RCTSegmentedControl', +): NativeComponentType); diff --git a/Libraries/Components/Slider/SliderNativeComponent.js b/Libraries/Components/Slider/SliderNativeComponent.js index 95e68062362e88..344aae387da4e8 100644 --- a/Libraries/Components/Slider/SliderNativeComponent.js +++ b/Libraries/Components/Slider/SliderNativeComponent.js @@ -18,6 +18,7 @@ import type { } from '../../Types/CodegenTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ImageSource} from '../../Image/ImageSource'; @@ -53,7 +54,7 @@ type NativeProps = $ReadOnly<{| onSlidingComplete?: ?DirectEventHandler, |}>; -export default codegenNativeComponent('Slider', { +export default (codegenNativeComponent('Slider', { interfaceOnly: true, paperComponentName: 'RCTSlider', -}); +}): NativeComponentType); diff --git a/Libraries/Components/Switch/SwitchNativeComponent.js b/Libraries/Components/Switch/SwitchNativeComponent.js index 1315d2addbda0a..7aa7a684ebdbd0 100644 --- a/Libraries/Components/Switch/SwitchNativeComponent.js +++ b/Libraries/Components/Switch/SwitchNativeComponent.js @@ -15,6 +15,7 @@ import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type SwitchChangeEvent = $ReadOnly<{| value: boolean, @@ -39,6 +40,6 @@ type NativeProps = $ReadOnly<{| onChange?: ?BubblingEventHandler, |}>; -export default codegenNativeComponent('Switch', { +export default (codegenNativeComponent('Switch', { paperComponentName: 'RCTSwitch', -}); +}): NativeComponentType); diff --git a/Libraries/Components/TextInput/RCTInputAccessoryViewNativeComponent.js b/Libraries/Components/TextInput/RCTInputAccessoryViewNativeComponent.js index 840ec57ca7fc4d..152615a45e799e 100644 --- a/Libraries/Components/TextInput/RCTInputAccessoryViewNativeComponent.js +++ b/Libraries/Components/TextInput/RCTInputAccessoryViewNativeComponent.js @@ -13,10 +13,13 @@ import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, backgroundColor?: ?ColorValue, |}>; -export default codegenNativeComponent('RCTInputAccessoryView'); +export default (codegenNativeComponent( + 'RCTInputAccessoryView', +): NativeComponentType); diff --git a/Libraries/Components/UnimplementedViews/UnimplementedNativeViewNativeComponent.js b/Libraries/Components/UnimplementedViews/UnimplementedNativeViewNativeComponent.js index f44691bb7bc8ff..cea9d45a2020e5 100644 --- a/Libraries/Components/UnimplementedViews/UnimplementedNativeViewNativeComponent.js +++ b/Libraries/Components/UnimplementedViews/UnimplementedNativeViewNativeComponent.js @@ -14,6 +14,7 @@ import type {WithDefault} from '../../Types/CodegenTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -22,4 +23,6 @@ type NativeProps = $ReadOnly<{| // NOTE: This component is not implemented in paper // Do not require this file in paper builds -export default codegenNativeComponent('UnimplementedNativeView'); +export default (codegenNativeComponent( + 'UnimplementedNativeView', +): NativeComponentType); diff --git a/Libraries/Components/View/ReactNativeViewAttributes.js b/Libraries/Components/View/ReactNativeViewAttributes.js index 92837b4bed1820..c68342a821a658 100644 --- a/Libraries/Components/View/ReactNativeViewAttributes.js +++ b/Libraries/Components/View/ReactNativeViewAttributes.js @@ -12,9 +12,7 @@ const ReactNativeStyleAttributes = require('./ReactNativeStyleAttributes'); -const ReactNativeViewAttributes = {}; - -ReactNativeViewAttributes.UIView = { +const UIView = { pointerEvents: true, accessible: true, accessibilityActions: true, @@ -39,8 +37,8 @@ ReactNativeViewAttributes.UIView = { style: ReactNativeStyleAttributes, }; -ReactNativeViewAttributes.RCTView = { - ...ReactNativeViewAttributes.UIView, +const RCTView = { + ...UIView, // This is a special performance property exposed by RCTView and useful for // scrolling content when there are many subviews, most of which are offscreen. @@ -50,4 +48,9 @@ ReactNativeViewAttributes.RCTView = { removeClippedSubviews: true, }; +const ReactNativeViewAttributes = { + UIView: UIView, + RCTView: RCTView, +}; + module.exports = ReactNativeViewAttributes; diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index f40a7536b37e8d..bd2c26f0e5d7d0 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -11,6 +11,7 @@ 'use strict'; import type {ViewProps} from './ViewPropTypes'; +import type {ViewNativeComponentType} from './ViewNativeComponent'; export type Props = ViewProps; @@ -21,4 +22,5 @@ export type Props = ViewProps; * * @see http://facebook.github.io/react-native/docs/view.html */ -module.exports = require('./ViewNativeComponent').default; +module.exports = (require('./ViewNativeComponent') + .default: ViewNativeComponentType); diff --git a/Libraries/Components/View/ViewNativeComponent.js b/Libraries/Components/View/ViewNativeComponent.js index c5cc06bc729379..6d8408f48f659e 100644 --- a/Libraries/Components/View/ViewNativeComponent.js +++ b/Libraries/Components/View/ViewNativeComponent.js @@ -18,7 +18,9 @@ const requireNativeComponent = require('../../ReactNative/requireNativeComponent import type {ViewProps} from './ViewPropTypes'; -type ViewNativeComponentType = Class>; +export type ViewNativeComponentType = Class< + ReactNative.NativeComponent, +>; let NativeViewComponent; let viewConfig; diff --git a/Libraries/Interaction/InteractionManager.js b/Libraries/Interaction/InteractionManager.js index 69a51b8145ef6a..a8148dd63af7d1 100644 --- a/Libraries/Interaction/InteractionManager.js +++ b/Libraries/Interaction/InteractionManager.js @@ -18,7 +18,7 @@ const infoLog = require('../Utilities/infoLog'); const invariant = require('invariant'); const keyMirror = require('fbjs/lib/keyMirror'); -type Handle = number; +export type Handle = number; import type {Task} from './TaskQueue'; const _emitter = new EventEmitter(); diff --git a/Libraries/Interaction/InteractionMixin.js b/Libraries/Interaction/InteractionMixin.js index 38539b60afe72f..fcbd88f5a1958e 100644 --- a/Libraries/Interaction/InteractionMixin.js +++ b/Libraries/Interaction/InteractionMixin.js @@ -11,6 +11,7 @@ 'use strict'; const InteractionManager = require('./InteractionManager'); +import {type Handle} from './InteractionManager'; /** * This mixin provides safe versions of InteractionManager start/end methods @@ -28,13 +29,13 @@ const InteractionMixin = { _interactionMixinHandles: ([]: Array), - createInteractionHandle: function() { + createInteractionHandle: function(): Handle { const handle = InteractionManager.createInteractionHandle(); this._interactionMixinHandles.push(handle); return handle; }, - clearInteractionHandle: function(clearHandle: number) { + clearInteractionHandle: function(clearHandle: number): void { InteractionManager.clearInteractionHandle(clearHandle); this._interactionMixinHandles = this._interactionMixinHandles.filter( handle => handle !== clearHandle, @@ -46,7 +47,7 @@ const InteractionMixin = { * * @param {function} callback */ - runAfterInteractions: function(callback: Function) { + runAfterInteractions: function(callback: Function): void { InteractionManager.runAfterInteractions(callback); }, }; diff --git a/Libraries/Lists/FillRateHelper.js b/Libraries/Lists/FillRateHelper.js index 8e47c55e2f42aa..b5b006bed29753 100644 --- a/Libraries/Lists/FillRateHelper.js +++ b/Libraries/Lists/FillRateHelper.js @@ -16,16 +16,16 @@ const warning = require('fbjs/lib/warning'); export type FillRateInfo = Info; class Info { - any_blank_count = 0; - any_blank_ms = 0; - any_blank_speed_sum = 0; - mostly_blank_count = 0; - mostly_blank_ms = 0; - pixels_blank = 0; - pixels_sampled = 0; - pixels_scrolled = 0; - total_time_spent = 0; - sample_count = 0; + any_blank_count: number = 0; + any_blank_ms: number = 0; + any_blank_speed_sum: number = 0; + mostly_blank_count: number = 0; + mostly_blank_ms: number = 0; + pixels_blank: number = 0; + pixels_sampled: number = 0; + pixels_scrolled: number = 0; + total_time_spent: number = 0; + sample_count: number = 0; } type FrameMetrics = {inLayout?: boolean, length: number, offset: number}; diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 3722bc1a273557..3afed1ba5a75b7 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -441,13 +441,13 @@ class FlatList extends React.PureComponent, void> { /** * Provides a handle to the underlying scroll responder. */ - getScrollResponder() { + getScrollResponder(): any { if (this._listRef) { return this._listRef.getScrollResponder(); } } - getScrollableNode() { + getScrollableNode(): any { if (this._listRef) { return this._listRef.getScrollableNode(); } @@ -671,7 +671,7 @@ class FlatList extends React.PureComponent, void> { }; }; - render() { + render(): React.Node { return ( > extends React.PureComponent< } } - getScrollableNode() { + getScrollableNode(): any { const listRef = this._wrapperListRef && this._wrapperListRef.getListRef(); if (listRef) { return listRef.getScrollableNode(); @@ -301,7 +301,7 @@ class SectionList> extends React.PureComponent< } } - render() { + render(): React.Node { return ( string, + maxToRenderPerBatch: number, + onEndReachedThreshold: number, + scrollEventThrottle: number, + updateCellsBatchingPeriod: number, + windowSize: number, +|}; + let _usedIndexForKey = false; let _keylessItemComponentName: string = ''; @@ -417,13 +429,13 @@ class VirtualizedList extends React.PureComponent { * Note that `this._scrollRef` might not be a `ScrollView`, so we * need to check that it responds to `getScrollResponder` before calling it. */ - getScrollResponder() { + getScrollResponder(): any { if (this._scrollRef && this._scrollRef.getScrollResponder) { return this._scrollRef.getScrollResponder(); } } - getScrollableNode() { + getScrollableNode(): any { if (this._scrollRef && this._scrollRef.getScrollableNode) { return this._scrollRef.getScrollableNode(); } else { @@ -431,7 +443,7 @@ class VirtualizedList extends React.PureComponent { } } - getScrollRef() { + getScrollRef(): any { if (this._scrollRef && this._scrollRef.getScrollRef) { return this._scrollRef.getScrollRef(); } else { @@ -445,7 +457,7 @@ class VirtualizedList extends React.PureComponent { } } - static defaultProps = { + static defaultProps: DefaultProps = { disableVirtualization: false, horizontal: false, initialNumToRender: 10, @@ -469,7 +481,21 @@ class VirtualizedList extends React.PureComponent { windowSize: 21, // multiples of length }; - static contextTypes = { + static contextTypes: + | any + | {| + virtualizedCell: {| + cellKey: React$PropType$Primitive, + |}, + virtualizedList: {| + getScrollMetrics: React$PropType$Primitive, + horizontal: React$PropType$Primitive, + getOutermostParentListRef: React$PropType$Primitive, + getNestedChildState: React$PropType$Primitive, + registerAsNestedChild: React$PropType$Primitive, + unregisterAsNestedChild: React$PropType$Primitive, + |}, + |} = { virtualizedCell: PropTypes.shape({ cellKey: PropTypes.string, }), @@ -483,7 +509,16 @@ class VirtualizedList extends React.PureComponent { }), }; - static childContextTypes = { + static childContextTypes: + | any + | {| + getScrollMetrics: React$PropType$Primitive, + horizontal: React$PropType$Primitive, + getOutermostParentListRef: React$PropType$Primitive, + getNestedChildState: React$PropType$Primitive, + registerAsNestedChild: React$PropType$Primitive, + unregisterAsNestedChild: React$PropType$Primitive, + |} = { virtualizedList: PropTypes.shape({ getScrollMetrics: PropTypes.func, horizontal: PropTypes.bool, @@ -494,7 +529,31 @@ class VirtualizedList extends React.PureComponent { }), }; - getChildContext() { + getChildContext(): {| + virtualizedList: { + getScrollMetrics: () => { + contentLength: number, + dOffset: number, + dt: number, + offset: number, + timestamp: number, + velocity: number, + visibleLength: number, + }, + horizontal: ?boolean, + getOutermostParentListRef: Function, + getNestedChildState: string => ?ChildListState, + registerAsNestedChild: ({ + cellKey: string, + key: string, + ref: VirtualizedList, + }) => ?ChildListState, + unregisterAsNestedChild: ({ + key: string, + state: ChildListState, + }) => void, + }, + |} { return { virtualizedList: { getScrollMetrics: this._getScrollMetrics, @@ -661,7 +720,7 @@ class VirtualizedList extends React.PureComponent { this._fillRateHelper.deactivateAndFlush(); } - static getDerivedStateFromProps(newProps: Props, prevState: State) { + static getDerivedStateFromProps(newProps: Props, prevState: State): State { const {data, getItemCount, maxToRenderPerBatch} = newProps; // first and last could be stale (e.g. if a new, shorter items props is passed in), so we make // sure we're rendering a reasonable range here. @@ -745,7 +804,7 @@ class VirtualizedList extends React.PureComponent { ); } - render() { + render(): React.Node { if (__DEV__) { const flatStyles = flattenStyle(this.props.contentContainerStyle); warning( diff --git a/Libraries/Lists/VirtualizedSectionList.js b/Libraries/Lists/VirtualizedSectionList.js index ebd12dfad57dc7..f02ba6771cfbdb 100644 --- a/Libraries/Lists/VirtualizedSectionList.js +++ b/Libraries/Lists/VirtualizedSectionList.js @@ -120,9 +120,10 @@ export type Props = RequiredProps & OptionalProps & VirtualizedListProps; -type DefaultProps = typeof VirtualizedList.defaultProps & { +type DefaultProps = {| + ...typeof VirtualizedList.defaultProps, data: $ReadOnlyArray, -}; +|}; type State = {childProps: VirtualizedListProps}; /** @@ -206,7 +207,7 @@ class VirtualizedSectionList< }; } - render() { + render(): React.Node { return ( ); diff --git a/Libraries/Modal/RCTModalHostViewNativeComponent.js b/Libraries/Modal/RCTModalHostViewNativeComponent.js index 688c2e32a93846..0297c3666229d3 100644 --- a/Libraries/Modal/RCTModalHostViewNativeComponent.js +++ b/Libraries/Modal/RCTModalHostViewNativeComponent.js @@ -11,6 +11,7 @@ 'use strict'; import codegenNativeComponent from '../Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../Utilities/codegenNativeComponent'; import type { WithDefault, BubblingEventHandler, @@ -112,7 +113,7 @@ type NativeProps = $ReadOnly<{| identifier?: WithDefault, |}>; -export default codegenNativeComponent('ModalHostView', { +export default (codegenNativeComponent('ModalHostView', { interfaceOnly: true, paperComponentName: 'RCTModalHostView', -}); +}): NativeComponentType); diff --git a/Libraries/NewAppScreen/components/DebugInstructions.js b/Libraries/NewAppScreen/components/DebugInstructions.js index c344a57bd2a008..8000e69ca00705 100644 --- a/Libraries/NewAppScreen/components/DebugInstructions.js +++ b/Libraries/NewAppScreen/components/DebugInstructions.js @@ -8,8 +8,9 @@ * @format */ -import React from 'react'; +import type {Node} from 'react'; import {Platform, StyleSheet, Text} from 'react-native'; +import React from 'react'; const styles = StyleSheet.create({ highlight: { @@ -17,7 +18,7 @@ const styles = StyleSheet.create({ }, }); -const DebugInstructions = Platform.select({ +const DebugInstructions: () => Node = Platform.select({ ios: () => ( Press Cmd + D in the simulator or{' '} diff --git a/Libraries/NewAppScreen/components/Header.js b/Libraries/NewAppScreen/components/Header.js index f1f5cf9f050fd4..06d01101f78658 100644 --- a/Libraries/NewAppScreen/components/Header.js +++ b/Libraries/NewAppScreen/components/Header.js @@ -9,12 +9,12 @@ */ 'use strict'; - -import React from 'react'; -import {Text, StyleSheet, ImageBackground} from 'react-native'; import Colors from './Colors'; +import type {Node} from 'react'; +import {Text, StyleSheet, ImageBackground} from 'react-native'; +import React from 'react'; -const Header = () => ( +const Header = (): Node => ( ( +const LinkList = (): Node => ( {links.map((item, index) => { return ( diff --git a/Libraries/NewAppScreen/components/ReloadInstructions.js b/Libraries/NewAppScreen/components/ReloadInstructions.js index e7fdd2f8bc1b05..320fab549d854e 100644 --- a/Libraries/NewAppScreen/components/ReloadInstructions.js +++ b/Libraries/NewAppScreen/components/ReloadInstructions.js @@ -8,8 +8,9 @@ * @format */ -import React from 'react'; +import type {Node} from 'react'; import {Platform, StyleSheet, Text} from 'react-native'; +import React from 'react'; const styles = StyleSheet.create({ highlight: { @@ -17,7 +18,7 @@ const styles = StyleSheet.create({ }, }); -const ReloadInstructions = Platform.select({ +const ReloadInstructions: () => Node = Platform.select({ ios: () => ( Press Cmd + R in the simulator to diff --git a/Libraries/Utilities/GlobalPerformanceLogger.js b/Libraries/Utilities/GlobalPerformanceLogger.js index ccab5e4685a6de..6b1d9266a4a334 100644 --- a/Libraries/Utilities/GlobalPerformanceLogger.js +++ b/Libraries/Utilities/GlobalPerformanceLogger.js @@ -8,9 +8,10 @@ * @format */ 'use strict'; - const createPerformanceLogger = require('./createPerformanceLogger'); +import type {IPerformanceLogger} from './createPerformanceLogger'; + /** * This is a global shared instance of IPerformanceLogger that is created with * createPerformanceLogger(). @@ -18,6 +19,6 @@ const createPerformanceLogger = require('./createPerformanceLogger'); * that are logged during loading bundle. If you want to log something from your * React component you should use PerformanceLoggerContext instead. */ -const GlobalPerformanceLogger = createPerformanceLogger(); +const GlobalPerformanceLogger: IPerformanceLogger = createPerformanceLogger(); module.exports = GlobalPerformanceLogger; diff --git a/Libraries/Utilities/codegenNativeComponent.js b/Libraries/Utilities/codegenNativeComponent.js index 46aa566df65841..7a39d7a65d40fe 100644 --- a/Libraries/Utilities/codegenNativeComponent.js +++ b/Libraries/Utilities/codegenNativeComponent.js @@ -22,10 +22,12 @@ type Options = $ReadOnly<{| paperComponentNameDeprecated?: string, |}>; +export type NativeComponentType = Class>; + function codegenNativeComponent( componentName: string, options?: Options, -): Class> { +): NativeComponentType { let componentNameInUse = options && options.paperComponentName ? options.paperComponentName diff --git a/Libraries/Utilities/setAndForwardRef.js b/Libraries/Utilities/setAndForwardRef.js index cf32c492005107..ba1a18b41d03b5 100644 --- a/Libraries/Utilities/setAndForwardRef.js +++ b/Libraries/Utilities/setAndForwardRef.js @@ -48,7 +48,10 @@ type Args = $ReadOnly<{| * module.exports = MyViewWithRef; */ -function setAndForwardRef({getForwardedRef, setLocalRef}: Args) { +function setAndForwardRef({ + getForwardedRef, + setLocalRef, +}: Args): (ref: ElementRef) => void { return function forwardRef(ref: ElementRef) { const forwardedRef = getForwardedRef(); diff --git a/Libraries/YellowBox/YellowBox.js b/Libraries/YellowBox/YellowBox.js index feb27f5faffe93..d94e23b50c359b 100644 --- a/Libraries/YellowBox/YellowBox.js +++ b/Libraries/YellowBox/YellowBox.js @@ -138,7 +138,7 @@ if (__DEV__) { YellowBoxRegistry.add({args, framesToPop: 2}); }; } else { - YellowBox = class extends React.Component { + YellowBox = class extends React.Component { static ignoreWarnings(patterns: $ReadOnlyArray): void { // Do nothing. } @@ -157,4 +157,8 @@ if (__DEV__) { }; } -module.exports = YellowBox; +module.exports = (YellowBox: Class> & { + ignoreWarnings($ReadOnlyArray): void, + install(): void, + uninstall(): void, +}); diff --git a/Libraries/vendor/emitter/EventValidator.js b/Libraries/vendor/emitter/EventValidator.js index 39bf3147bdfa48..429cc636237715 100644 --- a/Libraries/vendor/emitter/EventValidator.js +++ b/Libraries/vendor/emitter/EventValidator.js @@ -30,7 +30,7 @@ const EventValidator = { * const types = {someEvent: true, anotherEvent: true}; * const emitter = EventValidator.addValidation(emitter, types); */ - addValidation: function(emitter: Object, types: Object) { + addValidation: function(emitter: Object, types: Object): {emit: any => any} { const eventTypes = Object.keys(types); const emitterWithValidation = Object.create(emitter); diff --git a/RNTester/js/components/RNTesterSettingSwitchRow.js b/RNTester/js/components/RNTesterSettingSwitchRow.js index 983ff5f4fe0d69..fafcf7a5ffb722 100644 --- a/RNTester/js/components/RNTesterSettingSwitchRow.js +++ b/RNTester/js/components/RNTesterSettingSwitchRow.js @@ -10,21 +10,22 @@ 'use strict'; +const RNTesterStatePersister = require('../utils/RNTesterStatePersister'); const React = require('react'); + const {StyleSheet, Switch, Text, View} = require('react-native'); -const RNTesterStatePersister = require('../utils/RNTesterStatePersister'); class RNTesterSettingSwitchRow extends React.Component< $FlowFixMeProps, $FlowFixMeState, > { - UNSAFE_componentWillReceiveProps(newProps) { + UNSAFE_componentWillReceiveProps(newProps: $FlowFixMeProps) { const {onEnable, onDisable, persister} = this.props; if (newProps.persister.state !== persister.state) { newProps.persister.state ? onEnable() : onDisable(); } } - render() { + render(): React.Node { const {label, persister} = this.props; return ( diff --git a/RNTester/js/examples/PanResponder/PanResponderExample.js b/RNTester/js/examples/PanResponder/PanResponderExample.js index c768c8daf161ce..8b6d75a35e8cce 100644 --- a/RNTester/js/examples/PanResponder/PanResponderExample.js +++ b/RNTester/js/examples/PanResponder/PanResponderExample.js @@ -109,7 +109,7 @@ class PanResponderExample extends React.Component { this.circle && this.circle.setNativeProps(this._circleStyles); } - render() { + render(): React.Node { return ( ; class SnapshotViewIOS extends React.Component { - onDefaultAction = (event: SnapshotReadyEvent) => { + onDefaultAction: (event: SnapshotReadyEvent) => void = ( + event: SnapshotReadyEvent, + ) => { TestModule.verifySnapshot(TestModule.markTestPassed); }; - render() { + render(): React.Node { const testIdentifier = this.props.testIdentifier || 'test'; const onSnapshotReady = this.props.onSnapshotReady || this.onDefaultAction; return ( diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js index 60307e99353417..bf0fa17bd1ebe5 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js @@ -22,6 +22,7 @@ import type { } 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 NativeProps = $ReadOnly<{| ...ViewProps, @@ -37,4 +38,6 @@ type NativeProps = $ReadOnly<{| sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>, |}>; -export default codegenNativeComponent('ArrayPropsNativeComponent'); +export default (codegenNativeComponent( + 'ArrayPropsNativeComponent', +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/BooleanPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/BooleanPropNativeComponent.js index 2c6ad0a837e93e..2df67f38f041ca 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/BooleanPropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/BooleanPropNativeComponent.js @@ -13,6 +13,7 @@ import type {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 NativeProps = $ReadOnly<{| ...ViewProps, @@ -21,6 +22,6 @@ type NativeProps = $ReadOnly<{| disabled?: WithDefault, |}>; -export default codegenNativeComponent( +export default (codegenNativeComponent( 'BooleanPropNativeComponent', -); +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/ColorPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/ColorPropNativeComponent.js index 3850dcaf63cd5a..1a8c263ccfbf0b 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/ColorPropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/ColorPropNativeComponent.js @@ -13,6 +13,7 @@ import type {ColorValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../../../../Libraries/Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -21,4 +22,6 @@ type NativeProps = $ReadOnly<{| tintColor?: ColorValue, |}>; -export default codegenNativeComponent('ColorPropNativeComponent'); +export default (codegenNativeComponent( + 'ColorPropNativeComponent', +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/EnumPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/EnumPropNativeComponent.js index 3d38f07385ee6a..5a4ad2d5ac8088 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/EnumPropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/EnumPropNativeComponent.js @@ -13,6 +13,7 @@ import type {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 NativeProps = $ReadOnly<{| ...ViewProps, @@ -21,4 +22,6 @@ type NativeProps = $ReadOnly<{| alignment?: WithDefault<'top' | 'center' | 'bottom-right', 'center'>, |}>; -export default codegenNativeComponent('EnumPropNativeComponent'); +export default (codegenNativeComponent( + 'EnumPropNativeComponent', +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js index 1a0f2030e39958..ed93e3ffcfcce5 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js @@ -17,6 +17,7 @@ import type { } 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 OnChangeEvent = $ReadOnly<{| location: { @@ -38,6 +39,6 @@ type NativeProps = $ReadOnly<{| onChange?: ?BubblingEventHandler, |}>; -export default codegenNativeComponent( +export default (codegenNativeComponent( 'EventNestedObjectPropsNativeComponent', -); +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/EventPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/EventPropsNativeComponent.js index 65193c341e96b8..406381cfb15c6b 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/EventPropsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/EventPropsNativeComponent.js @@ -19,6 +19,7 @@ import type { } 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 OnChangeEvent = $ReadOnly<{| value: boolean, @@ -59,4 +60,6 @@ type NativeProps = $ReadOnly<{| >, |}>; -export default codegenNativeComponent('EventPropsNativeComponent'); +export default (codegenNativeComponent( + 'EventPropsNativeComponent', +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/FloatPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/FloatPropsNativeComponent.js index 7675e856c05d0a..5e72e470ee00d5 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/FloatPropsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/FloatPropsNativeComponent.js @@ -16,6 +16,7 @@ import type { } 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 NativeProps = $ReadOnly<{| ...ViewProps, @@ -29,4 +30,6 @@ type NativeProps = $ReadOnly<{| blurRadius6?: WithDefault, |}>; -export default codegenNativeComponent('FloatPropsNativeComponent'); +export default (codegenNativeComponent( + 'FloatPropsNativeComponent', +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/ImagePropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/ImagePropNativeComponent.js index cb6793910fc489..2ed439a0fab2b7 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/ImagePropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/ImagePropNativeComponent.js @@ -13,6 +13,7 @@ import type {ImageSource} from '../../../../../Libraries/Image/ImageSource'; import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../../../../Libraries/Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -21,4 +22,6 @@ type NativeProps = $ReadOnly<{| thumbImage?: ImageSource, |}>; -export default codegenNativeComponent('ImagePropNativeComponent'); +export default (codegenNativeComponent( + 'ImagePropNativeComponent', +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/IntegerPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/IntegerPropNativeComponent.js index b21576ffb7dd2f..efb1c901844fc2 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/IntegerPropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/IntegerPropNativeComponent.js @@ -16,6 +16,7 @@ import type { } 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 NativeProps = $ReadOnly<{| ...ViewProps, @@ -26,6 +27,6 @@ type NativeProps = $ReadOnly<{| progress3?: WithDefault, |}>; -export default codegenNativeComponent( +export default (codegenNativeComponent( 'IntegerPropNativeComponent', -); +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/InterfaceOnlyNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/InterfaceOnlyNativeComponent.js index 3bdce224efa5d2..9433c1e33e37f2 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/InterfaceOnlyNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/InterfaceOnlyNativeComponent.js @@ -16,6 +16,7 @@ import type { } 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 NativeProps = $ReadOnly<{| ...ViewProps, @@ -27,10 +28,10 @@ type NativeProps = $ReadOnly<{| onChange?: ?BubblingEventHandler<$ReadOnly<{|value: boolean|}>>, |}>; -export default codegenNativeComponent( +export default (codegenNativeComponent( 'InterfaceOnlyNativeComponent', { interfaceOnly: true, paperComponentName: 'RCTInterfaceOnlyComponent', }, -); +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/MultiNativePropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/MultiNativePropNativeComponent.js index dc8bb46a34c694..a495f01adeee0a 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/MultiNativePropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/MultiNativePropNativeComponent.js @@ -17,6 +17,7 @@ import type { import type {ImageSource} from '../../../../../Libraries/Image/ImageSource'; import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../../../../Libraries/Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -28,6 +29,6 @@ type NativeProps = $ReadOnly<{| point?: PointValue, |}>; -export default codegenNativeComponent( +export default (codegenNativeComponent( 'MultiNativePropNativeComponent', -); +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/NoPropsNoEventsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/NoPropsNoEventsNativeComponent.js index 5d75b6e3b59fc4..5e7cb39f407299 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/NoPropsNoEventsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/NoPropsNoEventsNativeComponent.js @@ -12,6 +12,7 @@ import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../../../../Libraries/Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -19,6 +20,6 @@ type NativeProps = $ReadOnly<{| // No Props or events |}>; -export default codegenNativeComponent( +export default (codegenNativeComponent( 'NoPropsNoEventsNativeComponent', -); +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/PointPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/PointPropNativeComponent.js index fdf3861e68ae6c..62bf4d2185f8d1 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/PointPropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/PointPropNativeComponent.js @@ -13,6 +13,7 @@ import type {PointValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent'; +import {type NativeComponentType} from '../../../../../Libraries/Utilities/codegenNativeComponent'; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -21,4 +22,6 @@ type NativeProps = $ReadOnly<{| startPoint?: PointValue, |}>; -export default codegenNativeComponent('PointPropNativeComponent'); +export default (codegenNativeComponent( + 'PointPropNativeComponent', +): NativeComponentType); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/StringPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/StringPropNativeComponent.js index b15debb6f27ccf..3a293470390249 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/StringPropNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/StringPropNativeComponent.js @@ -13,6 +13,7 @@ import type {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 NativeProps = $ReadOnly<{| ...ViewProps, @@ -22,4 +23,6 @@ type NativeProps = $ReadOnly<{| accessibilityRole?: string, |}>; -export default codegenNativeComponent('StringPropNativeComponent'); +export default (codegenNativeComponent( + 'StringPropNativeComponent', +): NativeComponentType); diff --git a/template/App.js b/template/App.js index 0fc721ae567367..bb77580955e70d 100644 --- a/template/App.js +++ b/template/App.js @@ -24,7 +24,7 @@ import { ReloadInstructions, } from 'react-native/Libraries/NewAppScreen'; -const App = () => { +const App: () => React$Node = () => { return ( <>