react-native-inverted-flat-list

1.0.3 • Public • Published

React Native Inverted FlatList

InvertedFlatList enables on pull to refresh functionality. Ideal to use when you need an infinite scrolling list loading more data when the user scrolls to the top using the onPullToRefresh method.

The onEndReached method on <FlatList inverted ... /> cannot be used as it is only called once. This is problematic if the loading of more data fails, for example when there is a network connection problem.

⚠️ WARNING ⚠️

InvertedFlatList enables the onPullToRefresh functionality using the onScroll method on the flatlist. It has not been tested when passing a custom onScroll prop. If you run into any problems using it, please create an issue

Documentation

Install

$ npm install react-native-inverted-flat-list --save

OR

$ yarn add react-native-inverted-flat-list

Example

import React, { Component } from 'react';
import { Text, View } from 'react-native';
import InvertedFlatList from 'react-native-inverted-flat-list';
 
class InfiniteScrollingList extends Component {
  state = {
    refreshing: false,
    // NOTE: The messages should be in reverse order
    messages: [
      { id: '5', text: 'Me too!'},
      { id: '4', text: 'I am fine thanks! How are you?'},
      { id: '3', text: 'How is it going?'},
      { id: '2', text: 'Hey'},
      { id: '1', text: 'Hello'}
    ]
  }
 
  onPullToRefresh = () => {
    const { refreshing, messages } = this.state;
 
    // Return early if already refreshing
    if (refreshing) return;
 
    this.setState({refreshing: true});
 
    // Load more messages
    const moreMessages = ...;
 
    const copyMessages = messages.slice();
    const newMessages = copyMessages.concat(moreMessages);
 
    this.setState({
      refreshing: false,
      messages: newMessages
    });
  }
 
  render() {
    const { messages, refreshing } = this.state;
    return (
      <InvertedFlatList
        refreshing={refreshing} // required
        data={messages} // required
        keyExtractor={item => item.id} // required
        onPullToRefresh={this.onPullToRefresh}
        renderItem={({ item }) => ( // required
          <View>
            <Text>{item.text}</Text>
          </View>
        )}
      />
    )
  }
}
 

Props

  • FlatList props
  • refreshOffset - The offset from the top before onPullToRefresh is triggered
  • onPullToRefresh - Function called when viewer scrolls to top

Example Projects

For projects using react-native-inverted-flat-list

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.3
    16
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.3
    16
  • 1.0.2
    1
  • 1.0.1
    1
  • 1.0.0
    1

Package Sidebar

Install

npm i react-native-inverted-flat-list

Weekly Downloads

19

Version

1.0.3

License

MIT

Unpacked Size

28.4 kB

Total Files

8

Last publish

Collaborators

  • pnicolaou