@unpourtous/react-native-search-list

A searchable ListView which supports Chinese PinYin and alphabetical index.

Showing:

Popularity

Downloads/wk

48

GitHub Stars

155

Maintenance

Last Commit

2yrs ago

Contributors

15

Package

Dependencies

5

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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 nametypedescriptiondefault value
dataarrayThe 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.
renderRownumberRender your custom row content.
rowHeightnumberThe height of the default row content, it will be used for scroll calculate.40
sectionHeaderHeightnumberThe height of section header content.24
searchListBackgroundColorstringBackgroundColor for searchList.#171a23
toolbarBackgroundColorstringToolbar background color.#171a23
searchBarToggleDurationnumberCustom search bar animation duration.300
searchBarBackgroundColorstringCustom search bar background color.#171a23
searchInputBackgroundColorstringCustom search input default state background color.
searchInputBackgroundColorActivestringCustom search input searching state background color.
searchInputPlaceholderstringCustom search input placeholder text.
searchInputPlaceholderColorstringCustom search input placeholder text color.
searchInputTextColorstringCustom search input default state text color.
searchInputTextColorActivestringCustom search input searching state text color.
searchBarBackgroundColorstringCustom search bar background color.
titlestringToolbar title.
titleTextColorstringToolbar title text color.
cancelTextColorstringSearch bar cancel text color.
cancelTitlestringSearch bar cancel text color.
sectionIndexTextColorstringSection index text color.
hideSectionListboolWhether to hide the alphabetical section listing view or not.
renderSectionIndexItemfuncCustom render SectionIndexItem.
sortFuncfuncThe sort function for the list view data source,sorting alphabetical by default
resultSortFuncfuncThe sort function for the search result,sorting first match position by default
onScrollToSectionfuncThe callback of alphabetical section view be clicked or touch.
renderBackButtonfuncRender a custom back buttom on Toolbar.
renderEmptyfuncRender a view when data is empty.
renderEmptyResultfuncRender a view when search result is empty.
renderSeparatorfuncRender row separator.
renderSectionHeaderfuncrenderSectionHeader for the internal ListView
renderHeaderfuncrenderHeader for the internal ListView
renderFooterfuncrenderFooter for the internal ListView
renderRowfuncrenderRow for the internal ListView
onSearchStartfuncCallback when searching start.
onSearchEndfuncCallback 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.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial