All Projects → cooperka → React Native Immutable List View

cooperka / React Native Immutable List View

Licence: mit
📜 Drop-in replacement for ListView, FlatList, and VirtualizedList.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Immutable List View

next-react-boilerplate
🔥 NextJS with additional tech feature like react-boilerplate. Demo >>
Stars: ✭ 20 (-90.29%)
Mutual labels:  immutable, immutablejs
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (+13.11%)
Mutual labels:  immutable, immutablejs
extendable-immutable
Wrapper classes around Immutable.js that turn it inheritable
Stars: ✭ 58 (-71.84%)
Mutual labels:  immutable, immutablejs
react-redux-immutable-webpack-ssr-starter
React + React-Router 4 + Redux + ImmutableJS + Bootstrap + webpack 3 with with Server side rendering, Hot Reload and redux-devtools STARTER
Stars: ✭ 21 (-89.81%)
Mutual labels:  immutable, immutablejs
json-immutable
Immutable.JS structure-aware JSON serializer/deserializer
Stars: ✭ 23 (-88.83%)
Mutual labels:  immutable, immutablejs
Switzerland
🇨🇭Switzerland takes a functional approach to Web Components by applying middleware to your components. Supports Redux, attribute mutations, CSS variables, React-esque setState/state, etc… out-of-the-box, along with Shadow DOM for style encapsulation and Custom Elements for interoperability.
Stars: ✭ 261 (+26.7%)
Mutual labels:  immutable, component
universal-routed-flux-demo
The code in this repo is intended for people who want to get started building universal flux applications, with modern and exciting technologies such as Reactjs, React Router and es6.
Stars: ✭ 31 (-84.95%)
Mutual labels:  immutable, immutablejs
Typed Immutable
Immutable and structurally typed data
Stars: ✭ 263 (+27.67%)
Mutual labels:  immutable, immutablejs
Form
The Form component allows you to easily create, process and reuse HTML forms.
Stars: ✭ 2,406 (+1067.96%)
Mutual labels:  component
Vue Upload Component
Vue.js file upload component, Multi-file upload, Upload directory, Drag upload, Drag the directory, Upload multiple files at the same time, html4 (IE 9), `PUT` method, Customize the filter
Stars: ✭ 2,422 (+1075.73%)
Mutual labels:  component
Inflector
Inflector converts words between their singular and plural forms (English only).
Stars: ✭ 2,232 (+983.5%)
Mutual labels:  component
Brouter
Stars: ✭ 198 (-3.88%)
Mutual labels:  component
Komponents Deprecated
📦 React-inspired UIKit Components - ⚠️ Deprecated
Stars: ✭ 202 (-1.94%)
Mutual labels:  component
Malagu
Malagu Development Framework (QQ: 1013685855 钉钉群:31992376)
Stars: ✭ 196 (-4.85%)
Mutual labels:  component
Smilerefresh
微笑下拉刷新。这是在 SwipeRefreshLayout基础上修改的下拉刷新库。
Stars: ✭ 203 (-1.46%)
Mutual labels:  listview
Stopwatch
The Stopwatch component provides a way to profile code.
Stars: ✭ 2,388 (+1059.22%)
Mutual labels:  component
Property Access
The PropertyAccess component provides function to read and write from/to an object or array using a simple string notation.
Stars: ✭ 2,362 (+1046.6%)
Mutual labels:  component
Vue Easytable
🍉 Table Component/ Data Grid / Data Table.Support Virtual Scroll,Column Fixed,Header Fixed,Header Grouping,Filter,Sort,Cell Ellipsis,Row Expand,Row Checkbox ...
Stars: ✭ 2,501 (+1114.08%)
Mutual labels:  component
Navigation Stack
NavigationStack is a stack-modeled UI navigation controller. Swift UI library made by @Ramotion
Stars: ✭ 2,289 (+1011.17%)
Mutual labels:  component
Expression Language
The ExpressionLanguage component provides an engine that can compile and evaluate expressions.
Stars: ✭ 2,418 (+1073.79%)
Mutual labels:  component

React Native Immutable ListView

Build status npm downloads npm version Latest GitHub tag


Logo


Drop-in replacement for React Native's ListView, FlatList, and VirtualizedList.

ImmutableListView screenshot

It supports Immutable.js to give you faster performance and less headaches.

Motivation

  • Do you use Immutable data, only to write the same boilerplate over and over in order to display it?
  • Do you want to show 'Loading...', 'No results', and 'Error!' states in your lists?
  • Do you have nested objects in your state so a shallow diff won't cut it for pure rendering?
  • Do you want better performance while animating screen transitions?

If you answered yes to ANY of these questions, this project can help. Check out the examples below.

How it works

For FlatList and VirtualizedList:

<ImmutableVirtualizedList
  immutableData={this.state.listData}
  renderItem={this.renderItem}
/>

For ListView (deprecated as of React Native v0.59):

<ImmutableListView
  immutableData={this.state.listData}
  renderRow={this.renderRow}
/>

The screenshot above shows two different lists. The first uses this data:

Immutable.fromJS({
  'Section A': [
    'foo',
    'bar',
  ],
  'Section B': [
    'fizz',
    'buzz',
  ],
})

The second list is even simpler:

Immutable.Range(1, 100)

There's an example app here if you'd like to see it in action.

