6.0.1 • Published 4 years ago

react-native-bpk-component-flat-list v6.0.1

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
4 years ago

react-native-bpk-component-flat-list

Backpack React Native flat list component.

Installation

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

Usage

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 component.

BpkFlatListItem

PropertyPropTypeRequiredDefault Value
onPressfunctrue-
titlestringtrue-
imageelementfalsenull
selectedboolfalsefalse
titlePropsobjectfalse{}

titleProps

titleProps is passed down to the BpkText used for the title. It accepts anything that React Native's Text component does.

BpkFlatListItemSeparator

Use this as the value for ItemSeparatorComponent.

No props.

BpkFlatListSearchField

This can be used as the value for ListHeaderComponent to allow users to search the list.

It's an instance of React Native's TextInput component and accepts the same props.

BpkFlatListNoResultsText

Use this as the value for ListEmptyComponent. It's generally only needed when the list can be searched.

PropertyPropTypeRequiredDefault Value
childrenNodetrue-

Theme Props

  • flatListSelectedItemColor
6.0.1

4 years ago

6.0.0

4 years ago

5.3.4

4 years ago

5.3.3

4 years ago

5.3.2

4 years ago

5.3.1

4 years ago

5.3.0

4 years ago

5.2.3

4 years ago

5.2.2

4 years ago

5.2.1

4 years ago

5.2.0

4 years ago

5.1.4

4 years ago

5.1.3

4 years ago

5.1.3-alpha.1

4 years ago

5.1.2

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.6

4 years ago

5.0.5

4 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.11

5 years ago

4.0.10

5 years ago

4.0.9

5 years ago

4.0.8

5 years ago

4.0.7

5 years ago

4.0.6

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.0

5 years ago

3.1.13

5 years ago

3.1.12

5 years ago

3.1.11

5 years ago

3.1.10

5 years ago

3.1.9

5 years ago

3.1.8

5 years ago

3.1.7

5 years ago

3.1.6

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.19

5 years ago

3.0.18

5 years ago

3.0.17

5 years ago

3.0.16

5 years ago

3.0.15

5 years ago

3.0.14

5 years ago

3.0.13

5 years ago

3.0.12

5 years ago

3.0.11

5 years ago

3.0.10

5 years ago

3.0.9

5 years ago

3.0.8

5 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.5-beta.1

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago