npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-searchable-list

v1.1.3

Published

A Wrapper around FlatList and SectionList with search feature.

Downloads

347

Readme

react-native-searchable-list

A powerful wrapper around React Native FlatList and SectionList to provide built in search feature. react-native-searchable-list is designed to be simple yet a powerful wrapper around react native's FlatList and SectionList components to provide them with search functionality.

Installation

npm i react-native-searchable-list --save

1. SearchableFlatList

API

| Props | Description | Data Type | isRequired | | ---------------- | ------------------------------------- | ----------------------------------------------------------------------------- | ------------------------ | | data | Data for the FlatList | Array | :white_check_mark: | | searchTerm | Searching Term being input by the user. Typically this will be a state variable bound to a text input | String | :white_check_mark: | | searchAttribute | Attribute to be searched in case of array of objects. This will be empty in case of a simple array data | String | :x: | | ignoreCase | Case sensitive / Case insensitive search. By default this will be set to true | Boolean | :x: |

By default the SearchableFlatList also inherits all the props of a React Native FlatList. You could use virtually any props you would with a FlatList.

Usage

import { SearchableFlatList } from "react-native-searchable-list";

 <SearchableFlatList
          data={this.state.flatListData}
          searchTerm={this.state.searchTerm}
          searchAttribute={this.state.searchAttribute}
          ignoreCase={true}
          renderItem={({ item }) => <Text>{item.name}</Text>}
          keyExtractor={item => item.id}
        />

Example

Github repo with the above examples - https://github.com/Chandrasekar-G/RNSearchableListDemo

1. Simple Array Data

Flat List

Usage

this.state = {
      data: [ "Taj Mahal",   "Great Wall of China", "Machu Picchu", "Christ the Redeemer", "Chichen Itza", "Roman Colosseum", "Petra" ],
      searchTerm: "",
      searchAttribute: "",
      ignoreCase: true
    };
render() {
    const { data, searchTerm, searchAttribute, ignoreCase } = this.state;
    <TextInput
      style={styles.search} placeholder={"Search Wonders"}
      onChangeText={searchTerm => this.setState({ searchTerm })} />

    <SearchableFlatList 
      style={styles.list} data={data}
      searchTerm={searchTerm} ignoreCase={ignoreCase} 
      renderItem={({ item }) => ( <Text style={styles.listItem}>{item}</Text> )}
      keyExtractor={item => item} />
}
2. Array of Objects

Flat List

Usage

this.state = {
      data: [ { id: 1, name: "Taj Mahal", country: "India" },
              { id: 2, name: "Great Wall of China", country: "China" },
              { id: 3, name: "Machu Picchu", country: "Peru" }, 
              { id: 4, name: "Christ the Redeemer", country: "Brazil" },
              { id: 5, name: "Chichen Itza", country: "Mexico" },
              { id: 6, name: "Roman Colosseum", country: "Italy" },
              { id: 7, name: "Petra", country: "Jordan" } ],
      searchTerm: "",
      searchAttribute: "country",
      ignoreCase: true
    };

render() {
    const { data, searchTerm, searchAttribute, ignoreCase } = this.state;
    <TextInput
      style={styles.search} placeholder={"Search Wonder Country"}
      onChangeText={searchTerm => this.setState({ searchTerm })} />

    <SearchableFlatList 
      style={styles.list} data={data} searchTerm={searchTerm}
      searchAttribute={searchAttribute} ignoreCase={ignoreCase}
      renderItem={({ item }) => ( <Text style={styles.listItem}>{item.name}</Text> )}
      keyExtractor={item => item.id} />
}
3. Array of Complex Objects

Flat List

Usage

this.state = {
      data: [
        { id: 1, name: "Taj Mahal", address: {  continent: "Asia", country: "India" } },
        { id: 2, name: "Great Wall of China", address: { continent: "Asia", country: "China" } },
        { id: 3, name: "Machu Picchu", address: { continent: "South America", country: "Peru" } },
        { id: 4, name: "Christ the Redeemer", address: { continent: "South America", country: "Brazil" } },
        { id: 5, name: "Chichen Itza", address: { continent: "South America", country: "Mexico" } },
        { id: 6, name: "Roman Colosseum", address: { continent: "Europe", country: "Italy" } },
        { id: 7, name: "Petra", address: { continent: "Asia", country: "Jordan" } } ],
      searchTerm: "",
      searchAttribute: "address.continent",
      ignoreCase: true
    };

render() {
    const { data, searchTerm, searchAttribute, ignoreCase } = this.state;
    <TextInput
      style={styles.search} placeholder={"Search Wonder Country"}
      onChangeText={searchTerm => this.setState({ searchTerm })} />
    
    <SearchableFlatList
      style={styles.list} data={data} 
      searchTerm={searchTerm} searchAttribute={searchAttribute} 
      ignoreCase={ignoreCase} 
      renderItem={({ item }) => ( <Text style={styles.listItem}>{item.name}</Text> )}
      keyExtractor={item => item.id} />
}

2. SearchableSectionList

API

