Git Product home page Git Product logo

react-native-reversed-flat-list's Introduction

react-native-reversed-flat-list

A reversed React Native FlatList, useful for creating performant bottom-anchored lists for chats and whatnot

Demo

⚠️ DEPRECATED ⚠️

React Native FlatList now supports reversed rendering out of the box using the inverted prop:

  <FlatList inverted {...} />

I recommend using it instead. Documentation below for legacy maintenance purposes.

Documentation

Use exactly like you would use FlatList.

- import {FlatList} from 'react-native';
+ import ReversedFlatList from 'react-native-reversed-flat-list';

const MessageList = ({ messages, renderMessage }) => (
-  <FlatList
+  <ReversedFlatList
    data={messages}
    renderItem={renderMessage}
  />
);

This component has not been tested with all the different options, bells and whistles of FlatList. If you hit a use case that doesn't work, please submit a Pull Request!

Known issues

How does it work

aka. The One Weird Trick They Don't Want You To Know About Making Performant Reverse Lists in React Native

I learned the basic mechanism from expo/react-native-invertible-scroll-view. The trick is to scale transform the FlatList's backing ScrollView to -1 in order to flip it on it's horizontal vertical axis, causing the list to look upside-down-mirrored. We then perform the same flip for each row within the list to turn them back the right way around. (To make it more natural to use the component with time-ordered datasets (oldest first), we also reverse the dataset.)

const styles = StyleSheet.create({
  flip: {
    transform: [{ scaleY: -1 }]
  }
});

Surprisingly, this works well, fast and reliably.

Attribution

License

MIT licensed

react-native-reversed-flat-list's People

Contributors

clauderic avatar danielmschmidt avatar jevakallio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.