Code Monkey home page Code Monkey logo

react-native-search-list's Introduction

A searchable ListView which supports Chinese PinYin and alphabetical index.

npm version FOSSA Status Standard - JavaScript Style Guide Open Source Love

React Native Search List

A searchable ListView which supports Chinese PinYin and alphabetical index.

The following pic may be helpful when understanding the structure and APIs:

Installation

$ npm install @unpourtous/react-native-search-list --save

Usage

To Use SearchList, need a array of object as data source,and each object has searchStr property, eample code are put in ./entry.js.

export default class example extends Component {
  constructor (props) {
    super(props)
    this.state = {
      dataSource: demoList
    }
  }

  // custom render row
  renderRow (item, sectionID, rowID, highlightRowFunc, isSearching) {
    return (
      <Touchable onPress={() => {
        Alert.alert('Clicked!', `sectionID: ${sectionID}; item: ${item.searchStr}`,
          [
            {text: 'OK', onPress: () => console.log('OK Pressed')},
          ],
          {cancelable: true})
      }}>
        <View key={rowID} style={{flex: 1, marginLeft: 20, height: rowHeight, justifyContent: 'center'}}>
          {/*use `HighlightableText` to highlight the search result*/}
          <HighlightableText
            matcher={item.matcher}
            text={item.searchStr}
            textColor={'#000'}
            hightlightTextColor={'#0069c0'}
          />
        </View>
      </Touchable>
    )
  }

  // render empty view when datasource is empty
  renderEmpty () {
    return (
      <View style={styles.emptyDataSource}>
        <Text style={{color: '#979797', fontSize: 18, paddingTop: 20}}> No Content </Text>
      </View>
    )
  }

  // render empty result view when search result is empty
  renderEmptyResult (searchStr) {
    return (
      <View style={styles.emptySearchResult}>
        <Text style={{color: '#979797', fontSize: 18, paddingTop: 20}}> No Result For <Text
          style={{color: '#171a23', fontSize: 18}}>{searchStr}</Text></Text>
        <Text style={{color: '#979797', fontSize: 18, alignItems: 'center', paddingTop: 10}}>Please search again</Text>
      </View>
    )
  }

  render () {
    return (
      <View style={styles.container}>
        <StatusBar backgroundColor='#F00' barStyle='light-content' />
        <SearchList
          data={this.state.dataSource}
          renderRow={this.renderRow.bind(this)}
          renderEmptyResult={this.renderEmptyResult.bind(this)}
          renderBackButton={() => null}
          renderEmpty={this.renderEmpty.bind(this)}

          rowHeight={rowHeight}

          toolbarBackgroundColor={'#2196f3'}
          title='Search List Demo'
          cancelTitle='取消'
          onClickBack={() => {}}

          searchListBackgroundColor={'#2196f3'}

          searchBarToggleDuration={300}

          searchInputBackgroundColor={'#0069c0'}
          searchInputBackgroundColorActive={'#6ec6ff'}
          searchInputPlaceholderColor={'#FFF'}
          searchInputTextColor={'#FFF'}
          searchInputTextColorActive={'#000'}
          searchInputPlaceholder='Search'
          sectionIndexTextColor={'#6ec6ff'}
          searchBarBackgroundColor={'#2196f3'}
        />
      </View>
    )
  }
}

APIs

