Skip to content

Commit

Permalink
Manual fixes for xplat/js/react-native-github
Browse files Browse the repository at this point in the history
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
  • Loading branch information
logandaniels authored and facebook-github-bot committed Aug 9, 2019
1 parent 99487d6 commit 9127fb5
Show file tree
Hide file tree
Showing 55 changed files with 270 additions and 122 deletions.
23 changes: 13 additions & 10 deletions Libraries/Animated/src/Animated.js
Expand Up @@ -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,
};
2 changes: 1 addition & 1 deletion Libraries/Animated/src/AnimatedMock.js
Expand Up @@ -110,7 +110,7 @@ const stagger = function(
return emptyAnimation;
};

type LoopAnimationConfig = {iterations: number};
type LoopAnimationConfig = {iterations: number, resetBeforeIteration?: boolean};

const loop = function(
animation: CompositeAnimation,
Expand Down
6 changes: 4 additions & 2 deletions Libraries/Animated/src/nodes/AnimatedInterpolation.js
Expand Up @@ -307,7 +307,9 @@ function checkInfiniteRange(name: string, arr: Array<number>) {

class AnimatedInterpolation extends AnimatedWithChildren {
// Export for testing.
static __createInterpolation = createInterpolation;
static __createInterpolation: (
config: InterpolationConfigType,
) => (input: number) => number | string = createInterpolation;

_parent: AnimatedNode;
_config: InterpolationConfigType;
Expand Down Expand Up @@ -347,7 +349,7 @@ class AnimatedInterpolation extends AnimatedWithChildren {
super.__detach();
}

__transformDataType(range: Array<any>) {
__transformDataType(range: Array<any>): Array<any> {
return range.map(NativeAnimatedHelper.transformDataType);
}

Expand Down
Expand Up @@ -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,
Expand Down Expand Up @@ -50,6 +51,6 @@ type NativeProps = $ReadOnly<{|
size?: WithDefault<'small' | 'large', 'small'>,
|}>;

export default codegenNativeComponent<NativeProps>('ActivityIndicatorView', {
export default (codegenNativeComponent<NativeProps>('ActivityIndicatorView', {
paperComponentName: 'RCTActivityIndicatorView',
});
}): NativeComponentType<NativeProps>);
2 changes: 1 addition & 1 deletion Libraries/Components/Button.js
Expand Up @@ -128,7 +128,7 @@ type ButtonProps = $ReadOnly<{|
*/

class Button extends React.Component<ButtonProps> {
render() {
render(): React.Node {
const {
accessibilityLabel,
color,
Expand Down
Expand Up @@ -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<NativeProps>('RCTMaskedView');
export default (codegenNativeComponent<NativeProps>(
'RCTMaskedView',
): NativeComponentType<NativeProps>);
Expand Up @@ -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,
Expand All @@ -29,4 +30,6 @@ type NativeProps = $ReadOnly<{|
testID?: WithDefault<string, ''>,
|}>;

export default codegenNativeComponent<NativeProps>('AndroidProgressBar');
export default (codegenNativeComponent<NativeProps>(
'AndroidProgressBar',
): NativeComponentType<NativeProps>);
Expand Up @@ -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,
Expand All @@ -29,4 +30,6 @@ type NativeProps = $ReadOnly<{|
trackImage?: ?ImageSource,
|}>;

export default codegenNativeComponent<NativeProps>('RCTProgressView');
export default (codegenNativeComponent<NativeProps>(
'RCTProgressView',
): NativeComponentType<NativeProps>);
Expand Up @@ -11,6 +11,7 @@
'use strict';

import codegenNativeComponent from '../../Utilities/codegenNativeComponent';
import {type NativeComponentType} from '../../Utilities/codegenNativeComponent';

import type {
DirectEventHandler,
Expand Down Expand Up @@ -64,4 +65,6 @@ type NativeProps = $ReadOnly<{|
refreshing: boolean,
|}>;

export default codegenNativeComponent<NativeProps>('AndroidSwipeRefreshLayout');
export default (codegenNativeComponent<NativeProps>(
'AndroidSwipeRefreshLayout',
): NativeComponentType<NativeProps>);
Expand Up @@ -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,
Expand Down Expand Up @@ -43,6 +44,6 @@ type NativeProps = $ReadOnly<{|
refreshing: boolean,
|}>;

export default codegenNativeComponent<NativeProps>('PullToRefreshView', {
export default (codegenNativeComponent<NativeProps>('PullToRefreshView', {
paperComponentName: 'RCTRefreshControl',
});
}): NativeComponentType<NativeProps>);
10 changes: 5 additions & 5 deletions Libraries/Components/RefreshControl/RefreshControl.js
Expand Up @@ -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',
Expand Down Expand Up @@ -135,7 +135,7 @@ export type RefreshControlProps = $ReadOnly<{|
* in the `onRefresh` function otherwise the refresh indicator will stop immediately.
*/
class RefreshControl extends React.Component<RefreshControlProps> {
static SIZE = RefreshLayoutConsts.SIZE;
static SIZE: any = RefreshLayoutConsts.SIZE;

_setNativePropsOnRef: ?({refreshing: boolean}) => void;
_lastNativeRefreshing = false;
Expand All @@ -161,7 +161,7 @@ class RefreshControl extends React.Component<RefreshControlProps> {
}
}

render() {
render(): React.Node {
const setRef = ref =>
(this._setNativePropsOnRef = ref ? ref.setNativeProps.bind(ref) : null);
if (Platform.OS === 'ios') {
Expand Down
Expand Up @@ -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,
Expand All @@ -22,4 +23,6 @@ type NativeProps = $ReadOnly<{|
emulateUnlessSupported?: WithDefault<boolean, false>,
|}>;

export default codegenNativeComponent<NativeProps>('RCTSafeAreaView');
export default (codegenNativeComponent<NativeProps>(
'RCTSafeAreaView',
): NativeComponentType<NativeProps>);
Expand Up @@ -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,
Expand Down Expand Up @@ -37,4 +38,6 @@ type NativeProps = $ReadOnly<{|
onChange?: ?BubblingEventHandler<OnChangeEvent>,
|}>;

export default codegenNativeComponent<NativeProps>('RCTSegmentedControl');
export default (codegenNativeComponent<NativeProps>(
'RCTSegmentedControl',
): NativeComponentType<NativeProps>);
5 changes: 3 additions & 2 deletions Libraries/Components/Slider/SliderNativeComponent.js
Expand Up @@ -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';
Expand Down Expand Up @@ -53,7 +54,7 @@ type NativeProps = $ReadOnly<{|
onSlidingComplete?: ?DirectEventHandler<Event, 'paperSlidingComplete'>,
|}>;

export default codegenNativeComponent<NativeProps>('Slider', {
export default (codegenNativeComponent<NativeProps>('Slider', {
interfaceOnly: true,
paperComponentName: 'RCTSlider',
});
}): NativeComponentType<NativeProps>);
5 changes: 3 additions & 2 deletions Libraries/Components/Switch/SwitchNativeComponent.js
Expand Up @@ -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,
Expand All @@ -39,6 +40,6 @@ type NativeProps = $ReadOnly<{|
onChange?: ?BubblingEventHandler<SwitchChangeEvent>,
|}>;

export default codegenNativeComponent<NativeProps>('Switch', {
export default (codegenNativeComponent<NativeProps>('Switch', {
paperComponentName: 'RCTSwitch',
});
}): NativeComponentType<NativeProps>);
Expand Up @@ -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<NativeProps>('RCTInputAccessoryView');
export default (codegenNativeComponent<NativeProps>(
'RCTInputAccessoryView',
): NativeComponentType<NativeProps>);
Expand Up @@ -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,
Expand All @@ -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<NativeProps>('UnimplementedNativeView');
export default (codegenNativeComponent<NativeProps>(
'UnimplementedNativeView',
): NativeComponentType<NativeProps>);
13 changes: 8 additions & 5 deletions Libraries/Components/View/ReactNativeViewAttributes.js
Expand Up @@ -12,9 +12,7 @@

const ReactNativeStyleAttributes = require('./ReactNativeStyleAttributes');

const ReactNativeViewAttributes = {};

ReactNativeViewAttributes.UIView = {
const UIView = {
pointerEvents: true,
accessible: true,
accessibilityActions: true,
Expand All @@ -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.
Expand All @@ -50,4 +48,9 @@ ReactNativeViewAttributes.RCTView = {
removeClippedSubviews: true,
};

const ReactNativeViewAttributes = {
UIView: UIView,
RCTView: RCTView,
};

module.exports = ReactNativeViewAttributes;
4 changes: 3 additions & 1 deletion Libraries/Components/View/View.js
Expand Up @@ -11,6 +11,7 @@
'use strict';

import type {ViewProps} from './ViewPropTypes';
import type {ViewNativeComponentType} from './ViewNativeComponent';

export type Props = ViewProps;

Expand All @@ -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);
4 changes: 3 additions & 1 deletion Libraries/Components/View/ViewNativeComponent.js
Expand Up @@ -18,7 +18,9 @@ const requireNativeComponent = require('../../ReactNative/requireNativeComponent

import type {ViewProps} from './ViewPropTypes';

type ViewNativeComponentType = Class<ReactNative.NativeComponent<ViewProps>>;
export type ViewNativeComponentType = Class<
ReactNative.NativeComponent<ViewProps>,
>;

let NativeViewComponent;
let viewConfig;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Interaction/InteractionManager.js
Expand Up @@ -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();
Expand Down

0 comments on commit 9127fb5

Please sign in to comment.