# react-native-bpk-component-flat-list

> Backpack React Native flat list component.

Latest version **6.0.1** (published 2020-02-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install react-native-bpk-component-flat-list
pnpm add react-native-bpk-component-flat-list
yarn add react-native-bpk-component-flat-list
bun add react-native-bpk-component-flat-list
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2020-02-26 |
| First published | 2018-05-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 107.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 543 |
| Author | Backpack Design System |
| Maintainers | georgegillams, k0nserv, ojcurt, shaundon, tiagohngl |

## Links

- npm: https://www.npmjs.com/package/react-native-bpk-component-flat-list
- Repository: https://github.com/Skyscanner/backpack
- Homepage: https://github.com/Skyscanner/backpack#readme
- Issues: https://github.com/Skyscanner/backpack/issues
- npm.io page: https://npm.io/package/react-native-bpk-component-flat-list

## Dependencies (7)

- [bpk-tokens](https://npm.io/package/bpk-tokens.md) ^32.0.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.5.8
- [react-native-bpk-theming](https://npm.io/package/react-native-bpk-theming.md) ^2.0.1
- [react-native-bpk-component-icon](https://npm.io/package/react-native-bpk-component-icon.md) ^3.0.1
- [react-native-bpk-component-text](https://npm.io/package/react-native-bpk-component-text.md) ^5.0.1
- [react-native-bpk-component-touchable-overlay](https://npm.io/package/react-native-bpk-component-touchable-overlay.md) ^3.0.1
- [react-native-bpk-component-touchable-native-feedback](https://npm.io/package/react-native-bpk-component-touchable-native-feedback.md) ^3.0.1

## Recent versions

- 6.0.1 (latest) — 2020-02-26
- 5.1.3-alpha.1 (canary) — 2019-12-03
- 6.0.0 — 2020-02-19
- 5.3.4 — 2020-02-13
- 5.3.3 — 2020-01-30
- 5.3.2 — 2020-01-22
- 5.3.1 — 2020-01-20
- 5.3.0 — 2019-12-20
- 5.2.3 — 2019-12-17
- 5.2.2 — 2019-12-12
- 5.2.1 — 2019-12-06
- 5.2.0 — 2019-12-05
- 5.1.4 — 2019-12-04
- 5.1.3 — 2019-12-04
- 5.1.2 — 2019-11-29
- … 89 more at https://npm.io/package/react-native-bpk-component-flat-list/versions

## README

# react-native-bpk-component-flat-list

> Backpack React Native flat list component.

## Installation

```sh
npm install react-native-bpk-component-flat-list --save-dev
```


## Usage

```js
import React, { Component } from 'react';
import { Image } from 'react-native';
import BpkFlatList, {
  BpkFlatListItem,
  BpkFlatListItemSeparator,
  BpkFlatListSearchField,
  BpkFlatListNoResultsText,
  } from 'react-native-bpk-component-flat-list';

const COUNTRIES = [
  { id: 'DZ', name: 'Algeria' },
  { id: 'CA', name: 'Canada' },
  { id: 'CD', name: 'Democratic Republic of the Congo' },
  { id: 'IT', name: 'Italy' },
  { id: 'JP', name: 'Japan' },
  { id: 'SE', name: 'Sweden' },
  { id: 'GB', name: 'United Kingdom' },
];

const FLAG_IMAGES = {
  'DZ': '/resources/algeria.png',
  'CA': '/resources/canada.png',
  'CD': '/resources/drcongo.png',
  'IT': '/resources/italy.png',
  'JP': '/resources/japan.png',
  'SE': '/resources/sweden.png',
  'GB': '/resources/uk.png',
};

export default class App extends Component {
  constructor() {
    super();
    this.itemOnPressCallbacks = {};
  }

  getItemOnPressCallback = countryId => {
    this.itemOnPressCallbacks[countryId] =
      this.itemOnPressCallbacks[countryId] ||
      (() => console.log(countryId));
    return this.itemOnPressCallbacks[countryId];
  };

  renderItem = ({ country }) => (
    <BpkFlatListItem
      key={country.id}
      title={country.name}
      image={<Image source={require(FLAG_IMAGES[country.id])} />}
      onPress={this.getItemOnPressCallback(country.id)}
      titleProps={{ weight: 'regular' }}
    />
  );

  filterItems = text => {
    // Logic to filter the data based on user input.
  }

  render() {
    return (
      <BpkFlatList
        data={COUNTRIES}
        renderItem={this.renderItem}
        ItemSeparatorComponent={BpkFlatListItemSeparator}
        ListHeaderComponent={
          <BpkFlatListSearchField
            placeholder="Search countries"
            onChangeText={this.filterItems}
          />
        }
        ListEmptyComponent={
          <BpkFlatListNoResultsText>No results</BpkFlatListNoResultsText>
        }
      />
    );
  }
}
```

## Props

### BpkFlatList

Inherits all props from React Native's [FlatList](https://facebook.github.io/react-native/docs/flatlist.html) component.

### BpkFlatListItem

| Property           | PropType                              | Required | Default Value |
| ------------------ | ------------------------------------- | -------- | ------------- |
| onPress            | func                                  | true     | -             |
| title              | string                                | true     | -             |
| image              | element                               | false    | null          |
| selected           | bool                                  | false    | false         |
| titleProps         | object                                | false    | {}            |

#### `titleProps`

`titleProps` is passed down to the `BpkText` used for the title. It accepts anything that React Native's [`Text` component](https://facebook.github.io/react-native/docs/text.html#props) does.

### BpkFlatListItemSeparator

Use this as the value for [`ItemSeparatorComponent`](https://facebook.github.io/react-native/docs/flatlist#itemseparatorcomponent).

No props.

### BpkFlatListSearchField

This can be used as the value for [`ListHeaderComponent`](https://facebook.github.io/react-native/docs/flatlist#listheadercomponent) to allow users to search the list.

It's an instance of React Native's [`TextInput`](https://facebook.github.io/react-native/docs/textinput) component and accepts the same props.

### BpkFlatListNoResultsText

Use this as the value for [`ListEmptyComponent`](https://facebook.github.io/react-native/docs/flatlist#listemptycomponent). It's generally only needed when the list can be searched.

| Property           | PropType                              | Required | Default Value |
| ------------------ | ------------------------------------- | -------- | ------------- |
| children           | Node                                  | true     | -             |

## Theme Props

* `flatListSelectedItemColor`

---
_Source: https://npm.io/package/react-native-bpk-component-flat-list · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
