From bd32234e6ec0006ede180d09b464f1277737e789 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Mon, 31 Dec 2018 08:26:00 -0800 Subject: [PATCH] Add flow types RNTester examples (#22829) Summary: This PR adds flow types for the RNTester examples, and updates all of the RNTester examples to match the flow type consistently. Previously, there was a mix of static class definitions and whether or not pages exported examples or a component. Now we will always export the same way, enforced by flow types Note: I also fixed most of the $FlowFixMe in changed components Pull Request resolved: https://github.com/facebook/react-native/pull/22829 Reviewed By: cpojer Differential Revision: D13563191 Pulled By: rickhanlonii fbshipit-source-id: b697e3346a863d1b130881592b0522a96c202b63 --- RNTester/js/ARTExample.js | 3 +- .../js/AccessibilityAndroidExample.android.js | 14 +- RNTester/js/AccessibilityIOSExample.js | 3 +- RNTester/js/ActionSheetIOSExample.js | 4 +- RNTester/js/ActivityIndicatorExample.js | 56 +++----- RNTester/js/AlertExample.js | 4 +- RNTester/js/AlertIOSExample.js | 107 +++++++------- RNTester/js/AnimatedExample.js | 42 +++--- RNTester/js/AnimatedGratuitousApp/AnExApp.js | 17 ++- RNTester/js/CheckBoxExample.js | 49 ++++--- RNTester/js/ClipboardExample.js | 27 ++-- RNTester/js/DatePickerAndroidExample.js | 32 ++++- RNTester/js/ExampleTypes.js | 29 ---- RNTester/js/FlatListExample.js | 29 +++- RNTester/js/GeolocationExample.js | 26 ++-- RNTester/js/ImageCapInsetsExample.js | 3 +- RNTester/js/ImageEditingExample.js | 24 ++-- RNTester/js/ImageExample.js | 130 +++++++++--------- RNTester/js/InputAccessoryViewExample.js | 27 ++-- RNTester/js/KeyboardAvoidingViewExample.js | 22 ++- RNTester/js/LayoutEventsExample.js | 3 +- RNTester/js/LayoutExample.js | 16 ++- RNTester/js/LinkingExample.js | 14 +- RNTester/js/ListExampleShared.js | 2 +- RNTester/js/ListViewExample.js | 16 ++- RNTester/js/ListViewGridLayoutExample.js | 14 +- RNTester/js/ListViewPagingExample.js | 14 +- RNTester/js/MaskedViewExample.js | 21 ++- RNTester/js/MultiColumnExample.js | 14 +- RNTester/js/PanResponderExample.js | 16 ++- .../js/PermissionsExampleAndroid.android.js | 9 +- .../js/ProgressBarAndroidExample.android.js | 14 +- RNTester/js/ProgressViewIOSExample.js | 20 +-- RNTester/js/RNTesterApp.ios.js | 2 +- RNTester/js/RNTesterExampleContainer.js | 4 - RNTester/js/RNTesterExampleList.js | 2 +- RNTester/js/RNTesterList.android.js | 5 +- RNTester/js/RNTesterList.ios.js | 6 +- RNTester/js/RTLExample.js | 15 +- RNTester/js/RefreshControlExample.js | 14 +- RNTester/js/SafeAreaViewExample.js | 43 +++--- RNTester/js/ScrollViewSimpleExample.js | 17 ++- RNTester/js/SectionListExample.js | 14 +- RNTester/js/ShareExample.js | 27 ++-- RNTester/js/Shared/RNTesterTypes.js | 22 +++ RNTester/js/StatusBarExample.js | 11 +- RNTester/js/SwipeableFlatListExample.js | 14 +- RNTester/js/SwipeableListViewExample.js | 19 +-- RNTester/js/TVEventHandlerExample.js | 38 +++-- RNTester/js/TabBarIOSBarStyleExample.js | 16 ++- RNTester/js/TabBarIOSExample.js | 23 +++- RNTester/js/TextExample.android.js | 17 ++- RNTester/js/TimePickerAndroidExample.js | 14 +- RNTester/js/ToastAndroidExample.android.js | 20 ++- RNTester/js/ToolbarAndroidExample.android.js | 14 +- .../js/ViewPagerAndroidExample.android.js | 21 ++- RNTester/js/WebSocketExample.js | 14 +- RNTester/js/createExamplePage.js | 5 +- 58 files changed, 715 insertions(+), 503 deletions(-) delete mode 100644 RNTester/js/ExampleTypes.js diff --git a/RNTester/js/ARTExample.js b/RNTester/js/ARTExample.js index 2a79591cb14..a57fc8eed0a 100644 --- a/RNTester/js/ARTExample.js +++ b/RNTester/js/ARTExample.js @@ -18,7 +18,8 @@ const {Surface, Path, Group, Shape} = ART; const scale = Platform.isTV ? 4 : 1; -class ARTExample extends React.Component<{}> { +type Props = $ReadOnly<{||}>; +class ARTExample extends React.Component { render() { const pathRect = new Path() .moveTo(scale * 0, scale * 0) diff --git a/RNTester/js/AccessibilityAndroidExample.android.js b/RNTester/js/AccessibilityAndroidExample.android.js index 0989f9f62d0..ac4b6c00108 100644 --- a/RNTester/js/AccessibilityAndroidExample.android.js +++ b/RNTester/js/AccessibilityAndroidExample.android.js @@ -31,9 +31,6 @@ const importantForAccessibilityValues = [ ]; class AccessibilityAndroidExample extends React.Component { - static title = 'Accessibility'; - static description = 'Examples of using Accessibility API.'; - state = { count: 0, backgroundImportantForAcc: 0, @@ -306,4 +303,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = AccessibilityAndroidExample; +exports.title = 'Accessibility'; +exports.description = 'Examples of using Accessibility API.'; +exports.examples = [ + { + title: 'Accessibility elements', + render(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/AccessibilityIOSExample.js b/RNTester/js/AccessibilityIOSExample.js index d6e20efc8a4..f9feffc05c7 100644 --- a/RNTester/js/AccessibilityIOSExample.js +++ b/RNTester/js/AccessibilityIOSExample.js @@ -14,7 +14,8 @@ const React = require('react'); const ReactNative = require('react-native'); const {AccessibilityInfo, Text, View, TouchableOpacity, Alert} = ReactNative; -class AccessibilityIOSExample extends React.Component<{}> { +type Props = $ReadOnly<{||}>; +class AccessibilityIOSExample extends React.Component { render() { return ( diff --git a/RNTester/js/ActionSheetIOSExample.js b/RNTester/js/ActionSheetIOSExample.js index 1a524859613..40dfc096b91 100644 --- a/RNTester/js/ActionSheetIOSExample.js +++ b/RNTester/js/ActionSheetIOSExample.js @@ -25,7 +25,9 @@ const BUTTONS = ['Option 0', 'Option 1', 'Option 2', 'Delete', 'Cancel']; const DESTRUCTIVE_INDEX = 3; const CANCEL_INDEX = 4; -class ActionSheetExample extends React.Component<{}, $FlowFixMeState> { +type Props = $ReadOnly<{||}>; +type State = {|clicked: string|}; +class ActionSheetExample extends React.Component { state = { clicked: 'none', }; diff --git a/RNTester/js/ActivityIndicatorExample.js b/RNTester/js/ActivityIndicatorExample.js index 937b368a443..ca25a457aa8 100644 --- a/RNTester/js/ActivityIndicatorExample.js +++ b/RNTester/js/ActivityIndicatorExample.js @@ -13,22 +13,14 @@ import React, {Component} from 'react'; import {ActivityIndicator, StyleSheet, View} from 'react-native'; -/** - * Optional Flowtype state and timer types definition - */ -type State = {animating: boolean}; -type Timer = number; +type State = {|animating: boolean|}; +type Props = $ReadOnly<{||}>; +type Timer = TimeoutID; -class ToggleAnimatingActivityIndicator extends Component< - $FlowFixMeProps, - State, -> { +class ToggleAnimatingActivityIndicator extends Component { _timer: Timer; - /* $FlowFixMe(>=0.85.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.85 was deployed. To see the error, delete this comment - * and run Flow. */ - constructor(props) { + constructor(props: Props) { super(props); this.state = { animating: true, @@ -40,16 +32,10 @@ class ToggleAnimatingActivityIndicator extends Component< } componentWillUnmount() { - /* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.63 was deployed. To see the error delete this - * comment and run Flow. */ clearTimeout(this._timer); } setToggleTimeout() { - /* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.63 was deployed. To see the error delete this - * comment and run Flow. */ this._timer = setTimeout(() => { this.setState({animating: !this.state.animating}); this.setToggleTimeout(); @@ -67,6 +53,22 @@ class ToggleAnimatingActivityIndicator extends Component< } } +const styles = StyleSheet.create({ + centering: { + alignItems: 'center', + justifyContent: 'center', + padding: 8, + }, + gray: { + backgroundColor: '#cccccc', + }, + horizontal: { + flexDirection: 'row', + justifyContent: 'space-around', + padding: 8, + }, +}); + exports.displayName = (undefined: ?string); exports.framework = 'React'; exports.title = ''; @@ -158,19 +160,3 @@ exports.examples = [ }, }, ]; - -const styles = StyleSheet.create({ - centering: { - alignItems: 'center', - justifyContent: 'center', - padding: 8, - }, - gray: { - backgroundColor: '#cccccc', - }, - horizontal: { - flexDirection: 'row', - justifyContent: 'space-around', - padding: 8, - }, -}); diff --git a/RNTester/js/AlertExample.js b/RNTester/js/AlertExample.js index fd888a73afb..1d783fb7084 100644 --- a/RNTester/js/AlertExample.js +++ b/RNTester/js/AlertExample.js @@ -23,7 +23,9 @@ const alertMessage = /** * Simple alert examples. */ -class SimpleAlertExampleBlock extends React.Component { +type Props = $ReadOnly<{||}>; + +class SimpleAlertExampleBlock extends React.Component { render() { return ( diff --git a/RNTester/js/AlertIOSExample.js b/RNTester/js/AlertIOSExample.js index 16868ce504a..b1e9f352eaf 100644 --- a/RNTester/js/AlertIOSExample.js +++ b/RNTester/js/AlertIOSExample.js @@ -16,59 +16,10 @@ const {StyleSheet, View, Text, TouchableHighlight, AlertIOS} = ReactNative; const {SimpleAlertExampleBlock} = require('./AlertExample'); -exports.framework = 'React'; -exports.title = 'AlertIOS'; -exports.description = 'iOS alerts and action sheets'; -exports.examples = [ - { - title: 'Alerts', - render() { - return ; - }, - }, - { - title: 'Prompt Options', - render(): React.Element { - return ; - }, - }, - { - title: 'Prompt Types', - render() { - return ( - - AlertIOS.prompt('Plain Text Entry')}> - - plain-text - - - - AlertIOS.prompt('Secure Text', null, null, 'secure-text') - }> - - secure-text - - - - AlertIOS.prompt('Login & Password', null, null, 'login-password') - }> - - login-password - - - - ); - }, - }, -]; +type Props = $ReadOnly<{||}>; +type State = {|promptValue: ?string|}; -class PromptOptions extends React.Component<$FlowFixMeProps, any> { +class PromptOptions extends React.Component { customButtons: Array; constructor(props) { @@ -196,3 +147,55 @@ const styles = StyleSheet.create({ fontWeight: 'bold', }, }); + +exports.framework = 'React'; +exports.title = 'AlertIOS'; +exports.description = 'iOS alerts and action sheets'; +exports.examples = [ + { + title: 'Alerts', + render() { + return ; + }, + }, + { + title: 'Prompt Options', + render(): React.Element { + return ; + }, + }, + { + title: 'Prompt Types', + render() { + return ( + + AlertIOS.prompt('Plain Text Entry')}> + + plain-text + + + + AlertIOS.prompt('Secure Text', null, null, 'secure-text') + }> + + secure-text + + + + AlertIOS.prompt('Login & Password', null, null, 'login-password') + }> + + login-password + + + + ); + }, + }, +]; diff --git a/RNTester/js/AnimatedExample.js b/RNTester/js/AnimatedExample.js index 1802d03a271..076692530ad 100644 --- a/RNTester/js/AnimatedExample.js +++ b/RNTester/js/AnimatedExample.js @@ -15,6 +15,22 @@ const ReactNative = require('react-native'); const {Animated, Easing, StyleSheet, Text, View} = ReactNative; const RNTesterButton = require('./RNTesterButton'); +const styles = StyleSheet.create({ + content: { + backgroundColor: 'deepskyblue', + borderWidth: 1, + borderColor: 'dodgerblue', + padding: 20, + margin: 20, + borderRadius: 10, + alignItems: 'center', + }, + rotatingImage: { + width: 70, + height: 70, + }, +}); + exports.framework = 'React'; exports.title = 'Animated - Examples'; exports.description = @@ -58,11 +74,11 @@ exports.examples = [ ); } } - class FadeInExample extends React.Component<$FlowFixMeProps, any> { - /* $FlowFixMe(>=0.85.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.85 was deployed. To see the error, delete - * this comment and run Flow. */ - constructor(props) { + + type Props = $ReadOnly<{||}>; + type State = {|show: boolean|}; + class FadeInExample extends React.Component { + constructor(props: Props) { super(props); this.state = { show: true, @@ -287,19 +303,3 @@ exports.examples = [ render: () => Checkout the Gratuitous Animation App!, }, ]; - -const styles = StyleSheet.create({ - content: { - backgroundColor: 'deepskyblue', - borderWidth: 1, - borderColor: 'dodgerblue', - padding: 20, - margin: 20, - borderRadius: 10, - alignItems: 'center', - }, - rotatingImage: { - width: 70, - height: 70, - }, -}); diff --git a/RNTester/js/AnimatedGratuitousApp/AnExApp.js b/RNTester/js/AnimatedGratuitousApp/AnExApp.js index f9aa375a7d9..be1142bd454 100644 --- a/RNTester/js/AnimatedGratuitousApp/AnExApp.js +++ b/RNTester/js/AnimatedGratuitousApp/AnExApp.js @@ -195,11 +195,6 @@ class Circle extends React.Component { } class AnExApp extends React.Component { - static title = 'Animated - Gratuitous App'; - static description = - 'Bunch of Animations - tap a circle to ' + - 'open a view with more animations, or longPress and drag to reorder circles.'; - _onMove: (position: Point) => void; constructor(props: any): void { super(props); @@ -365,4 +360,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = AnExApp; +exports.title = 'Animated - Gratuitous App'; +exports.description = + 'Bunch of Animations - tap a circle to open a view with more animations, or longPress and drag to reorder circles.'; +exports.examples = [ + { + title: 'And example app', + render(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/CheckBoxExample.js b/RNTester/js/CheckBoxExample.js index 1b16231ef33..3af9af42bfb 100644 --- a/RNTester/js/CheckBoxExample.js +++ b/RNTester/js/CheckBoxExample.js @@ -14,7 +14,13 @@ const React = require('react'); const ReactNative = require('react-native'); const {CheckBox, Text, View, StyleSheet} = ReactNative; -class BasicCheckBoxExample extends React.Component<{}, $FlowFixMeState> { +type BasicState = {| + trueCheckBoxIsOn: boolean, + falseCheckBoxIsOn: boolean, +|}; + +type BasicProps = $ReadOnly<{||}>; +class BasicCheckBoxExample extends React.Component { state = { trueCheckBoxIsOn: true, falseCheckBoxIsOn: false, @@ -37,7 +43,8 @@ class BasicCheckBoxExample extends React.Component<{}, $FlowFixMeState> { } } -class DisabledCheckBoxExample extends React.Component<{}, $FlowFixMeState> { +type DisabledProps = $ReadOnly<{||}>; +class DisabledCheckBoxExample extends React.Component { render() { return ( @@ -48,7 +55,13 @@ class DisabledCheckBoxExample extends React.Component<{}, $FlowFixMeState> { } } -class EventCheckBoxExample extends React.Component<{}, $FlowFixMeState> { +type EventProps = $ReadOnly<{||}>; +type EventState = {| + eventCheckBoxIsOn: boolean, + eventCheckBoxRegressionIsOn: boolean, +|}; + +class EventCheckBoxExample extends React.Component { state = { eventCheckBoxIsOn: false, eventCheckBoxRegressionIsOn: true, @@ -92,7 +105,20 @@ class EventCheckBoxExample extends React.Component<{}, $FlowFixMeState> { } } -let examples = [ +const styles = StyleSheet.create({ + container: { + flexDirection: 'row', + justifyContent: 'space-around', + }, + checkbox: { + marginBottom: 10, + }, +}); + +exports.title = ''; +exports.displayName = 'CheckBoxExample'; +exports.description = 'Native boolean input'; +exports.examples = [ { title: 'CheckBoxes can be set to true or false', render(): React.Element { @@ -118,18 +144,3 @@ let examples = [ }, }, ]; - -exports.title = ''; -exports.displayName = 'CheckBoxExample'; -exports.description = 'Native boolean input'; -exports.examples = examples; - -const styles = StyleSheet.create({ - container: { - flexDirection: 'row', - justifyContent: 'space-around', - }, - checkbox: { - marginBottom: 10, - }, -}); diff --git a/RNTester/js/ClipboardExample.js b/RNTester/js/ClipboardExample.js index adc6f40a1db..d093db9b059 100644 --- a/RNTester/js/ClipboardExample.js +++ b/RNTester/js/ClipboardExample.js @@ -14,7 +14,12 @@ const React = require('react'); const ReactNative = require('react-native'); const {Clipboard, View, Text, StyleSheet} = ReactNative; -class ClipboardExample extends React.Component<{}, $FlowFixMeState> { +type Props = $ReadOnly<{||}>; +type State = {| + content: string, +|}; + +class ClipboardExample extends React.Component { state = { content: 'Content will appear here', }; @@ -41,6 +46,16 @@ class ClipboardExample extends React.Component<{}, $FlowFixMeState> { } } +const styles = StyleSheet.create({ + label: { + color: 'blue', + }, + content: { + color: 'red', + marginTop: 20, + }, +}); + exports.title = 'Clipboard'; exports.description = 'Show Clipboard contents.'; exports.examples = [ @@ -51,13 +66,3 @@ exports.examples = [ }, }, ]; - -const styles = StyleSheet.create({ - label: { - color: 'blue', - }, - content: { - color: 'red', - marginTop: 20, - }, -}); diff --git a/RNTester/js/DatePickerAndroidExample.js b/RNTester/js/DatePickerAndroidExample.js index 8e50de02595..bd303dc2a3e 100644 --- a/RNTester/js/DatePickerAndroidExample.js +++ b/RNTester/js/DatePickerAndroidExample.js @@ -21,10 +21,25 @@ const { const RNTesterBlock = require('./RNTesterBlock'); const RNTesterPage = require('./RNTesterPage'); -class DatePickerAndroidExample extends React.Component { - static title = 'DatePickerAndroid'; - static description = 'Standard Android date picker dialog'; +type Props = $ReadOnly<{||}>; +type State = {| + presetDate: Date, + simpleDate: Date, + spinnerDate: Date, + calendarDate: Date, + defaultDate: Date, + allDate: Date, + simpleText: string, + spinnerText: string, + calendarText: string, + defaultText: string, + minText: string, + maxText: string, + presetText: string, + allText: string, +|}; +class DatePickerAndroidExample extends React.Component { state = { presetDate: new Date(2020, 4, 5), simpleDate: new Date(2020, 4, 5), @@ -144,4 +159,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = DatePickerAndroidExample; +exports.title = 'DatePickerAndroid'; +exports.description = 'Standard Android date picker dialog'; +exports.examples = [ + { + title: 'Simple date picker', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ExampleTypes.js b/RNTester/js/ExampleTypes.js deleted file mode 100644 index aa5c84ebca7..00000000000 --- a/RNTester/js/ExampleTypes.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow - */ - -'use strict'; - -import type React from 'react'; - -export type Example = { - title: string, - /* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.89 was deployed. To see the error, delete this comment - * and run Flow. */ - render: () => ?React.Element, - description?: string, - platform?: string, -}; - -export type ExampleModule = { - title: string, - description: string, - examples: Array, -}; diff --git a/RNTester/js/FlatListExample.js b/RNTester/js/FlatListExample.js index d8eeb4626cf..2277b1fa621 100644 --- a/RNTester/js/FlatListExample.js +++ b/RNTester/js/FlatListExample.js @@ -10,6 +10,8 @@ 'use strict'; +import type {Item} from './ListExampleShared'; + const Alert = require('Alert'); const React = require('react'); const ReactNative = require('react-native'); @@ -40,10 +42,20 @@ const VIEWABILITY_CONFIG = { waitForInteraction: true, }; -class FlatListExample extends React.PureComponent<{}, $FlowFixMeState> { - static title = ''; - static description = 'Performant, scrollable list of data.'; +type Props = $ReadOnly<{||}>; +type State = {| + data: Array, + debug: boolean, + horizontal: boolean, + inverted: boolean, + filterText: string, + fixedHeight: boolean, + logViewable: boolean, + virtualized: boolean, + empty: boolean, +|}; +class FlatListExample extends React.PureComponent { state = { data: genItemData(100), debug: false, @@ -220,4 +232,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = FlatListExample; +exports.title = ''; +exports.description = 'Performant, scrollable list of data.'; +exports.examples = [ + { + title: 'Simple list of items', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/GeolocationExample.js b/RNTester/js/GeolocationExample.js index 8ed2182ecd9..808f6c074c5 100644 --- a/RNTester/js/GeolocationExample.js +++ b/RNTester/js/GeolocationExample.js @@ -14,19 +14,6 @@ const React = require('react'); const ReactNative = require('react-native'); const {StyleSheet, Text, View, Alert} = ReactNative; -exports.framework = 'React'; -exports.title = 'Geolocation'; -exports.description = 'Examples of using the Geolocation API.'; - -exports.examples = [ - { - title: 'navigator.geolocation', - render: function(): React.Element { - return ; - }, - }, -]; - class GeolocationExample extends React.Component<{}, $FlowFixMeState> { state = { initialPosition: 'unknown', @@ -75,3 +62,16 @@ const styles = StyleSheet.create({ fontWeight: '500', }, }); + +exports.framework = 'React'; +exports.title = 'Geolocation'; +exports.description = 'Examples of using the Geolocation API.'; + +exports.examples = [ + { + title: 'navigator.geolocation', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ImageCapInsetsExample.js b/RNTester/js/ImageCapInsetsExample.js index 546c639577d..4a7ac0028d1 100644 --- a/RNTester/js/ImageCapInsetsExample.js +++ b/RNTester/js/ImageCapInsetsExample.js @@ -16,7 +16,8 @@ const ReactNative = require('react-native'); const nativeImageSource = require('nativeImageSource'); const {Image, StyleSheet, Text, View} = ReactNative; -class ImageCapInsetsExample extends React.Component<{}> { +type Props = $ReadOnly<{||}>; +class ImageCapInsetsExample extends React.Component { render() { return ( diff --git a/RNTester/js/ImageEditingExample.js b/RNTester/js/ImageEditingExample.js index c62784acb2c..bc4fdbb7a07 100644 --- a/RNTester/js/ImageEditingExample.js +++ b/RNTester/js/ImageEditingExample.js @@ -278,18 +278,6 @@ class ImageCropper extends React.Component<$FlowFixMeProps, $FlowFixMeState> { } } -exports.framework = 'React'; -exports.title = 'ImageEditor'; -exports.description = 'Cropping and scaling with ImageEditor'; -exports.examples = [ - { - title: 'Image Cropping', - render() { - return ; - }, - }, -]; - const styles = StyleSheet.create({ container: { flex: 1, @@ -314,3 +302,15 @@ const styles = StyleSheet.create({ fontWeight: '500', }, }); + +exports.framework = 'React'; +exports.title = 'ImageEditor'; +exports.description = 'Cropping and scaling with ImageEditor'; +exports.examples = [ + { + title: 'Image Cropping', + render() { + return ; + }, + }, +]; diff --git a/RNTester/js/ImageExample.js b/RNTester/js/ImageExample.js index abec3802716..7b55b1c4f25 100644 --- a/RNTester/js/ImageExample.js +++ b/RNTester/js/ImageExample.js @@ -335,6 +335,71 @@ class MultipleSourcesExample extends React.Component< } } +const fullImage = { + uri: 'https://facebook.github.io/react-native/img/opengraph.png', +}; +const smallImage = { + uri: 'https://facebook.github.io/react-native/img/favicon.png', +}; + +const styles = StyleSheet.create({ + base: { + width: 38, + height: 38, + }, + progress: { + flex: 1, + alignItems: 'center', + flexDirection: 'row', + width: 100, + }, + leftMargin: { + marginLeft: 10, + }, + background: { + backgroundColor: '#222222', + }, + sectionText: { + marginVertical: 6, + }, + nestedText: { + marginLeft: 12, + marginTop: 20, + backgroundColor: 'transparent', + color: 'white', + }, + resizeMode: { + width: 90, + height: 60, + borderWidth: 0.5, + borderColor: 'black', + }, + resizeModeText: { + fontSize: 11, + marginBottom: 3, + }, + icon: { + width: 15, + height: 15, + }, + horizontal: { + flexDirection: 'row', + }, + gif: { + flex: 1, + height: 200, + }, + base64: { + flex: 1, + height: 50, + resizeMode: 'contain', + }, + touchableText: { + fontWeight: '500', + color: 'blue', + }, +}); + exports.displayName = (undefined: ?string); exports.framework = 'React'; exports.title = ''; @@ -890,68 +955,3 @@ exports.examples = [ }, }, ]; - -const fullImage = { - uri: 'https://facebook.github.io/react-native/img/opengraph.png', -}; -const smallImage = { - uri: 'https://facebook.github.io/react-native/img/favicon.png', -}; - -const styles = StyleSheet.create({ - base: { - width: 38, - height: 38, - }, - progress: { - flex: 1, - alignItems: 'center', - flexDirection: 'row', - width: 100, - }, - leftMargin: { - marginLeft: 10, - }, - background: { - backgroundColor: '#222222', - }, - sectionText: { - marginVertical: 6, - }, - nestedText: { - marginLeft: 12, - marginTop: 20, - backgroundColor: 'transparent', - color: 'white', - }, - resizeMode: { - width: 90, - height: 60, - borderWidth: 0.5, - borderColor: 'black', - }, - resizeModeText: { - fontSize: 11, - marginBottom: 3, - }, - icon: { - width: 15, - height: 15, - }, - horizontal: { - flexDirection: 'row', - }, - gif: { - flex: 1, - height: 200, - }, - base64: { - flex: 1, - height: 50, - resizeMode: 'contain', - }, - touchableText: { - fontWeight: '500', - color: 'blue', - }, -}); diff --git a/RNTester/js/InputAccessoryViewExample.js b/RNTester/js/InputAccessoryViewExample.js index 70f9b572945..3cc2665d565 100644 --- a/RNTester/js/InputAccessoryViewExample.js +++ b/RNTester/js/InputAccessoryViewExample.js @@ -23,7 +23,8 @@ const { View, } = ReactNative; -class Message extends React.PureComponent<*> { +type MessageProps = $ReadOnly<{||}>; +class Message extends React.PureComponent { render() { return ( @@ -33,7 +34,9 @@ class Message extends React.PureComponent<*> { } } -class TextInputBar extends React.PureComponent<*, *> { +type TextInputProps = $ReadOnly<{||}>; +type TextInputState = {|text: string|}; +class TextInputBar extends React.PureComponent { state = {text: ''}; render() { @@ -59,12 +62,8 @@ class TextInputBar extends React.PureComponent<*, *> { } const BAR_HEIGHT = 44; - -class InputAccessoryViewExample extends React.Component<*> { - static title = ''; - static description = - 'Example showing how to use an InputAccessoryView to build an iMessage-like sticky text input'; - +type InputAccessoryProps = $ReadOnly<{||}>; +class InputAccessoryViewExample extends React.Component { render() { return ( <> @@ -108,4 +107,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = InputAccessoryViewExample; +exports.title = ''; +exports.description = + 'Example showing how to use an InputAccessoryView to build an iMessage-like sticky text input'; +exports.examples = [ + { + title: 'Simple view with sticky input', + render: function(): React.Node { + return ; + }, + }, +]; diff --git a/RNTester/js/KeyboardAvoidingViewExample.js b/RNTester/js/KeyboardAvoidingViewExample.js index 5a959c8618e..b3c84d18e3f 100644 --- a/RNTester/js/KeyboardAvoidingViewExample.js +++ b/RNTester/js/KeyboardAvoidingViewExample.js @@ -25,11 +25,13 @@ const { const RNTesterBlock = require('./RNTesterBlock'); const RNTesterPage = require('./RNTesterPage'); -class KeyboardAvoidingViewExample extends React.Component { - static title = ''; - static description = - 'Base component for views that automatically adjust their height or position to move out of the way of the keyboard.'; +type Props = $ReadOnly<{||}>; +type State = {| + behavior: string, + modalOpen: boolean, +|}; +class KeyboardAvoidingViewExample extends React.Component { state = { behavior: 'padding', modalOpen: false, @@ -105,4 +107,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = KeyboardAvoidingViewExample; +exports.title = ''; +exports.description = + 'Base component for views that automatically adjust their height or position to move out of the way of the keyboard.'; +exports.examples = [ + { + title: 'Simple keyboard view', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/LayoutEventsExample.js b/RNTester/js/LayoutEventsExample.js index e0676af568b..b9e555852d6 100644 --- a/RNTester/js/LayoutEventsExample.js +++ b/RNTester/js/LayoutEventsExample.js @@ -16,6 +16,7 @@ const {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative; import type {ViewLayout, ViewLayoutEvent} from 'ViewPropTypes'; +type Props = $ReadOnly<{||}>; type State = { containerStyle?: {|width: number|}, extraText?: string, @@ -25,7 +26,7 @@ type State = { viewStyle: {|margin: number|}, }; -class LayoutEventExample extends React.Component<{}, State> { +class LayoutEventExample extends React.Component { state: State = { viewStyle: { margin: 20, diff --git a/RNTester/js/LayoutExample.js b/RNTester/js/LayoutExample.js index fed6f705783..d77e6c67de4 100644 --- a/RNTester/js/LayoutExample.js +++ b/RNTester/js/LayoutExample.js @@ -51,10 +51,6 @@ class CircleBlock extends React.Component<$FlowFixMeProps> { } class LayoutExample extends React.Component<$FlowFixMeProps> { - static title = 'Layout - Flexbox'; - static description = 'Examples of using the flexbox API to layout views.'; - static displayName = 'LayoutExample'; - render() { const fiveColoredCircles = [ , @@ -196,4 +192,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = LayoutExample; +exports.title = 'Layout - Flexbox'; +exports.description = 'Examples of using the flexbox API to layout views.'; +exports.displayName = 'LayoutExample'; +exports.examples = [ + { + title: 'Simple layout using flexbox', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/LinkingExample.js b/RNTester/js/LinkingExample.js index def07bdb523..32ae2bc990e 100644 --- a/RNTester/js/LinkingExample.js +++ b/RNTester/js/LinkingExample.js @@ -69,9 +69,6 @@ class SendIntentButton extends React.Component { } class IntentAndroidExample extends React.Component { - static title = 'Linking'; - static description = 'Shows how to use Linking to open URLs.'; - render() { return ( @@ -119,4 +116,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = IntentAndroidExample; +exports.title = 'Linking'; +exports.description = 'Shows how to use Linking to open URLs.'; +exports.examples = [ + { + title: 'Simple list of items', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ListExampleShared.js b/RNTester/js/ListExampleShared.js index ee1bdad0341..b01d418de2f 100644 --- a/RNTester/js/ListExampleShared.js +++ b/RNTester/js/ListExampleShared.js @@ -24,7 +24,7 @@ const { View, } = ReactNative; -type Item = { +export type Item = { title: string, text: string, key: string, diff --git a/RNTester/js/ListViewExample.js b/RNTester/js/ListViewExample.js index eb2c572be28..a8663da20bd 100644 --- a/RNTester/js/ListViewExample.js +++ b/RNTester/js/ListViewExample.js @@ -29,10 +29,7 @@ type State = {| dataSource: ListViewDataSource, |}; -class ListViewSimpleExample extends React.Component { - static title = ''; - static description = 'Performant, scrollable list of data.'; - +class ListViewExample extends React.Component { state = { dataSource: this.getInitialDataSource(), }; @@ -166,4 +163,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = ListViewSimpleExample; +exports.title = ''; +exports.description = 'Performant, scrollable list of data.'; +exports.examples = [ + { + title: 'Simple list of items', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ListViewGridLayoutExample.js b/RNTester/js/ListViewGridLayoutExample.js index 2bc2cb25143..e3d6cb5b63c 100644 --- a/RNTester/js/ListViewGridLayoutExample.js +++ b/RNTester/js/ListViewGridLayoutExample.js @@ -44,9 +44,6 @@ type State = {| |}; class ListViewGridLayoutExample extends React.Component { - static title = ' - Grid Layout'; - static description = 'Flexbox grid layout.'; - state = { dataSource: this.getInitialDataSource(), }; @@ -152,4 +149,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = ListViewGridLayoutExample; +exports.title = ' - Grid Layout'; +exports.description = 'Flexbox grid layout.'; +exports.examples = [ + { + title: 'Simple list view with grid layout', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ListViewPagingExample.js b/RNTester/js/ListViewPagingExample.js index 8c81d62cb9e..4aade764f44 100644 --- a/RNTester/js/ListViewPagingExample.js +++ b/RNTester/js/ListViewPagingExample.js @@ -88,9 +88,6 @@ class Thumb extends React.Component<{}, $FlowFixMeState> { } class ListViewPagingExample extends React.Component<$FlowFixMeProps, *> { - static title = ' - Paging'; - static description = 'Floating headers & layout animations.'; - // $FlowFixMe found when converting React.createClass to ES6 constructor(props) { super(props); @@ -282,4 +279,13 @@ const layoutAnimationConfigs = [ animations.layout.easeInEaseOut, ]; -module.exports = ListViewPagingExample; +exports.title = ' - Paging'; +exports.description = 'Floating headers & layout animations.'; +exports.examples = [ + { + title: 'Simple list view with pagination', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/MaskedViewExample.js b/RNTester/js/MaskedViewExample.js index 8a2ebd71116..5516a68ff74 100644 --- a/RNTester/js/MaskedViewExample.js +++ b/RNTester/js/MaskedViewExample.js @@ -22,11 +22,12 @@ const { View, } = require('react-native'); -class MaskedViewExample extends React.Component<{}, $FlowFixMeState> { - static title = ''; - static description = - 'Renders the child view with a mask specified in the `renderMask` prop.'; +type Props = $ReadOnly<{||}>; +type State = {| + alternateChildren: boolean, +|}; +class MaskedViewExample extends React.Component { state = { alternateChildren: true, }; @@ -181,4 +182,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = MaskedViewExample; +exports.title = ''; +exports.description = + 'Renders the child view with a mask specified in the `renderMask` prop.'; +exports.examples = [ + { + title: 'Simple masked view', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/MultiColumnExample.js b/RNTester/js/MultiColumnExample.js index 28f7804c5ef..c7ae28a997e 100644 --- a/RNTester/js/MultiColumnExample.js +++ b/RNTester/js/MultiColumnExample.js @@ -34,9 +34,6 @@ class MultiColumnExample extends React.PureComponent< $FlowFixMeProps, $FlowFixMeState, > { - static title = ' - MultiColumn'; - static description = 'Performant, scrollable grid of data.'; - state = { data: genItemData(1000), filterText: '', @@ -165,4 +162,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = MultiColumnExample; +exports.title = ' - MultiColumn'; +exports.description = 'Performant, scrollable grid of data.'; +exports.examples = [ + { + title: 'Simple flat list multi column', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/PanResponderExample.js b/RNTester/js/PanResponderExample.js index b484dc086bf..94735f5e583 100644 --- a/RNTester/js/PanResponderExample.js +++ b/RNTester/js/PanResponderExample.js @@ -28,10 +28,6 @@ const CIRCLE_SIZE = 80; type Props = $ReadOnly<{||}>; class PanResponderExample extends React.Component { - static title = 'PanResponder Sample'; - static description = - 'Shows the Use of PanResponder to provide basic gesture handling'; - _handleStartShouldSetPanResponder = ( event: PressEvent, gestureState: GestureState, @@ -141,4 +137,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = PanResponderExample; +exports.title = 'PanResponder Sample'; +exports.description = + 'Shows the Use of PanResponder to provide basic gesture handling'; +exports.examples = [ + { + title: 'Basic gresture handling', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/PermissionsExampleAndroid.android.js b/RNTester/js/PermissionsExampleAndroid.android.js index 93a7451809b..a45efa9a544 100644 --- a/RNTester/js/PermissionsExampleAndroid.android.js +++ b/RNTester/js/PermissionsExampleAndroid.android.js @@ -23,11 +23,6 @@ const { const Item = Picker.Item; -exports.displayName = (undefined: ?string); -exports.framework = 'React'; -exports.title = 'PermissionsAndroid'; -exports.description = 'Permissions example for API 23+.'; - class PermissionsExample extends React.Component<{}, $FlowFixMeState> { state = { permission: PermissionsAndroid.PERMISSIONS.CAMERA, @@ -105,6 +100,10 @@ class PermissionsExample extends React.Component<{}, $FlowFixMeState> { }; } +exports.displayName = (undefined: ?string); +exports.framework = 'React'; +exports.title = 'PermissionsAndroid'; +exports.description = 'Permissions example for API 23+.'; exports.examples = [ { title: 'Permissions Example', diff --git a/RNTester/js/ProgressBarAndroidExample.android.js b/RNTester/js/ProgressBarAndroidExample.android.js index 9c45fc54c40..02761819cb7 100644 --- a/RNTester/js/ProgressBarAndroidExample.android.js +++ b/RNTester/js/ProgressBarAndroidExample.android.js @@ -57,9 +57,6 @@ class MovingBar extends React.Component { } class ProgressBarAndroidExample extends React.Component<{}> { - static title = ''; - static description = 'Horizontal bar to show the progress of some operation.'; - render() { return ( @@ -91,4 +88,13 @@ class ProgressBarAndroidExample extends React.Component<{}> { } } -module.exports = ProgressBarAndroidExample; +exports.title = ''; +exports.description = 'Horizontal bar to show the progress of some operation.'; +exports.examples = [ + { + title: 'Simple progress bar', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ProgressViewIOSExample.js b/RNTester/js/ProgressViewIOSExample.js index b7d85470744..63bc82c0767 100644 --- a/RNTester/js/ProgressViewIOSExample.js +++ b/RNTester/js/ProgressViewIOSExample.js @@ -82,6 +82,16 @@ class ProgressViewExample extends React.Component { } } +const styles = StyleSheet.create({ + container: { + marginTop: -20, + backgroundColor: 'transparent', + }, + progressView: { + marginTop: 20, + }, +}); + exports.displayName = (undefined: ?string); exports.framework = 'React'; exports.title = 'ProgressViewIOS'; @@ -94,13 +104,3 @@ exports.examples = [ }, }, ]; - -const styles = StyleSheet.create({ - container: { - marginTop: -20, - backgroundColor: 'transparent', - }, - progressView: { - marginTop: 20, - }, -}); diff --git a/RNTester/js/RNTesterApp.ios.js b/RNTester/js/RNTesterApp.ios.js index 56a90d435ba..1e7f9da2f19 100644 --- a/RNTester/js/RNTesterApp.ios.js +++ b/RNTester/js/RNTesterApp.ios.js @@ -33,7 +33,7 @@ const { YellowBox, } = ReactNative; -import type {RNTesterExample} from './RNTesterList.ios'; +import type {RNTesterExample} from 'RNTesterTypes'; import type {RNTesterAction} from './RNTesterActions'; import type {RNTesterNavigationState} from './RNTesterNavigationReducer'; diff --git a/RNTester/js/RNTesterExampleContainer.js b/RNTester/js/RNTesterExampleContainer.js index 5f3299d0b8c..2dcc7713b01 100644 --- a/RNTester/js/RNTesterExampleContainer.js +++ b/RNTester/js/RNTesterExampleContainer.js @@ -34,10 +34,6 @@ class RNTesterExampleContainer extends React.Component { } render(): React.Element { - if (!this.props.module.examples) { - return ; - } - if (this.props.module.examples.length === 1) { const Example = this.props.module.examples[0].render; return ; diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index af95d285296..98ebda4a4fb 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -22,7 +22,7 @@ const View = require('View'); /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found when * making Flow check .android.js files. */ -import type {RNTesterExample} from './RNTesterList.ios'; +import type {RNTesterExample} from 'RNTesterTypes'; import type {ViewStyleProp} from 'StyleSheet'; type Props = { diff --git a/RNTester/js/RNTesterList.android.js b/RNTester/js/RNTesterList.android.js index 8657fc43061..9f1b648c7a5 100644 --- a/RNTester/js/RNTesterList.android.js +++ b/RNTester/js/RNTesterList.android.js @@ -10,10 +10,7 @@ 'use strict'; -export type RNTesterExample = { - key: string, - module: Object, -}; +import type {RNTesterExample} from 'RNTesterTypes'; const ComponentExamples: Array = [ { diff --git a/RNTester/js/RNTesterList.ios.js b/RNTester/js/RNTesterList.ios.js index bcf31b320b9..e68d2e57124 100644 --- a/RNTester/js/RNTesterList.ios.js +++ b/RNTester/js/RNTesterList.ios.js @@ -10,11 +10,7 @@ 'use strict'; -export type RNTesterExample = { - key: string, - module: Object, - supportsTVOS: boolean, -}; +import type {RNTesterExample} from 'RNTesterTypes'; const ComponentExamples: Array = [ { diff --git a/RNTester/js/RTLExample.js b/RNTester/js/RTLExample.js index c7afa0e1876..96fe2fc8a2a 100644 --- a/RNTester/js/RTLExample.js +++ b/RNTester/js/RTLExample.js @@ -372,10 +372,6 @@ const BorderExample = withRTLState(({isRTL, setRTL}) => { }); class RTLExample extends React.Component { - static title = 'RTLExample'; - static description = - 'Examples to show how to apply components to RTL layout.'; - _panResponder: Object; constructor(props: Object) { @@ -679,4 +675,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = RTLExample; +exports.title = 'RTLExample'; +exports.description = 'Examples to show how to apply components to RTL layout.'; +exports.examples = [ + { + title: 'Simple RTL', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/RefreshControlExample.js b/RNTester/js/RefreshControlExample.js index 30f20cf03ca..515eeac33ae 100644 --- a/RNTester/js/RefreshControlExample.js +++ b/RNTester/js/RefreshControlExample.js @@ -56,9 +56,6 @@ class Row extends React.Component { } class RefreshControlExample extends React.Component { - static title = ''; - static description = 'Adds pull-to-refresh support to a scrollview.'; - state = { isRefreshing: false, loaded: 0, @@ -118,4 +115,13 @@ class RefreshControlExample extends React.Component { }; } -module.exports = RefreshControlExample; +exports.title = ''; +exports.description = 'Adds pull-to-refresh support to a scrollview.'; +exports.examples = [ + { + title: 'Simple refresh', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/SafeAreaViewExample.js b/RNTester/js/SafeAreaViewExample.js index 37a3910a716..0dbc79e0947 100644 --- a/RNTester/js/SafeAreaViewExample.js +++ b/RNTester/js/SafeAreaViewExample.js @@ -19,12 +19,6 @@ const Switch = require('Switch'); const Text = require('Text'); const View = require('View'); -exports.displayName = (undefined: ?string); -exports.framework = 'React'; -exports.title = ''; -exports.description = - 'SafeAreaView automatically applies paddings reflect the portion of the view that is not covered by other (special) ancestor views.'; - class SafeAreaViewExample extends React.Component< {}, {| @@ -100,6 +94,27 @@ class IsIPhoneXExample extends React.Component<{}> { } } +const styles = StyleSheet.create({ + modal: { + flex: 1, + }, + safeArea: { + flex: 1, + height: 1000, + }, + safeAreaContent: { + flex: 1, + backgroundColor: '#ffaaaa', + alignItems: 'center', + justifyContent: 'center', + }, +}); + +exports.displayName = (undefined: ?string); +exports.framework = 'React'; +exports.title = ''; +exports.description = + 'SafeAreaView automatically applies paddings reflect the portion of the view that is not covered by other (special) ancestor views.'; exports.examples = [ { title: ' Example', @@ -117,19 +132,3 @@ exports.examples = [ render: () => , }, ]; - -const styles = StyleSheet.create({ - modal: { - flex: 1, - }, - safeArea: { - flex: 1, - height: 1000, - }, - safeAreaContent: { - flex: 1, - backgroundColor: '#ffaaaa', - alignItems: 'center', - justifyContent: 'center', - }, -}); diff --git a/RNTester/js/ScrollViewSimpleExample.js b/RNTester/js/ScrollViewSimpleExample.js index c72a4707689..f5ca4fcedf8 100644 --- a/RNTester/js/ScrollViewSimpleExample.js +++ b/RNTester/js/ScrollViewSimpleExample.js @@ -17,10 +17,6 @@ const {ScrollView, StyleSheet, Text, TouchableOpacity} = ReactNative; const NUM_ITEMS = 20; class ScrollViewSimpleExample extends React.Component<{}> { - static title = ''; - static description = - 'Component that enables scrolling through child components.'; - /* $FlowFixMe(>=0.85.0 site=react_native_fb) This comment suppresses an error * found when Flow v0.85 was deployed. To see the error, delete this comment * and run Flow. */ @@ -90,4 +86,15 @@ const styles = StyleSheet.create({ }, }); -module.exports = ScrollViewSimpleExample; +exports.title = ''; +exports.description = + 'Component that enables scrolling through child components.'; + +exports.examples = [ + { + title: 'Simple scroll view', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/SectionListExample.js b/RNTester/js/SectionListExample.js index 0d72c60fab2..be4179f7e6c 100644 --- a/RNTester/js/SectionListExample.js +++ b/RNTester/js/SectionListExample.js @@ -62,9 +62,6 @@ const CustomSeparatorComponent = ({highlighted, text}) => ( ); class SectionListExample extends React.PureComponent<{}, $FlowFixMeState> { - static title = ''; - static description = 'Performant, scrollable list of data.'; - state = { data: genItemData(1000), debug: false, @@ -275,4 +272,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = SectionListExample; +exports.title = ''; +exports.description = 'Performant, scrollable list of data.'; +exports.examples = [ + { + title: 'Simple scrollable list', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ShareExample.js b/RNTester/js/ShareExample.js index d1608a25071..97d30e6c1cb 100644 --- a/RNTester/js/ShareExample.js +++ b/RNTester/js/ShareExample.js @@ -14,19 +14,10 @@ const React = require('react'); const ReactNative = require('react-native'); const {StyleSheet, View, Text, TouchableHighlight, Share} = ReactNative; -exports.framework = 'React'; -exports.title = 'Share'; -exports.description = 'Share data with other Apps.'; -exports.examples = [ - { - title: 'Share Text Content', - render() { - return ; - }, - }, -]; +type Props = $ReadOnly<{||}>; +type State = {|result: string|}; -class ShareMessageExample extends React.Component<$FlowFixMeProps, any> { +class ShareMessageExample extends React.Component { _shareMessage: Function; _shareText: Function; _showResult: Function; @@ -116,3 +107,15 @@ const styles = StyleSheet.create({ padding: 10, }, }); + +exports.framework = 'React'; +exports.title = 'Share'; +exports.description = 'Share data with other Apps.'; +exports.examples = [ + { + title: 'Share Text Content', + render() { + return ; + }, + }, +]; diff --git a/RNTester/js/Shared/RNTesterTypes.js b/RNTester/js/Shared/RNTesterTypes.js index 00b91ea0ae7..a07b60d3796 100644 --- a/RNTester/js/Shared/RNTesterTypes.js +++ b/RNTester/js/Shared/RNTesterTypes.js @@ -11,6 +11,7 @@ 'use strict'; import type {ComponentType} from 'React'; +import * as React from 'react'; export type RNTesterProps = $ReadOnly<{| navigator?: ?$ReadOnlyArray< @@ -22,3 +23,24 @@ export type RNTesterProps = $ReadOnly<{| |}>, >, |}>; + +export type RNTesterExampleModuleItem = $ReadOnly<{| + title: string, + platform?: string, + description?: string, + render: () => React.Node, +|}>; + +export type RNTesterExampleModule = $ReadOnly<{| + title: string, + description: string, + displayName?: ?string, + framework?: string, + examples: Array, +|}>; + +export type RNTesterExample = $ReadOnly<{| + key: string, + module: RNTesterExampleModule, + supportsTVOS?: boolean, +|}>; diff --git a/RNTester/js/StatusBarExample.js b/RNTester/js/StatusBarExample.js index dece8e23fa2..258215c83f1 100644 --- a/RNTester/js/StatusBarExample.js +++ b/RNTester/js/StatusBarExample.js @@ -21,10 +21,6 @@ const { Modal, } = ReactNative; -exports.framework = 'React'; -exports.title = ''; -exports.description = 'Component for controlling the status bar'; - const colors = ['#ff0000', '#00ff00', '#0000ff', 'rgba(0, 0, 0, 0.4)']; const barStyles = ['default', 'light-content']; @@ -434,7 +430,10 @@ class ModalExample extends React.Component<{}, $FlowFixMeState> { } } -const examples = [ +exports.framework = 'React'; +exports.title = ''; +exports.description = 'Component for controlling the status bar'; +exports.examples = [ { title: 'StatusBar hidden', render() { @@ -496,8 +495,6 @@ const examples = [ }, ]; -exports.examples = examples; - const styles = StyleSheet.create({ container: { flex: 1, diff --git a/RNTester/js/SwipeableFlatListExample.js b/RNTester/js/SwipeableFlatListExample.js index 7cf2a0810dc..feef9fff12a 100644 --- a/RNTester/js/SwipeableFlatListExample.js +++ b/RNTester/js/SwipeableFlatListExample.js @@ -44,9 +44,6 @@ const data = [ ]; class SwipeableFlatListExample extends React.Component { - static title = ''; - static description = 'Performant, scrollable, swipeable list of data.'; - render() { return ( { + return ; + }, + }, +]; diff --git a/RNTester/js/SwipeableListViewExample.js b/RNTester/js/SwipeableListViewExample.js index d8d82306e47..cb54b86d76e 100644 --- a/RNTester/js/SwipeableListViewExample.js +++ b/RNTester/js/SwipeableListViewExample.js @@ -30,13 +30,7 @@ type State = {| dataSource: SwipeableListViewDataSource, |}; -class SwipeableListViewSimpleExample extends React.Component< - RNTesterProps, - State, -> { - static title = ''; - static description = 'Performant, scrollable, swipeable list of data.'; - +class SwipeableListViewExample extends React.Component { state = { dataSource: SwipeableListView.getNewDataSource().cloneWithRowsAndSections( ...this._genDataSource({}), @@ -203,4 +197,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = SwipeableListViewSimpleExample; +exports.title = ''; +exports.description = 'Performant, scrollable, swipeable list of data.'; +exports.examples = [ + { + title: 'Simple swipable list', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/TVEventHandlerExample.js b/RNTester/js/TVEventHandlerExample.js index 4a5dd7ea352..82f2f41755b 100644 --- a/RNTester/js/TVEventHandlerExample.js +++ b/RNTester/js/TVEventHandlerExample.js @@ -15,28 +15,10 @@ const ReactNative = require('react-native'); const {Platform, View, Text, TouchableOpacity, TVEventHandler} = ReactNative; -exports.framework = 'React'; -exports.title = 'TVEventHandler example'; -exports.description = 'iOS alerts and action sheets'; -exports.examples = [ - { - title: 'TVEventHandler', - render() { - return ; - }, - }, -]; - -class TVEventHandlerView extends React.Component< - $FlowFixMeProps, - { - lastEventType: string, - }, -> { - /* $FlowFixMe(>=0.85.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.85 was deployed. To see the error, delete this comment - * and run Flow. */ - constructor(props) { +type Props = $ReadOnly<{||}>; +type State = {|lastEventType: string|}; +class TVEventHandlerView extends React.Component { + constructor(props: Props) { super(props); this.state = { lastEventType: '', @@ -92,3 +74,15 @@ class TVEventHandlerView extends React.Component< } } } + +exports.framework = 'React'; +exports.title = 'TVEventHandler example'; +exports.description = 'iOS alerts and action sheets'; +exports.examples = [ + { + title: 'TVEventHandler', + render() { + return ; + }, + }, +]; diff --git a/RNTester/js/TabBarIOSBarStyleExample.js b/RNTester/js/TabBarIOSBarStyleExample.js index a8dfd135c4e..3456cd42d1d 100644 --- a/RNTester/js/TabBarIOSBarStyleExample.js +++ b/RNTester/js/TabBarIOSBarStyleExample.js @@ -30,10 +30,6 @@ const base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAQAAACSR7JhAAADtUlEQVR4Ac3YA2Bj6QLH0XPT1Fzbtm29tW3btm3bfLZtv7e2ObZnms7d8Uw098tuetPzrxv8wiISrtVudrG2JXQZ4VOv+qUfmqCGGl1mqLhoA52oZlb0mrjsnhKpgeUNEs91Z0pd1kvihA3ULGVHiQO2narKSHKkEMulm9VgUyE60s1aWoMQUbpZOWE+kaqs4eLEjdIlZTcFZB0ndc1+lhB1lZrIuk5P2aib1NBpZaL+JaOGIt0ls47SKzLC7CqrlGF6RZ09HGoNy1lYl2aRSWL5GuzqWU1KafRdoRp0iOQEiDzgZPnG6DbldcomadViflnl/cL93tOoVbsOLVM2jylvdWjXolWX1hmfZbGR/wjypDjFLSZIRov09BgYmtUqPQPlQrPapecLgTIy0jMgPKtTeob2zWtrGH3xvjUkPCtNg/tm1rjwrMa+mdUkPd3hWbH0jArPGiU9ufCsNNWFZ40wpwn+62/66R2RUtoso1OB34tnLOcy7YB1fUdc9e0q3yru8PGM773vXsuZ5YIZX+5xmHwHGVvlrGPN6ZSiP1smOsMMde40wKv2VmwPPVXNut4sVpUreZiLBHi0qln/VQeI/LTMYXpsJtFiclUN+5HVZazim+Ky+7sAvxWnvjXrJFneVtLWLyPJu9K3cXLWeOlbMTlrIelbMDlrLenrjEQOtIF+fuI9xRp9ZBFp6+b6WT8RrxEpdK64BuvHgDk+vUy+b5hYk6zfyfs051gRoNO1usU12WWRWL73/MMEy9pMi9qIrR4ZpV16Rrvduxazmy1FSvuFXRkqTnE7m2kdb5U8xGjLw/spRr1uTov4uOgQE+0N/DvFrG/Jt7i/FzwxbA9kDanhf2w+t4V97G8lrT7wc08aA2QNUkuTfW/KimT01wdlfK4yEw030VfT0RtZbzjeMprNq8m8tnSTASrTLti64oBNdpmMQm0eEwvfPwRbUBywG5TzjPCsdwk3IeAXjQblLCoXnDVeoAz6SfJNk5TTzytCNZk/POtTSV40NwOFWzw86wNJRpubpXsn60NJFlHeqlYRbslqZm2jnEZ3qcSKgm0kTli3zZVS7y/iivZTweYXJ26Y+RTbV1zh3hYkgyFGSTKPfRVbRqWWVReaxYeSLarYv1Qqsmh1s95S7G+eEWK0f3jYKTbV6bOwepjfhtafsvUsqrQvrGC8YhmnO9cSCk3yuY984F1vesdHYhWJ5FvASlacshUsajFt2mUM9pqzvKGcyNJW0arTKN1GGGzQlH0tXwLDgQTurS8eIQAAAABJRU5ErkJggg=='; class TabBarIOSBarStyleExample extends React.Component<{}> { - static title = ' - Custom Bar Style'; - static description = 'Tab-based navigation.'; - static displayName = 'TabBarIOSBarStyleExample'; - render() { return ( @@ -58,4 +54,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = TabBarIOSBarStyleExample; +exports.title = ' - Custom Bar Style'; +exports.description = 'Tab-based navigation.'; +exports.displayName = 'TabBarIOSBarStyleExample'; +exports.examples = [ + { + title: 'Custom tab bar navigation', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/TabBarIOSExample.js b/RNTester/js/TabBarIOSExample.js index 6fc9015ce2e..ea03982d06e 100644 --- a/RNTester/js/TabBarIOSExample.js +++ b/RNTester/js/TabBarIOSExample.js @@ -17,11 +17,14 @@ const {StyleSheet, TabBarIOS, Text, View} = ReactNative; const base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAQAAACSR7JhAAADtUlEQVR4Ac3YA2Bj6QLH0XPT1Fzbtm29tW3btm3bfLZtv7e2ObZnms7d8Uw098tuetPzrxv8wiISrtVudrG2JXQZ4VOv+qUfmqCGGl1mqLhoA52oZlb0mrjsnhKpgeUNEs91Z0pd1kvihA3ULGVHiQO2narKSHKkEMulm9VgUyE60s1aWoMQUbpZOWE+kaqs4eLEjdIlZTcFZB0ndc1+lhB1lZrIuk5P2aib1NBpZaL+JaOGIt0ls47SKzLC7CqrlGF6RZ09HGoNy1lYl2aRSWL5GuzqWU1KafRdoRp0iOQEiDzgZPnG6DbldcomadViflnl/cL93tOoVbsOLVM2jylvdWjXolWX1hmfZbGR/wjypDjFLSZIRov09BgYmtUqPQPlQrPapecLgTIy0jMgPKtTeob2zWtrGH3xvjUkPCtNg/tm1rjwrMa+mdUkPd3hWbH0jArPGiU9ufCsNNWFZ40wpwn+62/66R2RUtoso1OB34tnLOcy7YB1fUdc9e0q3yru8PGM773vXsuZ5YIZX+5xmHwHGVvlrGPN6ZSiP1smOsMMde40wKv2VmwPPVXNut4sVpUreZiLBHi0qln/VQeI/LTMYXpsJtFiclUN+5HVZazim+Ky+7sAvxWnvjXrJFneVtLWLyPJu9K3cXLWeOlbMTlrIelbMDlrLenrjEQOtIF+fuI9xRp9ZBFp6+b6WT8RrxEpdK64BuvHgDk+vUy+b5hYk6zfyfs051gRoNO1usU12WWRWL73/MMEy9pMi9qIrR4ZpV16Rrvduxazmy1FSvuFXRkqTnE7m2kdb5U8xGjLw/spRr1uTov4uOgQE+0N/DvFrG/Jt7i/FzwxbA9kDanhf2w+t4V97G8lrT7wc08aA2QNUkuTfW/KimT01wdlfK4yEw030VfT0RtZbzjeMprNq8m8tnSTASrTLti64oBNdpmMQm0eEwvfPwRbUBywG5TzjPCsdwk3IeAXjQblLCoXnDVeoAz6SfJNk5TTzytCNZk/POtTSV40NwOFWzw86wNJRpubpXsn60NJFlHeqlYRbslqZm2jnEZ3qcSKgm0kTli3zZVS7y/iivZTweYXJ26Y+RTbV1zh3hYkgyFGSTKPfRVbRqWWVReaxYeSLarYv1Qqsmh1s95S7G+eEWK0f3jYKTbV6bOwepjfhtafsvUsqrQvrGC8YhmnO9cSCk3yuY984F1vesdHYhWJ5FvASlacshUsajFt2mUM9pqzvKGcyNJW0arTKN1GGGzQlH0tXwLDgQTurS8eIQAAAABJRU5ErkJggg=='; -class TabBarExample extends React.Component<{}, $FlowFixMeState> { - static title = ''; - static description = 'Tab-based navigation.'; - static displayName = 'TabBarExample'; +type Props = $ReadOnly<{||}>; +type State = {| + selectedTab: string, + notifCount: number, + presses: number, +|}; +class TabBarExample extends React.Component { state = { selectedTab: 'redTab', notifCount: 0, @@ -100,4 +103,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = TabBarExample; +exports.title = ''; +exports.description = 'Tab-based navigation.'; +exports.displayName = 'TabBarExample'; +exports.examples = [ + { + title: 'Simple tab navigation', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/TextExample.android.js b/RNTester/js/TextExample.android.js index a8b23ad87b2..c0f660ecfdd 100644 --- a/RNTester/js/TextExample.android.js +++ b/RNTester/js/TextExample.android.js @@ -17,7 +17,7 @@ const RNTesterBlock = require('./RNTesterBlock'); const RNTesterPage = require('./RNTesterPage'); const TextLegend = require('./Shared/TextLegend'); -class Entity extends React.Component<$FlowFixMeProps> { +class Entity extends React.Component<{|children: React.Node|}> { render() { return ( @@ -26,7 +26,6 @@ class Entity extends React.Component<$FlowFixMeProps> { ); } } - class AttributeToggler extends React.Component<{}, $FlowFixMeState> { state = {fontWeight: 'bold', fontSize: 15}; @@ -71,9 +70,6 @@ class AttributeToggler extends React.Component<{}, $FlowFixMeState> { } class TextExample extends React.Component<{}> { - static title = ''; - static description = 'Base component for rendering styled text.'; - render() { return ( @@ -605,4 +601,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = TextExample; +exports.title = ''; +exports.description = 'Base component for rendering styled text.'; +exports.examples = [ + { + title: 'Basic text', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/TimePickerAndroidExample.js b/RNTester/js/TimePickerAndroidExample.js index e2b56d9dcc6..c14329e10eb 100644 --- a/RNTester/js/TimePickerAndroidExample.js +++ b/RNTester/js/TimePickerAndroidExample.js @@ -22,9 +22,6 @@ const RNTesterBlock = require('./RNTesterBlock'); const RNTesterPage = require('./RNTesterPage'); class TimePickerAndroidExample extends React.Component { - static title = 'TimePickerAndroid'; - static description = 'Standard Android time picker dialog'; - state = { isoFormatText: 'pick a time (24-hour format)', presetHour: 4, @@ -117,4 +114,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = TimePickerAndroidExample; +exports.title = 'TimePickerAndroid'; +exports.description = 'Standard Android time picker dialog'; +exports.examples = [ + { + title: 'Simple time picker', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ToastAndroidExample.android.js b/RNTester/js/ToastAndroidExample.android.js index 7894ba0c3d3..f7e654104cb 100644 --- a/RNTester/js/ToastAndroidExample.android.js +++ b/RNTester/js/ToastAndroidExample.android.js @@ -17,12 +17,8 @@ const {StyleSheet, Text, ToastAndroid, TouchableWithoutFeedback} = ReactNative; const RNTesterBlock = require('RNTesterBlock'); const RNTesterPage = require('RNTesterPage'); -class ToastExample extends React.Component<{}, $FlowFixMeState> { - static title = 'Toast Example'; - static description = - 'Example that demonstrates the use of an Android Toast to provide feedback.'; - state = {}; - +type Props = $ReadOnly<{||}>; +class ToastExample extends React.Component { render() { return ( @@ -123,4 +119,14 @@ const styles = StyleSheet.create({ }, }); -module.exports = ToastExample; +exports.title = 'Toast Example'; +exports.description = + 'Example that demonstrates the use of an Android Toast to provide feedback.'; +exports.examples = [ + { + title: 'Basic toast', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ToolbarAndroidExample.android.js b/RNTester/js/ToolbarAndroidExample.android.js index 84144fa5e90..3abb48a36c0 100644 --- a/RNTester/js/ToolbarAndroidExample.android.js +++ b/RNTester/js/ToolbarAndroidExample.android.js @@ -22,9 +22,6 @@ const Switch = require('Switch'); const ToolbarAndroid = require('ToolbarAndroid'); class ToolbarAndroidExample extends React.Component<{}, $FlowFixMeState> { - static title = ''; - static description = 'Examples of using the Android toolbar.'; - state = { actionText: 'Example app with toolbar component', toolbarSwitch: false, @@ -174,4 +171,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = ToolbarAndroidExample; +exports.title = ''; +exports.description = 'Examples of using the Android toolbar.'; +exports.examples = [ + { + title: 'Basic toolbar', + render: function(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/ViewPagerAndroidExample.android.js b/RNTester/js/ViewPagerAndroidExample.android.js index e9046616072..ebd01df8be8 100644 --- a/RNTester/js/ViewPagerAndroidExample.android.js +++ b/RNTester/js/ViewPagerAndroidExample.android.js @@ -33,7 +33,9 @@ const IMAGE_URIS = [ 'https://apod.nasa.gov/apod/image/1510/lunareclipse_27Sep_beletskycrop4.jpg', ]; -class LikeCount extends React.Component { +type Props = $ReadOnly<{||}>; +type State = {|likes: number|}; +class LikeCount extends React.Component { state = { likes: 7, }; @@ -92,10 +94,6 @@ class ProgressBar extends React.Component { } class ViewPagerAndroidExample extends React.Component { - static title = ''; - static description = - 'Container that allows to flip left and right between child views.'; - state = { page: 0, animationsAreEnabled: true, @@ -291,4 +289,15 @@ const styles = StyleSheet.create({ }, }); -module.exports = ViewPagerAndroidExample; +exports.title = ''; +exports.description = + 'Container that allows to flip left and right between child views.'; + +exports.examples = [ + { + title: 'Basic pager', + render(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/WebSocketExample.js b/RNTester/js/WebSocketExample.js index fdb35ca69ad..82ee4dbc53a 100644 --- a/RNTester/js/WebSocketExample.js +++ b/RNTester/js/WebSocketExample.js @@ -125,9 +125,6 @@ type State = { }; class WebSocketExample extends React.Component { - static title = 'WebSocket'; - static description = 'WebSocket API'; - state: State = { url: DEFAULT_WS_URL, httpUrl: DEFAULT_HTTP_URL, @@ -347,4 +344,13 @@ const styles = StyleSheet.create({ }, }); -module.exports = WebSocketExample; +exports.title = 'WebSocket'; +exports.description = 'WebSocket API'; +exports.examples = [ + { + title: 'Basic websocket', + render(): React.Element { + return ; + }, + }, +]; diff --git a/RNTester/js/createExamplePage.js b/RNTester/js/createExamplePage.js index 271057c3fb6..57037cde057 100644 --- a/RNTester/js/createExamplePage.js +++ b/RNTester/js/createExamplePage.js @@ -13,12 +13,11 @@ const React = require('react'); const RNTesterExampleContainer = require('./RNTesterExampleContainer'); - -import type {ExampleModule} from 'ExampleTypes'; +import type {RNTesterExample} from 'RNTesterTypes'; const createExamplePage = function( title: ?string, - exampleModule: ExampleModule, + exampleModule: RNTesterExample, ): React.ComponentType { class ExamplePage extends React.Component<{}> { render() {