diff --git a/ReactAndroid/src/androidTest/js/UIManagerTestModule.js b/ReactAndroid/src/androidTest/js/UIManagerTestModule.js index 9cfefe8cd..9690f6fce 100644 --- a/ReactAndroid/src/androidTest/js/UIManagerTestModule.js +++ b/ReactAndroid/src/androidTest/js/UIManagerTestModule.js @@ -5,220 +5,270 @@ * LICENSE file in the root directory of this source tree. * * @format + * @flow */ 'use strict'; -var BatchedBridge = require('BatchedBridge'); -var React = require('React'); -var StyleSheet = require('StyleSheet'); -var View = require('View'); -var Text = require('Text'); +const BatchedBridge = require('BatchedBridge'); +const React = require('React'); +const StyleSheet = require('StyleSheet'); +const View = require('View'); +const Text = require('Text'); -var createReactClass = require('create-react-class'); -var renderApplication = require('renderApplication'); +const renderApplication = require('renderApplication'); -var FlexTestApp = createReactClass({ - displayName: 'FlexTestApp', - _styles: StyleSheet.create({ - container: { - width: 200, - height: 200, - flexDirection: 'row', - }, - child: { - flex: 1, - }, - absolute: { - position: 'absolute', - top: 15, - left: 10, - width: 50, - height: 60, - }, - }), - render: function() { +type FlexTestAppProps = $ReadOnly<{||}>; +class FlexTestApp extends React.Component { + render() { return ( ); + } +} + +const FlexTestAppStyles = StyleSheet.create({ + container: { + width: 200, + height: 200, + flexDirection: 'row', + }, + child: { + flex: 1, + }, + absolute: { + position: 'absolute', + top: 15, + left: 10, + width: 50, + height: 60, + }, + bgRed: { + backgroundColor: '#ff0000', + }, + bgBlue: { + backgroundColor: '#0000ff', }, }); -var FlexWithText = createReactClass({ - displayName: 'FlexWithText', - _styles: StyleSheet.create({ - container: { - flexDirection: 'column', - margin: 20, - }, - row: { - flexDirection: 'row', - alignItems: 'flex-end', - height: 300, - }, - inner: { - flex: 1, - margin: 10, - }, - }), - render: function() { +type FlexWithTextProps = $ReadOnly<{||}>; +class FlexWithText extends React.Component { + render() { return ( - - Hello - World + + Hello + World ); + } +} + +const FlexWithTextStyles = StyleSheet.create({ + container: { + flexDirection: 'column', + margin: 20, + }, + row: { + flexDirection: 'row', + alignItems: 'flex-end', + height: 300, + }, + inner: { + flex: 1, + margin: 10, }, }); -var AbsolutePositionTestApp = createReactClass({ - displayName: 'AbsolutePositionTestApp', - _styles: StyleSheet.create({ - absolute: { - position: 'absolute', - top: 15, - left: 10, - width: 50, - height: 60, - }, - }), - render: function() { +type AbsolutePositionTestAppProps = $ReadOnly<{||}>; +class AbsolutePositionTestApp extends React.Component< + AbsolutePositionTestAppProps, +> { + render() { return ( ); + } +} + +const AbsolutePositionTestAppStyles = StyleSheet.create({ + absolute: { + position: 'absolute', + top: 15, + left: 10, + width: 50, + height: 60, }, }); -var AbsolutePositionBottomRightTestApp = createReactClass({ - displayName: 'AbsolutePositionBottomRightTestApp', - _styles: StyleSheet.create({ - container: { - width: 100, - height: 100, - }, - absolute: { - position: 'absolute', - bottom: 15, - right: 10, - width: 50, - height: 60, - }, - }), - render: function() { +type AbsolutePositionBottomRightTestAppProps = $ReadOnly<{||}>; +class AbsolutePositionBottomRightTestApp extends React.Component< + AbsolutePositionBottomRightTestAppProps, +> { + render() { return ( - + ); + } +} + +const AbsolutePositionBottomRightTestAppStyles = StyleSheet.create({ + container: { + width: 100, + height: 100, + }, + absolute: { + position: 'absolute', + bottom: 15, + right: 10, + width: 50, + height: 60, }, }); -var CenteredTextView = createReactClass({ - displayName: 'CenteredTextView', - _styles: StyleSheet.create({ - parent: { - width: 200, - height: 100, - backgroundColor: '#aa3311', - justifyContent: 'center', - alignItems: 'center', - }, - text: { - fontSize: 15, - color: '#672831', - }, - }), - render: function() { +type CenteredTextViewProps = $ReadOnly<{| + text?: ?string, +|}>; +class CenteredTextView extends React.Component { + render() { return ( - - + + {this.props.text} ); + } +} + +const CenteredTextViewStyles = StyleSheet.create({ + parent: { + width: 200, + height: 100, + backgroundColor: '#aa3311', + justifyContent: 'center', + alignItems: 'center', + }, + text: { + fontSize: 15, + color: '#672831', }, }); -var flushUpdatePositionInList = null; -var UpdatePositionInListTestApp = createReactClass({ - displayName: 'UpdatePositionInListTestApp', - _styles: StyleSheet.create({ - element: { - height: 10, - }, - active: { - height: 50, - }, - }), - getInitialState: function() { +let flushUpdatePositionInList = null; + +type UpdatePositionInListTestAppProps = $ReadOnly<{||}>; +type UpdatePositionInListTestAppState = {| + active: boolean, +|}; +class UpdatePositionInListTestApp extends React.Component< + UpdatePositionInListTestAppProps, + UpdatePositionInListTestAppState, +> { + state = { + active: false, + }; + + constructor(...args) { + super(...args); flushUpdatePositionInList = () => this.setState({active: true}); - return {active: false}; - }, - render: function() { + } + + render() { return ( - + - + ); + } +} + +const UpdatePositionInListTestAppStyles = StyleSheet.create({ + element: { + height: 10, + }, + active: { + height: 50, }, }); -var UIManagerTestModule = { - renderFlexTestApplication: function(rootTag) { - renderApplication(FlexTestApp, {}, rootTag); +/** + * This is a workaround for the following flow problem: + * + * const emptyObject: {||} = {}; // Raises error + * + * @see https://github.com/facebook/flow/issues/2977 + */ +const emptyExactProps = Object.freeze({}); + +const UIManagerTestModule = { + renderFlexTestApplication(rootTag: number) { + renderApplication(FlexTestApp, emptyExactProps, rootTag); }, - renderFlexWithTextApplication: function(rootTag) { - renderApplication(FlexWithText, {}, rootTag); + renderFlexWithTextApplication(rootTag: number) { + renderApplication(FlexWithText, emptyExactProps, rootTag); }, - renderAbsolutePositionBottomRightTestApplication: function(rootTag) { - renderApplication(AbsolutePositionBottomRightTestApp, {}, rootTag); + renderAbsolutePositionBottomRightTestApplication(rootTag: number) { + renderApplication( + AbsolutePositionBottomRightTestApp, + emptyExactProps, + rootTag, + ); }, - renderAbsolutePositionTestApplication: function(rootTag) { - renderApplication(AbsolutePositionTestApp, {}, rootTag); + renderAbsolutePositionTestApplication(rootTag: number) { + renderApplication(AbsolutePositionTestApp, emptyExactProps, rootTag); }, - renderCenteredTextViewTestApplication: function(rootTag, text) { + renderCenteredTextViewTestApplication(rootTag: number, text: string) { renderApplication(CenteredTextView, {text: text}, rootTag); }, - renderUpdatePositionInListTestApplication: function(rootTag) { - renderApplication(UpdatePositionInListTestApp, {}, rootTag); - }, - flushUpdatePositionInList: function() { - flushUpdatePositionInList(); + renderUpdatePositionInListTestApplication(rootTag: number) { + renderApplication(UpdatePositionInListTestApp, emptyExactProps, rootTag); }, + flushUpdatePositionInList, }; BatchedBridge.registerCallableModule(