I have a flat list with some hardcoded data. How can I implement the Activity indicator to spin and to be displayed until the flat list data is completely displayed on the screen? Below is my code. Thanks
import React, {useState} from 'react';
import { View, FlatList, TouchableOpacity, ActivityIndicator } from 'react-native';
import { MainScreenCard } from '../mainScreen.components/mainScreen.card';
import { Spacer } from '../assets.driveAround/spacer';
export const MainScreen = ({navigation}) => {
return(
<>
<FlatList
data={[
{ name: 1 },
{ name: 2 },
{ name: 3 },
{ name: 4 }
]}
renderItem={() => (
<TouchableOpacity onPress={() => navigation.navigate("Login")}>
<Spacer position="bottom" size="large">
<MainScreenCard/>
</Spacer>
</TouchableOpacity>
)}
keyExtractor={(item) => item.name}
contentContainerStyle={{ padding: 16 }}
/>
</>
);
}
There are two main options depending on how you want to refresh. If you want to pull from the top of the screen to refresh provide it a refresh control https://reactnative.dev/docs/refreshcontrol
Otherwise, another simple option is to use an ActivityIndicator to show a spinner overtop of the view https://reactnative.dev/docs/activityindicator