Skip to content

Commit

Permalink
xplat/js/react-native-github
Browse files Browse the repository at this point in the history
Reviewed By: panagosg7

Differential Revision: D16657770

fbshipit-source-id: 4e260842c838a35317515044c54ccf55a083da33
  • Loading branch information
logandaniels authored and facebook-github-bot committed Aug 9, 2019
1 parent 9127fb5 commit 91f139b
Show file tree
Hide file tree
Showing 251 changed files with 1,479 additions and 973 deletions.
4 changes: 2 additions & 2 deletions IntegrationTests/AppEventsTest.js
Expand Up @@ -36,7 +36,7 @@ class AppEventsTest extends React.Component<{}, State> {
this.setState({sent: event});
}

receiveEvent = (event: any) => {
receiveEvent: (event: any) => void = (event: any) => {
if (deepDiffer(event.data, TEST_PAYLOAD)) {
throw new Error('Received wrong event: ' + JSON.stringify(event));
}
Expand All @@ -46,7 +46,7 @@ class AppEventsTest extends React.Component<{}, State> {
});
};

render() {
render(): React.Node {
return (
<View style={styles.container}>
<Text>{JSON.stringify(this.state, null, ' ')}</Text>
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/AsyncStorageTest.js
Expand Up @@ -172,7 +172,7 @@ function testOptimizedMultiGet() {
}

class AsyncStorageTest extends React.Component<{}, $FlowFixMeState> {
state = {
state: any | $TEMPORARY$object<{|done: boolean, messages: string|}> = {
messages: 'Initializing...',
done: false,
};
Expand All @@ -189,7 +189,7 @@ class AsyncStorageTest extends React.Component<{}, $FlowFixMeState> {
AsyncStorage.clear(testSetAndGet);
}

render() {
render(): React.Node {
return (
<View style={styles.container}>
<Text>
Expand Down
6 changes: 3 additions & 3 deletions IntegrationTests/ImageCachePolicyTest.js
Expand Up @@ -36,9 +36,9 @@ type State = {
};

class ImageCachePolicyTest extends React.Component<Props, $FlowFixMeState> {
state = {};
state: $FlowFixMe | $TEMPORARY$object<{||}> = {};

shouldComponentUpdate(nextProps: Props, nextState: State) {
shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
const results: Array<?boolean> = TESTS.map(x => nextState[x]);

if (!results.includes(undefined)) {
Expand All @@ -56,7 +56,7 @@ class ImageCachePolicyTest extends React.Component<Props, $FlowFixMeState> {
this.setState({[name]: pass});
}

render() {
render(): React.Node {
return (
<View style={styles.container}>
<Text>Hello</Text>
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/ImageSnapshotTest.js
Expand Up @@ -22,11 +22,11 @@ class ImageSnapshotTest extends React.Component<{}> {
}
}

done = (success: boolean) => {
done: (success: boolean) => void = (success: boolean) => {
TestModule.markTestPassed(success);
};

render() {
render(): React.Node {
return (
<Image
source={require('./blue_square.png')}
Expand Down
9 changes: 5 additions & 4 deletions IntegrationTests/IntegrationTestHarnessTest.js
Expand Up @@ -10,9 +10,10 @@

'use strict';

const requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
const React = require('react');
const ReactNative = require('react-native');

const requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
const {Text, View, StyleSheet} = ReactNative;
const {TestModule} = ReactNative.NativeModules;

Expand All @@ -26,7 +27,7 @@ type State = {|
|};

class IntegrationTestHarnessTest extends React.Component<Props, State> {
state = {
state: State = {
done: false,
};

Expand All @@ -38,7 +39,7 @@ class IntegrationTestHarnessTest extends React.Component<Props, State> {
}
}

runTest = () => {
runTest: () => void = () => {
if (this.props.shouldThrow) {
throw new Error('Throwing error because shouldThrow');
}
Expand All @@ -52,7 +53,7 @@ class IntegrationTestHarnessTest extends React.Component<Props, State> {
});
};

render() {
render(): React.Node {
return (
<View style={styles.container}>
<Text>
Expand Down
14 changes: 7 additions & 7 deletions IntegrationTests/LayoutEventsTest.js
Expand Up @@ -58,22 +58,22 @@ class LayoutEventsTest extends React.Component<Props, State> {
this.setState({viewStyle: {margin: 60}});
}

addWrapText = () => {
addWrapText: () => void = () => {
debug('addWrapText invoked');
this.setState(
{extraText: ' And a bunch more text to wrap around a few lines.'},
() => this.checkLayout(this.changeContainer),
);
};

changeContainer = () => {
changeContainer: () => void = () => {
debug('changeContainer invoked');
this.setState({containerStyle: {width: 280}}, () =>
this.checkLayout(TestModule.markTestCompleted),
);
};

checkLayout = (next?: ?() => void) => {
checkLayout: (next?: ?() => void) => void = (next?: ?() => void) => {
const view = this._view;
const txt = this._txt;
const img = this._img;
Expand Down Expand Up @@ -117,22 +117,22 @@ class LayoutEventsTest extends React.Component<Props, State> {
}
}

onViewLayout = (e: LayoutEvent) => {
onViewLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
debug('received view layout event\n', e.nativeEvent);
this.setState({viewLayout: e.nativeEvent.layout}, this.checkLayout);
};

onTextLayout = (e: LayoutEvent) => {
onTextLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
debug('received text layout event\n', e.nativeEvent);
this.setState({textLayout: e.nativeEvent.layout}, this.checkLayout);
};

onImageLayout = (e: LayoutEvent) => {
onImageLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
debug('received image layout event\n', e.nativeEvent);
this.setState({imageLayout: e.nativeEvent.layout}, this.checkLayout);
};

render() {
render(): React.Node {
const viewStyle = [styles.view, this.state.viewStyle];
const textLayout = this.state.textLayout || {width: '?', height: '?'};
const imageLayout = this.state.imageLayout || {x: '?', y: '?'};
Expand Down
16 changes: 8 additions & 8 deletions IntegrationTests/PromiseTest.js
Expand Up @@ -16,10 +16,10 @@ const {View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;

class PromiseTest extends React.Component<{}> {
shouldResolve = false;
shouldReject = false;
shouldSucceedAsync = false;
shouldThrowAsync = false;
shouldResolve: boolean = false;
shouldReject: boolean = false;
shouldSucceedAsync: boolean = false;
shouldThrowAsync: boolean = false;

componentDidMount() {
Promise.all([
Expand All @@ -37,19 +37,19 @@ class PromiseTest extends React.Component<{}> {
);
}

testShouldResolve = () => {
testShouldResolve: () => any = () => {
return TestModule.shouldResolve()
.then(() => (this.shouldResolve = true))
.catch(() => (this.shouldResolve = false));
};

testShouldReject = () => {
testShouldReject: () => any = () => {
return TestModule.shouldReject()
.then(() => (this.shouldReject = false))
.catch(() => (this.shouldReject = true));
};

testShouldSucceedAsync = async (): Promise<any> => {
testShouldSucceedAsync: () => Promise<any> = async (): Promise<any> => {
try {
await TestModule.shouldResolve();
this.shouldSucceedAsync = true;
Expand All @@ -58,7 +58,7 @@ class PromiseTest extends React.Component<{}> {
}
};

testShouldThrowAsync = async (): Promise<any> => {
testShouldThrowAsync: () => Promise<any> = async (): Promise<any> => {
try {
await TestModule.shouldReject();
this.shouldThrowAsync = false;
Expand Down
10 changes: 6 additions & 4 deletions IntegrationTests/ReactContentSizeUpdateTest.js
Expand Up @@ -10,9 +10,9 @@

'use strict';

const RCTNativeAppEventEmitter = require('react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter');
const React = require('react');
const ReactNative = require('react-native');
const RCTNativeAppEventEmitter = require('react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter');

const {View} = ReactNative;

Expand All @@ -35,7 +35,7 @@ class ReactContentSizeUpdateTest extends React.Component<Props, State> {
_timeoutID: ?TimeoutID = null;
_subscription: ?EmitterSubscription = null;

state = {
state: State = {
height: reactViewHeight,
width: reactViewWidth,
};
Expand Down Expand Up @@ -70,7 +70,9 @@ class ReactContentSizeUpdateTest extends React.Component<Props, State> {
});
}

rootViewDidChangeIntrinsicSize = (intrinsicSize: State) => {
rootViewDidChangeIntrinsicSize: (intrinsicSize: State) => void = (
intrinsicSize: State,
) => {
if (
intrinsicSize.height === newReactViewHeight &&
intrinsicSize.width === newReactViewWidth
Expand All @@ -79,7 +81,7 @@ class ReactContentSizeUpdateTest extends React.Component<Props, State> {
}
};

render() {
render(): React.Node {
return (
<View style={{height: this.state.height, width: this.state.width}} />
);
Expand Down
5 changes: 3 additions & 2 deletions IntegrationTests/SimpleSnapshotTest.js
Expand Up @@ -12,6 +12,7 @@

const React = require('react');
const ReactNative = require('react-native');

const requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');

const {StyleSheet, View} = ReactNative;
Expand All @@ -25,11 +26,11 @@ class SimpleSnapshotTest extends React.Component<{}> {
requestAnimationFrame(() => TestModule.verifySnapshot(this.done));
}

done = (success: boolean) => {
done: (success: boolean) => void = (success: boolean) => {
TestModule.markTestPassed(success);
};

render() {
render(): React.Node {
return (
<View style={styles.container}>
<View style={styles.box1} />
Expand Down
12 changes: 6 additions & 6 deletions IntegrationTests/SizeFlexibilityUpdateTest.js
Expand Up @@ -10,9 +10,9 @@

'use strict';

const RCTNativeAppEventEmitter = require('react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter');
const React = require('react');
const ReactNative = require('react-native');
const RCTNativeAppEventEmitter = require('react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter');
const {View} = ReactNative;

const {TestModule} = ReactNative.NativeModules;
Expand Down Expand Up @@ -46,15 +46,15 @@ class SizeFlexibilityUpdateTest extends React.Component<Props> {
}
}

markPassed = () => {
markPassed: () => void = () => {
TestModule.markTestPassed(true);
finalState = true;
};

rootViewDidChangeIntrinsicSize = (intrinsicSize: {
width: number,
rootViewDidChangeIntrinsicSize: (intrinsicSize: {
height: number,
}) => {
width: number,
}) => void = (intrinsicSize: {width: number, height: number}) => {
if (finalState) {
// If a test reaches its final state, it is not expected to do anything more
TestModule.markTestPassed(false);
Expand Down Expand Up @@ -99,7 +99,7 @@ class SizeFlexibilityUpdateTest extends React.Component<Props> {
}
};

render() {
render(): React.Node {
return <View style={{height: reactViewHeight, width: reactViewWidth}} />;
}
}
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/TimersTest.js
Expand Up @@ -33,7 +33,7 @@ class TimersTest extends React.Component<Props, State> {
_immediateIDs: Set<ImmediateID> = new Set();
_animationFrameIDs: Set<AnimationFrameID> = new Set();

state = {
state: State = {
count: 0,
done: false,
};
Expand Down Expand Up @@ -228,7 +228,7 @@ class TimersTest extends React.Component<Props, State> {
}
}

render() {
render(): React.Node {
return (
<View style={styles.container}>
<Text>
Expand Down
6 changes: 3 additions & 3 deletions IntegrationTests/WebSocketTest.js
Expand Up @@ -113,7 +113,7 @@ class WebSocketTest extends React.Component<{}, State> {
this.testConnect();
}

testConnect = () => {
testConnect: () => void = () => {
this._connect();
this._waitFor(this._socketIsConnected, 5, connectSucceeded => {
if (!connectSucceeded) {
Expand All @@ -124,7 +124,7 @@ class WebSocketTest extends React.Component<{}, State> {
});
};

testSendAndReceive = () => {
testSendAndReceive: () => void = () => {
this._sendTestMessage();
this._waitFor(this._receivedTestExpectedResponse, 5, messageReceived => {
if (!messageReceived) {
Expand All @@ -135,7 +135,7 @@ class WebSocketTest extends React.Component<{}, State> {
});
};

testDisconnect = () => {
testDisconnect: () => void = () => {
this._disconnect();
this._waitFor(this._socketIsDisconnected, 5, disconnectSucceeded => {
TestModule.markTestPassed(disconnectSucceeded);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/ActionSheetIOS/NativeActionSheetManager.js
Expand Up @@ -47,4 +47,4 @@ export interface Spec extends TurboModule {
) => void;
}

export default TurboModuleRegistry.get<Spec>('ActionSheetManager');
export default (TurboModuleRegistry.get<Spec>('ActionSheetManager'): ?Spec);
2 changes: 1 addition & 1 deletion Libraries/Alert/NativeAlertManager.js
Expand Up @@ -31,4 +31,4 @@ export interface Spec extends TurboModule {
) => void;
}

export default TurboModuleRegistry.get<Spec>('AlertManager');
export default (TurboModuleRegistry.get<Spec>('AlertManager'): ?Spec);
5 changes: 3 additions & 2 deletions Libraries/Animated/src/AnimatedEvent.js
Expand Up @@ -14,6 +14,7 @@ const NativeAnimatedHelper = require('./NativeAnimatedHelper');
const ReactNative = require('../../Renderer/shims/ReactNative');

const invariant = require('invariant');

const {shouldUseNativeDriver} = require('./NativeAnimatedHelper');

export type Mapping = {[key: string]: Mapping} | AnimatedValue;
Expand All @@ -26,7 +27,7 @@ function attachNativeEvent(
viewRef: any,
eventName: string,
argMapping: Array<?Mapping>,
) {
): $TEMPORARY$object<{|detach: () => void|}> {
// Find animated values in `argMapping` and create an array representing their
// key path inside the `nativeEvent` object. Ex.: ['contentOffset', 'x'].
const eventMappings = [];
Expand Down Expand Up @@ -130,7 +131,7 @@ class AnimatedEvent {
this._attachedEvent && this._attachedEvent.detach();
}

__getHandler() {
__getHandler(): any | ((...args: any) => void) {
if (this.__isNative) {
return this._callListeners;
}
Expand Down

0 comments on commit 91f139b

Please sign in to comment.