Installation

  1. Install:

    • Using npm: npm install react-native-immutable-list-view --save
    • Using Yarn: yarn add react-native-immutable-list-view
  2. Import it in your JS:

    For FlatList and VirtualizedList:

    import { ImmutableVirtualizedList } from 'react-native-immutable-list-view';
    

    For ListView:

    import { ImmutableListView } from 'react-native-immutable-list-view/lib/ImmutableListView';
    

Example usage -- replacing FlatList

Goodbye, keyExtractor boilerplate!

Note: This example diff looks much better on GitHub than on npm's site. Red means delete, green means add.

-import { Text, View, FlatList } from 'react-native';
+import { Text, View } from 'react-native';
+import { ImmutableVirtualizedList } from 'react-native-immutable-list-view';

 import style from './styles';
 import listData from './listData';

 class App extends Component {

   renderItem({ item, index }) {
     return <Text style={style.row}>{item}</Text>;
   }

  render() {
    return (
      <View style={style.container}>
         <Text style={style.welcome}>
           Welcome to React Native!
         </Text>
-        <FlatList
-          data={listData}
-          getItem={(items, index) => items.get(index)}
-          getItemCount={(items) => items.size}
-          keyExtractor={(item, index) => String(index)}
+        <ImmutableVirtualizedList
+          immutableData={listData}
           renderItem={this.renderItem}
         />
      </View>
    );
  }

}

Example usage -- replacing ListView

You can remove all that boilerplate in your constructor, as well as lifecycle methods like componentWillReceiveProps if all they're doing is updating your dataSource. ImmutableListView will handle all of this for you.

Note: This example diff looks much better on GitHub than on npm's site. Red means delete, green means add.

-import { Text, View, ListView } from 'react-native';
+import { Text, View } from 'react-native';
+import { ImmutableListView } from 'react-native-immutable-list-view/lib/ImmutableListView';

 import style from './styles';
 import listData from './listData';

 class App extends Component {

-  constructor(props) {
-    super(props);
-
-    const dataSource = new ListView.DataSource({
-      rowHasChanged: (r1, r2) => r1 !== r2,
-      sectionHeaderHasChanged: (s1, s2) => s1 !== s2,
-    });
-
-    const mutableData = listData.toJS();
-
-    this.state = {
-      dataSource: dataSource.cloneWithRowsAndSections(mutableData),
-    };
-  }
-
-  componentWillReceiveProps(newProps) {
-    this.setState({
-      dataSource: this.state.dataSource.cloneWithRows(newProps.listData),
-    });
-  }
-
   renderRow(rowData) {
     return <Text style={style.row}>{rowData}</Text>;
   }

  renderSectionHeader(sectionData, category) {
    return <Text style={style.header}>{category}</Text>;
  }

  render() {
    return (
      <View style={style.container}>
         <Text style={style.welcome}>
           Welcome to React Native!
         </Text>
-        <ListView
-          dataSource={this.state.dataSource}
+        <ImmutableListView
+          immutableData={listData}
           renderRow={this.renderRow}
           renderSectionHeader={this.renderSectionHeader}
         />
      </View>
    );
  }

}

Customization

All the props supported by React Native's underlying List are simply passed through, and should work exactly the same. You can see all the VirtualizedList props or ListView props on React Native's website.

You can customize the look of your list by implementing renderItem for FlatList and VirtualizedList or renderRow for ListView.

Here are the additional props that ImmutableVirtualizedList and ImmutableListView accept:

Prop name Data type Default value? Description
immutableData Any Immutable.Iterable Required. The data to render. See below for some examples.
rowsDuringInteraction number undefined How many rows of data to initially display while waiting for interactions to finish (e.g. Navigation animations).
sectionHeaderHasChanged func (prevSectionData, nextSectionData) => false Only needed if your section header is dependent on your row data (uncommon; see ListViewDataSource's constructor for details).
renderEmpty string or func undefined If your data is empty (e.g. null, [], {}) and this prop is defined, then this will be rendered instead. Pull-refresh and scrolling functionality will be lost. Most of the time you should use renderEmptyInList instead.
renderEmptyInList string or func 'No data.' If your data is empty (e.g. null, [], {}) and this prop is defined, then this will be rendered instead. Pull-refresh and scrolling functionality will be kept! See below for more details.

Also see React Native's FlatListExample for more inspiration.

Methods

Methods such as scrollToEnd are passed through just like the props described above. You can read about them here for ListView or here for FlatList and VirtualizedList.

The references to the raw VirtualizedList or ListView component are available via getVirtualizedList() or getListView(). These references allow you to access any other methods on the underlying List that you might need.

How to format your data

ImmutableListView accepts several standard formats for list data. Here are some examples:

List

[rowData1, rowData2, ...]

Map of Lists

{
    section1: [
        rowData1,
        rowData2,
        ...
    ],
    ...
}

Map of Maps

{
    section1: {
        rowId1: rowData1,
        rowId2: rowData2,
        ...
    },
    ...
}

To try it out yourself, you can use the example app!

Support is coming soon for section headers with ImmutableVirtualizedList too, similar to SectionList. See PR #34.

Loading / Empty / Error states

The optional renderEmptyInList prop takes a string and renders an Immutable List displaying the text you specified. By default, this text is simply No data., but you can customize this based on your state. For example:

render() {
  const emptyText = this.state.isLoading
    ? "Loading..."
    : this.state.errorMsg
      ? "Error!"
      : "No data.";

  return (
    <ImmutableVirtualizedList
      immutableData={this.state.listData}
      renderItem={this.renderItem}
      renderEmptyInList={emptyText}
    />
  );
}

The empty list will receive all the same props as your normal list, so things like pull-to-refresh will still work.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].