| Props | Description | Data Type | isRequired | | ---------------- | ------------------------------------- | ----------------------------------------------------------------------------- | ------------------------ | | sections | Data for the SectionList | Array | :white_check_mark: | | searchTerm | Searching Term being input by the user. Typically this will be a state variable bound to a text input | String | :white_check_mark: | | searchByTitle | Search applies to the title instead of the data is set to true. By default this is set to false | Boolean | :x: | | searchAttribute | Attribute to be searched in case of array of objects. This will be empty in case of a simple array data | String | :x: | | ignoreCase | Case sensitive / Case insensitive search. By default this will be set to true | Boolean | :x: |

By default the SearchableSectionList also inherits all the props of a React Native SectionList. You could use virtually any props you would with a SectionList.

Usage

import { SearchableSectionList } from "react-native-searchable-list";

 <SearchableSectionList
          sections={this.state.flatListData}
          searchTerm={this.state.searchTerm}
          searchAttribute={this.state.searchAttribute}
          ignoreCase={true}
          searchByTitle={false}
          renderSectionHeader={({ section: { title } }) => ( <Text style={{ fontWeight: "bold" }}>{title}</Text> )}
          renderItem={({ item }) => ( <Text style={styles.listItem}>{item}</Text> )}
          keyExtractor={item => item}
        />

Example

Github repo with the above examples - https://github.com/Chandrasekar-G/RNSearchableListDemo

1. Simple Array Data

Section List

Usage

this.state = {
      data: [ { title: "Asia", data: ["Taj Mahal", "Great Wall of China", "Petra"] },
              { title: "South America", data: ["Machu Picchu", "Christ the Redeemer", "Chichen Itza"] },
              { title: "Europe", data: ["Roman Colosseum"] } ],
      searchTerm: "",
      searchAttribute: "",
      searchByTitle: false,
      ignoreCase: true
    };

render() {
    const { data, searchTerm, searchByTitle, searchAttribute, ignoreCase } = this.state;
    <TextInput
      style={styles.search} placeholder={"Search Wonders"}
      onChangeText={searchTerm => this.setState({ searchTerm })} />

    <SearchableSectionList
        sections={data} searchTerm={searchTerm}
        ignoreCase={ignoreCase}
        renderSectionHeader={({ section: { title } }) => (
          <Text style={{ fontWeight: "bold" }}>{title}</Text>
        )}
        renderItem={({ item }) => (
          <Text style={styles.listItem}>{item}</Text>
        )}
        keyExtractor={item => item}
    />
}
2. Array of Objects

Section List

Usage

this.state = {
      data: [ { title: "Asia", data: [ { id: 1, name: "Taj Mahal", address: { continent: "Asia", country: "India" } },
                                       { id: 2, name: "Great Wall of China", address: { continent: "Asia", country: "China" } },
                                       { id: 7, name: "Petra", address: { continent: "Asia", country: "Jordan" } } ] },
              { title: "South America", data: [ { id: 3, name: "Machu Picchu", address: { continent: "", country: "Peru" } },
                                                { id: 4, name: "Christ the Redeemer", address: { continent: "South America", country: "Brazil" } },
                                                { id: 5, name: "Chichen Itza", address: { continent: "South America", country: "Mexico" } } ] },
              { title: "Europe", data: [ { id: 6, name: "Roman Colosseum", address: { continent: "Europe", country: "Italy" } } ] } ],
      searchTerm: "",
      searchAttribute: "address.country",
      ignoreCase: true
    };

render() {
    const { data, searchTerm, searchAttribute, ignoreCase } = this.state;
    <TextInput
      style={styles.search} placeholder={"Search Wonder Country"}
      onChangeText={searchTerm => this.setState({ searchTerm })} />

    <SearchableSectionList
      sections={data} searchTerm={searchTerm}
      searchAttribute={searchAttribute} searchByTitle={false}
      ignoreCase={ignoreCase}
      renderSectionHeader={({ section: { title } }) => (
        <Text style={{ fontWeight: "bold" }}>{title}</Text>
      )}
      renderItem={({ item }) => (
        <Text style={styles.listItem}>{item.name}</Text>
      )}
      keyExtractor={item => item.id}
    />
}
3. Search By Title

Section List

Usage

this.state = {
      data: [ { title: "Asia", data: ["Taj Mahal", "Great Wall of China", "Petra"] },
              { title: "South America", data: ["Machu Picchu", "Christ the Redeemer", "Chichen Itza"] },
              { title: "Europe", data: ["Roman Colosseum"] } ],
      searchTerm: "",
      searchAttribute: "",
      searchByTitle: true,
      ignoreCase: true
    };

render() {
    const { data, searchTerm, searchAttribute, ignoreCase } = this.state;
    <TextInput
      style={styles.search} placeholder={"Search Wonder Country"}
      onChangeText={searchTerm => this.setState({ searchTerm })} />
    
    <SearchableSectionList
      sections={data} searchTerm={searchTerm}
      searchAttribute={searchAttribute} searchByTitle={searchByTitle}
      ignoreCase={ignoreCase}
      renderSectionHeader={({ section: { title } }) => (
        <Text style={{ fontWeight: "bold" }}>{title}</Text>
      )}
      renderItem={({ item }) => (
        <Text style={styles.listItem}>{item}</Text>
      )}
      keyExtractor={item => item}
    />
}