From 552cbce29c06a4291f0175004ccc4f9d95499dba Mon Sep 17 00:00:00 2001 From: Aniket Kumar Date: Mon, 22 Jun 2020 04:02:28 +0530 Subject: [PATCH] Update RefreshControl for auto doc-gen --- .../RefreshControl/RefreshControl.js | 148 +++++++++++------- 1 file changed, 95 insertions(+), 53 deletions(-) diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index a85c820791d1e1..810cc55ae8fc0d 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -6,6 +6,7 @@ * * @format * @flow + * @generate-docs */ 'use strict'; @@ -36,41 +37,63 @@ if (Platform.OS === 'android') { type IOSProps = $ReadOnly<{| /** - * The color of the refresh indicator. + The color of the refresh indicator. + + @platform ios */ tintColor?: ?ColorValue, /** - * Title color. + The color of the refresh indicator title. + + @platform ios */ titleColor?: ?ColorValue, /** - * The title displayed under the refresh indicator. + The title displayed under the refresh indicator. + + @platform ios */ title?: ?string, |}>; type AndroidProps = $ReadOnly<{| /** - * Whether the pull to refresh functionality is enabled. + Whether the pull to refresh functionality is enabled. + + @platform android + + @default true */ enabled?: ?boolean, /** - * The colors (at least one) that will be used to draw the refresh indicator. + The colors (at least one) that will be used to draw the refresh indicator. + + @platform android */ colors?: ?$ReadOnlyArray, /** - * The background color of the refresh indicator. + The background color of the refresh indicator. + + @platform android */ progressBackgroundColor?: ?ColorValue, /** - * Size of the refresh indicator, see RefreshControl.SIZE. + Size of the refresh indicator. + + @platform android + + @default RefreshLayoutConsts.SIZE.DEFAULT */ size?: ?( | typeof RefreshLayoutConsts.SIZE.DEFAULT | typeof RefreshLayoutConsts.SIZE.LARGE ), /** - * Progress view top offset + Progress view top offset + + @platform android + + @default 0 */ progressViewOffset?: ?number, |}>; @@ -81,60 +104,79 @@ export type RefreshControlProps = $ReadOnly<{| ...AndroidProps, /** - * Called when the view starts refreshing. + Called when the view starts refreshing. */ onRefresh?: ?() => void | Promise, /** - * Whether the view should be indicating an active refresh. + Whether the view should be indicating an active refresh. */ refreshing: boolean, |}>; /** - * This component is used inside a ScrollView or ListView to add pull to refresh - * functionality. When the ScrollView is at `scrollY: 0`, swiping down - * triggers an `onRefresh` event. - * - * ### Usage example - * - * ``` js - * class RefreshableList extends Component { - * constructor(props) { - * super(props); - * this.state = { - * refreshing: false, - * }; - * } - * - * _onRefresh() { - * this.setState({refreshing: true}); - * fetchData().then(() => { - * this.setState({refreshing: false}); - * }); - * } - * - * render() { - * return ( - * - * } - * ... - * > - * ... - * - * ); - * } - * ... - * } - * ``` - * - * __Note:__ `refreshing` is a controlled prop, this is why it needs to be set to true - * in the `onRefresh` function otherwise the refresh indicator will stop immediately. + This component is used inside a ScrollView or ListView to add pull to refresh + functionality. When the ScrollView is at `scrollY: 0`, swiping down + triggers an `onRefresh` event. + + ```SnackPlayer name=RefreshControl&supportedPlatforms=ios,android + import React from 'react'; + import { + ScrollView, + RefreshControl, + StyleSheet, + Text, + SafeAreaView, + } from 'react-native'; + import Constants from 'expo-constants'; + + const wait = (timeout) => { + return new Promise(resolve => { + setTimeout(resolve, timeout); + }); + } + + const App = () => { + const [refreshing, setRefreshing] = React.useState(false); + + const onRefresh = React.useCallback(() => { + setRefreshing(true); + + wait(2000).then(() => setRefreshing(false)); + }, []); + + return ( + + + } + > + Pull down to see RefreshControl indicator + + + ); + } + + const styles = StyleSheet.create({ + container: { + flex: 1, + marginTop: Constants.statusBarHeight, + }, + scrollView: { + flex: 1, + backgroundColor: 'pink', + alignItems: 'center', + justifyContent: 'center', + }, + }); + + export default App; + ``` + + > Note: `refreshing` is a controlled prop, this is why it needs to be set to + true in the `onRefresh` function otherwise the refresh indicator will stop immediately. */ class RefreshControl extends React.Component { static SIZE: any = RefreshLayoutConsts.SIZE;