I am implementing pagination in react native app my Web API is giving total record size and option to send page no as a parameter. www.URL.com/api/GetAll?pageNo={pageNumber}. Currently I'm using the standard approach i.e:
let pageNumbers = TotalRecords/PageSize;
for(i=0; i<pageNumbers; i++)
{
pageNumberArray[i] = i + 1;
}
this.setstate({pageNumber: pageNumberArray})
render()
{
this.state.data.map(function (data, index)
{
<Card>
<CardItem>
<Text>SHOWING DATA HERE {data.Title}</Text>
</CardItem>
</Card>
}
{/*SHOWING PAGE NUMBERS*/}
{this.state.totalRecrods > 1 &&
<View>
<FlatList
height={50}
style={{padding:10}}
data={ this.state.pageNumber }
renderItem={({item}) => <Text style={{backgroundColor:'rgb(191, 219,215)', margin:5,height:50}}>{item}</Text>}
keyExtractor={(item, index) => index}
horizontal={true}
/>
</View>
}
}
Now I have standard page numbers and on click on every page number I called the URL again with respective page number and update the data state that shows next 50 records.
The issue is I don’t like this traditional approach in mobile app. I want to implement the Card View such that on scroll it automatically loads another 50 records. Not showing page numbers to the user and saving all time clicking on page number to go to next page.