FlatList refresh control
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?
Could you add some example? I'm using it and it works okay for me
@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()}
/>
}
/>
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:
-
RefreshControl works if renderItem has the following shape:
const renderItem = () => ( <View> <Text>Foo</Text> </View> ) -
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
Any answers for this? im having the same issue
@tallen11 - I had the same issue, appears that the
FlatListcomponent from the gesture handler lib doesn't supportonRefresh&refreshingprops directly on the component, like the RN component. Instead add theRefreshControlelement prop to theFlatListcomponent 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).
Is there any way to solve this problem?
@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
@osdnk This issue should be reopened. On iOS it works, on Android it does not.
@vishalnarkhede You should create a new issue for this.
Still have the issue on android
For those experiencing this issue on Android, ensure that you import RefreshControl from react-native-gesture-handler, not from react-native.
@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>
)}
/>
)
}