Code Monkey home page Code Monkey logo

react-native-alphabet-sectionlist's Introduction

Due to ListView is deprecated, This component is based on React Native SectionList.

Install:

npm install react-native-alphabet-sectionlist  --save  

list drag

Usage

The most basic way to use this component is as follows:

<AlphabetSectionList
  data={this.state.data}
  renderItem={this.renderItem}
  renderHeader={this.renderHeader}
  // custom section header
  renderSectionHeader={this.renderSectionHeader}
  // default section header styles
  sectionHeaderStyle={{ paddingVertical: 5 }}
  sectionHeaderTextStyle={{ fontSize: 16, color: 'blue' }}
/>

You can find a more complete example below

Example

import React from 'react';
import {
  View,
  Text,
} from 'react-native';
import AlphabetSectionList from 'react-native-alphabet-sectionlist';

class App extends React.Component {

  constructor(props) {
    super(props);

    this.state = {
      data: {
        'A': [{ name: 'A1' }, { name: 'A2' }, { name: 'A3' }],
        "E": [{ name: 'E1' }, { name: 'E2' }, { name: 'E3' }, { name: 'E4' }],
        'F': [{ name: 'F1' }, { name: 'F2' }, { name: 'F3' }],
        'H': [{ name: 'H1' }, { name: 'H2' }, { name: 'H3' }, { name: 'H5' }],
        'J': [{ name: 'J1' }, { name: 'J2' }, { name: 'J3' }, { name: 'J5' }],
        'K': [{ name: 'K1' }, { name: 'K2' }, { name: 'K3' }, { name: 'K5' }],
        'N': [{ name: 'N1' }, { name: 'N2' }, { name: 'N3' }, { name: 'N5' }],
        'Y': [{ name: 'Y1' }, { name: 'Y2' }, { name: 'Y3' }, { name: 'Y5' }, { name: 'Y6' }],
      },
    }

  }

  renderItem = ({ item }) => {
    return (
      <View style={{
        marginLeft: 10,
        paddingVertical: 10,
        borderBottomColor: 'lightgray',
        borderBottomWidth: 0.5
      }}>
        <Text>{item.name}</Text>
      </View>
    )
  }

  renderHeader = () => {
    return (
      <View>
        <Text>header1</Text>
        <Text>header2</Text>
      </View>
    )
  }

  renderSectionHeader = ({ section: { title } }) => {
    return (
      <View style={{
        paddingLeft: 10,
        backgroundColor: '#f1f2f3',
        paddingVertical: 5,
      }}>
        <Text style={{ color: 'blue' }}>{title}</Text>
      </View>
    )
  }

  render() {
    return (
      <View style={{ flex: 1 }}>
        <AlphabetSectionList
          data={this.state.data}
          renderItem={this.renderItem}
          renderHeader={this.renderHeader}
          // custom section header
          renderSectionHeader={this.renderSectionHeader}
          // default section header styles
          // sectionHeaderStyle={{ paddingVertical: 5 }}
          // sectionHeaderTextStyle={{ fontSize: 16, color: 'blue' }}
        />
      </View>
    )
  }
}

export default App;

react-native-alphabet-sectionlist's People

Contributors

coderjwyang avatar khoitruongg 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.