Showing a white refresh circle on the top while navigating back from a screen having refresh control in the flatlist. This issue is occuring in the android devices only and not occuring in the android OS 8.
this issue won’t come if i refresh the screen at-least once when mounted and issue won’t come if i comment the refresh control.
i'm attaching the sample code below , please help me to fix this issue.
import * as React from 'react';
import { View, Text, FlatList, StyleSheet, Button, RefreshControl } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
function HomeScreen(props) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Go to Next Screen"
onPress={() => props.navigation.navigate('FlatList')} />
</View>
);
}
const DATA = [
{
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
title: 'First Item',
},
{
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
title: 'Second Item',
},
{
id: '58694a0f-3da1-471f-bd96-145571e29d72',
title: 'Third Item',
},
];
const Item = ({ title }) => (
<View style={styles.item}>
<Text style={styles.title}>{title}</Text>
</View>
);
const FlatListScreen = () => {
const renderItem = ({ item }) => (
<Item title={item.title} />
);
return (
<View style={styles.container}>
<FlatList
data={DATA}
style={{ marginTop: 50 }}
renderItem={renderItem}
keyExtractor={(item, index) => index.toString()}
refreshControl={<RefreshControl
onRefresh={() => { }}
refreshing={false}
/>
}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'black'
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 32,
},
});
const Stack = createNativeStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="FlatList" component={FlatListScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
It seems to be a bug in the RefreshControl. This happens when it's unmounted.
There's an open issue for that: https://github.com/facebook/react-native/issues/34718
Someone posted a workaround: https://github.com/facebook/react-native/issues/34718#issuecomment-1295919690
The issue itself must be solved upstream tough.
Below is the workaround (I changed a bit to allow to specify a custom offset, because I use it in my code):
Then you can use it in your code like: