Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull To Refresh without FlatList

Tags:

react-native

I have a View that renders dynamic cards from an API

<View>
 <Card>1</Card>
 <Card>2</Card>
 <Card>3</Card>
</View>

Is there a way to do a pull-to-refresh on this view?

Make a call to the server and refresh this view without a FlatList component?

like image 318
Hector Avatar asked Mar 16 '18 16:03

Hector


People also ask

How do you make a pull to refresh react native?

Pull to Refresh functionality is implemented using RefreshControl component in React Native. RefreshControl 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.

How do I automatically refresh a page in react native?

Fast Refresh is a React Native feature that allows you to get near-instant feedback for changes in your React components. Fast Refresh is enabled by default, and you can toggle "Enable Fast Refresh" in the React Native developer menu. With Fast Refresh enabled, most edits should be visible within a second or two.

Which prop is used to set whether RefreshControl is refreshing or not?

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.

What is pull down to refresh?

Pull-to-refresh lets a user pull down on a list of data using touch in order to retrieve more data. Pull-to-refresh is widely used on devices with a touch screen.


1 Answers

React-Native's RefreshControl can only be applied to a ScrollView. (Note that a FlatList is actually a ScrollView).

So wrap your <Card />'s in a <ScrollView> rather than a <View> and you can apply the RefreshControl to it as seen in the docs.

Here is an example Snack for you: https://snack.expo.io/Hk606OYKM

like image 163
MattyK14 Avatar answered Nov 15 '22 08:11

MattyK14