prop name type description default value
data array The rows of list view.each object should contain searchStr, it will be used for search source. If you have custom row id,you should set searchKey for each object.
renderRow number Render your custom row content.
rowHeight number The height of the default row content, it will be used for scroll calculate. 40
sectionHeaderHeight number The height of section header content. 24
searchListBackgroundColor string BackgroundColor for searchList. #171a23
toolbarBackgroundColor string Toolbar background color. #171a23
searchBarToggleDuration number Custom search bar animation duration. 300
searchBarBackgroundColor string Custom search bar background color. #171a23
searchInputBackgroundColor string Custom search input default state background color.
searchInputBackgroundColorActive string Custom search input searching state background color.
searchInputPlaceholder string Custom search input placeholder text.
searchInputPlaceholderColor string Custom search input placeholder text color.
searchInputTextColor string Custom search input default state text color.
searchInputTextColorActive string Custom search input searching state text color.
searchBarBackgroundColor string Custom search bar background color.
title string Toolbar title.
titleTextColor string Toolbar title text color.
cancelTextColor string Search bar cancel text color.
cancelTitle string Search bar cancel text color.
sectionIndexTextColor string Section index text color.
hideSectionList bool Whether to hide the alphabetical section listing view or not.
renderSectionIndexItem func Custom render SectionIndexItem.
sortFunc func The sort function for the list view data source,sorting alphabetical by default
resultSortFunc func The sort function for the search result,sorting first match position by default
onScrollToSection func The callback of alphabetical section view be clicked or touch.
renderBackButton func Render a custom back buttom on Toolbar.
renderEmpty func Render a view when data is empty.
renderEmptyResult func Render a view when search result is empty.
renderSeparator func Render row separator.
renderSectionHeader func renderSectionHeader for the internal ListView
renderHeader func renderHeader for the internal ListView
renderFooter func renderFooter for the internal ListView
renderRow func renderRow for the internal ListView
onSearchStart func Callback when searching start.
onSearchEnd func Callback when searching end.

Thanks

TODO

  1. add hightlight demo
  2. test ios & android & android with status bar and without

Our Other Projects

License

This library is distributed under MIT Licence.

react-native-search-list's People

Contributors

erichua23 avatar fossabot avatar haywoodfu avatar mariorozic avatar rcrab avatar tong233 avatar vengean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-search-list's Issues

Use 2 HighlightableTexts

Hi!
My rows includes a title and a subtitle

I’d like the search to take into account both – which I was able to do. What I wasn’t able to achieve is to use 2 HighlightableTexts – and highlight only the relevant one (what it does now is highlighting on both indexes)

Is it possible?

Thanks!

How can I select a row i need selected items

Is there any option ?? I am getting selected items but i cannot add Active class to it ..

I have added a indexNum and isSelected(bool) to my array

renderRow (item, sectionID, rowID, highlightRowFunc, isSearching) {
          return (
            <Touchable onPress={() => {
              this.addToSelectedItem(item.indexNum);
            }}>
              <View key={rowID} style={{flex: 1, marginLeft: 20, height: rowHeight, justifyContent: 'center'}}>
                  <View style={this.state.dataSource[item.indexNum].isSelected ? {backgroundColor:'red'} : null}>
                    <HighlightableText
                      matcher={item.matcher}
                      text={item.searchStr}
                      textColor={'#000'}
                      hightlightTextColor={'#0069c0'}
                    />
                  </View>

              </View>
            </Touchable>
          )
        }

it is selecting after a hot re-load .

Hide Toolbar

Hello,
I'm building an address book application on RN. Just for info, the app will be released in GPL3.
I'm using this component as the main list.
Because I'm using react-nativation, i would like to know if is possible to hide the toolbar, or to add this feature in the next release.
Thank you for your job on this project!

There are not any func of Cancel ?

Hi,
Please add the func for cancel event. I found but there are not any func. Also when user click on cancel then clear searchField blank.

FlatList compatibility

Hi there, is there any planning to support flatlist instead of ListView? As far as I am concerned ListView load all the data into the memory and not only what it is been rendered.
Nice work by the way!

安装失败

npm install @unpourtous/react-native-search-list --save
一堆 error

ios Cancel out of the screen

image1 1

Maybe we could remove the cancel if the search input is not selected. and only display the cancel button when it's needed.

Example

This is not really an issue but also this is missing an example so I cant see exactly whats going on. Ive managed to get it to pull data from an external file but how to link the row to its prop and pass to another page.

PropTypes error

Getting a PropTypes error when trying to load the example with the latest version of RN.

undefined is not an object (evaluating '_react3.default.PropTypes.bool')

CustomSearchBar.js:21:42

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.