react-native-gesture-handler icon indicating copy to clipboard operation
react-native-gesture-handler copied to clipboard

FlatList refresh control

Open tallen11 opened this issue 7 years ago • 12 comments

Replacing the standard react-native FlatList with the one from this library has made refreshing not work. I'm setting the refreshing and onRefresh props like normal and no refresh control appears. Is there further setup for this library?

tallen11 avatar May 03 '19 14:05 tallen11

Could you add some example? I'm using it and it works okay for me

osdnk avatar May 22 '19 14:05 osdnk

@tallen11 - I had the same issue, appears that the FlatList component from the gesture handler lib doesn't support onRefresh & refreshing props directly on the component, like the RN component. Instead add the RefreshControl element prop to the FlatList component like so:

<FlatList
  refreshControl={
    <RefreshControl
      refreshing={this.state.isRefreshing}
      onRefresh={() => this.refreshMethod()}
    />
  }
/>

harryfinn avatar Jul 05 '19 00:07 harryfinn

I have the same problem.

@osdnk - Let say we have the following: <FlatList data={data} renderItem={renderItem} refreshControl={ <RefreshControl refreshing={refreshing} onRefresh={onRefresh} /> } />;

I've realized that RNGH behaves differently in the two following scenarios:

  1. RefreshControl works if renderItem has the following shape: const renderItem = () => ( <View> <Text>Foo</Text> </View> )

  2. But it doesn't work for the following: const renderItem = () => ( <View> <Text>Foo</Text> <Text>Bar</Text> </View> )

No idea what is causing this though

re-za avatar Nov 18 '20 23:11 re-za

Any answers for this? im having the same issue

haibert avatar Jun 04 '21 19:06 haibert

@tallen11 - I had the same issue, appears that the FlatList component from the gesture handler lib doesn't support onRefresh & refreshing props directly on the component, like the RN component. Instead add the RefreshControl element prop to the FlatList component like so:

<FlatList
  refreshControl={
    <RefreshControl
      refreshing={this.state.isRefreshing}
      onRefresh={() => this.refreshMethod()}
    />
  }
/>

On iOS it worked, but on android it doesn't work (when the list is large).

ireshdudeja avatar Jun 16 '21 12:06 ireshdudeja

Is there any way to solve this problem?

gdoudeng avatar Jun 18 '21 03:06 gdoudeng

@osdnk I am facing the same issue. So pull-to-refresh works perfectly fine on iOS. Although on Android, if the list size is more than the screen-size (basically when scroll shows up) - in that case pull-to-refresh doesn't work. I have setup an Expo snack to reproduce this issue - https://snack.expo.io/@vishalnarkhede/gesture-handler-flatlist-issue

vishalnarkhede avatar Jul 05 '21 11:07 vishalnarkhede

@osdnk This issue should be reopened. On iOS it works, on Android it does not.

swizes avatar Mar 30 '22 14:03 swizes

@vishalnarkhede You should create a new issue for this.

Livijn avatar Apr 26 '22 09:04 Livijn

Still have the issue on android

Fortidude avatar Apr 24 '23 10:04 Fortidude

For those experiencing this issue on Android, ensure that you import RefreshControl from react-native-gesture-handler, not from react-native.

iasinov avatar Nov 28 '23 18:11 iasinov

@iasinov I did try your advice but still the on refresh is not working.

This is my mocked list

import React, { useState } from 'react'
import { FlatList as RNFlatList, View, Text } from 'react-native'
import { FlatList, RefreshControl } from 'react-native-gesture-handler'

const mockData = Array.from({ length: 30 }, (_, i) => ({ id: i + 1, title: `Item ${i + 1}` }))

export const FakeList = () => {
  const [refreshing, setRefreshing] = useState(false)

  const onRefresh = () => {
    setRefreshing(true)
    setTimeout(() => setRefreshing(false), 1000)
  }

  return (
    <FlatList
      data={mockData}
      keyExtractor={(item) => item.id.toString()}
      refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}
      renderItem={({ item }) => (
        <View style={{ padding: 20, borderBottomWidth: 1, borderColor: '#ccc' }}>
          <Text style={{ color: 'black' }}>{item.title}</Text>
        </View>
      )}
    />
  )
}

achtan avatar Mar 12 '25 11:03 achtan