66 *
77 * @format
88 * @flow
9+ * @generate -docs
910 */
1011
1112'use strict' ;
@@ -36,41 +37,63 @@ if (Platform.OS === 'android') {
3637
3738type IOSProps = $ReadOnly < { |
3839 /**
39- * The color of the refresh indicator.
40+ The color of the refresh indicator.
41+
42+ @platform ios
4043 */
4144 tintColor ?: ?ColorValue ,
4245 /**
43- * Title color.
46+ The color of the refresh indicator title.
47+
48+ @platform ios
4449 */
4550 titleColor ?: ?ColorValue ,
4651 /**
47- * The title displayed under the refresh indicator.
52+ The title displayed under the refresh indicator.
53+
54+ @platform ios
4855 */
4956 title ?: ?string ,
5057| } > ;
5158
5259type AndroidProps = $ReadOnly < { |
5360 /**
54- * Whether the pull to refresh functionality is enabled.
61+ Whether the pull to refresh functionality is enabled.
62+
63+ @platform android
64+
65+ @default true
5566 */
5667 enabled ?: ?boolean ,
5768 /**
58- * The colors (at least one) that will be used to draw the refresh indicator.
69+ The colors (at least one) that will be used to draw the refresh indicator.
70+
71+ @platform android
5972 */
6073 colors ?: ?$ReadOnlyArray < ColorValue > ,
6174 /**
62- * The background color of the refresh indicator.
75+ The background color of the refresh indicator.
76+
77+ @platform android
6378 */
6479 progressBackgroundColor ?: ?ColorValue ,
6580 /**
66- * Size of the refresh indicator, see RefreshControl.SIZE.
81+ Size of the refresh indicator.
82+
83+ @platform android
84+
85+ @default RefreshLayoutConsts.SIZE.DEFAULT
6786 */
6887 size ?: ?(
6988 | typeof RefreshLayoutConsts . SIZE . DEFAULT
7089 | typeof RefreshLayoutConsts . SIZE . LARGE
7190 ) ,
7291 /**
73- * Progress view top offset
92+ Progress view top offset
93+
94+ @platform android
95+
96+ @default 0
7497 */
7598 progressViewOffset ?: ?number ,
7699| } > ;
@@ -81,60 +104,79 @@ export type RefreshControlProps = $ReadOnly<{|
81104 ...AndroidProps ,
82105
83106 /**
84- * Called when the view starts refreshing.
107+ Called when the view starts refreshing.
85108 */
86109 onRefresh ?: ?( ) => void | Promise < void > ,
87110
88111 /**
89- * Whether the view should be indicating an active refresh.
112+ Whether the view should be indicating an active refresh.
90113 */
91114 refreshing : boolean ,
92115| } > ;
93116
94117/**
95- * This component is used inside a ScrollView or ListView to add pull to refresh
96- * functionality. When the ScrollView is at `scrollY: 0`, swiping down
97- * triggers an `onRefresh` event.
98- *
99- * ### Usage example
100- *
101- * ``` js
102- * class RefreshableList extends Component {
103- * constructor(props) {
104- * super(props);
105- * this.state = {
106- * refreshing: false,
107- * };
108- * }
109- *
110- * _onRefresh() {
111- * this.setState({refreshing: true});
112- * fetchData().then(() => {
113- * this.setState({refreshing: false});
114- * });
115- * }
116- *
117- * render() {
118- * return (
119- * <ListView
120- * refreshControl={
121- * <RefreshControl
122- * refreshing={this.state.refreshing}
123- * onRefresh={this._onRefresh.bind(this)}
124- * />
125- * }
126- * ...
127- * >
128- * ...
129- * </ListView>
130- * );
131- * }
132- * ...
133- * }
134- * ```
135- *
136- * __Note:__ `refreshing` is a controlled prop, this is why it needs to be set to true
137- * in the `onRefresh` function otherwise the refresh indicator will stop immediately.
118+ This component is used inside a ScrollView or ListView to add pull to refresh
119+ functionality. When the ScrollView is at `scrollY: 0`, swiping down
120+ triggers an `onRefresh` event.
121+
122+ ```SnackPlayer name=RefreshControl&supportedPlatforms=ios,android
123+ import React from 'react';
124+ import {
125+ ScrollView,
126+ RefreshControl,
127+ StyleSheet,
128+ Text,
129+ SafeAreaView,
130+ } from 'react-native';
131+ import Constants from 'expo-constants';
132+
133+ const wait = (timeout) => {
134+ return new Promise(resolve => {
135+ setTimeout(resolve, timeout);
136+ });
137+ }
138+
139+ const App = () => {
140+ const [refreshing, setRefreshing] = React.useState(false);
141+
142+ const onRefresh = React.useCallback(() => {
143+ setRefreshing(true);
144+
145+ wait(2000).then(() => setRefreshing(false));
146+ }, []);
147+
148+ return (
149+ <SafeAreaView style={styles.container}>
150+ <ScrollView
151+ contentContainerStyle={styles.scrollView}
152+ refreshControl={
153+ <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
154+ }
155+ >
156+ <Text>Pull down to see RefreshControl indicator</Text>
157+ </ScrollView>
158+ </SafeAreaView>
159+ );
160+ }
161+
162+ const styles = StyleSheet.create({
163+ container: {
164+ flex: 1,
165+ marginTop: Constants.statusBarHeight,
166+ },
167+ scrollView: {
168+ flex: 1,
169+ backgroundColor: 'pink',
170+ alignItems: 'center',
171+ justifyContent: 'center',
172+ },
173+ });
174+
175+ export default App;
176+ ```
177+
178+ > Note: `refreshing` is a controlled prop, this is why it needs to be set to
179+ true in the `onRefresh` function otherwise the refresh indicator will stop immediately.
138180 */
139181class RefreshControl extends React . Component < RefreshControlProps > {
140182 static SIZE : any = RefreshLayoutConsts . SIZE ;
0 commit comments