diff --git a/example.js b/example.js index 10c22e3..8c97ad3 100644 --- a/example.js +++ b/example.js @@ -115,7 +115,7 @@ const SearchListExample = () => { { + itemOnPress={(item) => { console.log('Single Item :: ', item); }} rowHeight={40} @@ -150,4 +150,4 @@ const styles = StyleSheet.create({ } }); -export default SearchListExample; \ No newline at end of file +export default SearchListExample; diff --git a/src/SearchList.js b/src/SearchList.js index 2138918..5e9d4ee 100644 --- a/src/SearchList.js +++ b/src/SearchList.js @@ -7,7 +7,8 @@ import { Image, Platform, SectionList, - TouchableOpacity, Alert + TouchableOpacity, + Alert } from 'react-native'; import React, { Component } from 'react'; @@ -18,7 +19,7 @@ import { sTrim } from './utils'; import SearchService from './SearchService'; -import { +import { SearchBar, Toolbar, SectionIndex, @@ -27,7 +28,7 @@ import { Empty, EmptyResult, SectionHeader, - SectionIndexItem, + SectionIndexItem } from './components'; export default class SearchList extends Component { @@ -170,7 +171,10 @@ export default class SearchList extends Component { const copiedSource = Array.from(data); this.setState({ originalListData: copiedSource }); this.parseInitList( - SearchService.sortList(SearchService.initList(copiedSource, searchCursor), this.props.sortFunc) + SearchService.sortList( + SearchService.initList(copiedSource, searchCursor), + this.props.sortFunc + ) ); resolve(); }); @@ -224,7 +228,7 @@ export default class SearchList extends Component { */ _renderSectionHeader({ section: { title } }) { const { sectionHeaderHeight } = this.props; - return + return ; } /** @@ -235,8 +239,10 @@ export default class SearchList extends Component { * @private */ _renderSectionIndexItem(section) { - const { colors: { sectionIndexTextColor } } = this.props; - return + const { + colors: { sectionIndexTextColor } + } = this.props; + return ; } /** @@ -295,18 +301,20 @@ export default class SearchList extends Component { _renderRow({ index, item, section }) { const { searchCursor, itemOnPress } = this.props; return ( - typeof itemOnPress === 'undefined' ? this.itemOnPress(item) : itemOnPress(item)} > - - {/* use `HighlightableText` to highlight the search result */} - - - + + typeof itemOnPress === 'undefined' ? this.itemOnPress(item) : itemOnPress(item) + }> + + {/* use `HighlightableText` to highlight the search result */} + + + ); } @@ -458,7 +466,11 @@ export default class SearchList extends Component { const { searchCursor, renderEmptyResult, renderEmpty, data } = this.props; if (isSearching && !isReady && searchStr !== '') { - return typeof renderEmptyResult === 'undefined' ? : renderEmptyResult(searchStr) + return typeof renderEmptyResult === 'undefined' ? ( + + ) : ( + renderEmptyResult(searchStr) + ); } if (data && data.length > 0 && isReady) { return ( @@ -486,7 +498,9 @@ export default class SearchList extends Component { /> ); } - {typeof renderEmpty === 'undefined' ? : renderEmpty()} + { + typeof renderEmpty === 'undefined' ? : renderEmpty(); + } } /** @@ -593,12 +607,8 @@ export default class SearchList extends Component { * @private */ _renderSectionIndex() { - const { - hideSectionList, - toolbarHeight, - sectionIndexContainerStyle, - renderSectionIndexItem - } = this.props; + const { hideSectionList, toolbarHeight, sectionIndexContainerStyle, renderSectionIndexItem } = + this.props; const { isSearching, sectionIds, animatedValue } = this.state; if (isSearching) { diff --git a/src/SearchService.js b/src/SearchService.js index ddc8437..4c10d08 100644 --- a/src/SearchService.js +++ b/src/SearchService.js @@ -83,7 +83,7 @@ export default class SearchService { static sortResultList(searchResultList, resultSortFunc) { searchResultList.sort( resultSortFunc || - function (a, b) { + ((a, b) => { if (b.matcher && a.matcher) { if (b.matcher.charMatchStartIndex < a.matcher.charMatchStartIndex) { return 1; @@ -94,7 +94,7 @@ export default class SearchService { return 0; } return 0; - } + }) ); const { formattedData } = this.parseList(searchResultList); @@ -148,9 +148,7 @@ export default class SearchService { formattedData.push({ title: orderIndex, data: [] }); } - const rowData = formattedData.find((object) => { - return object.title === orderIndex; - }); + const rowData = formattedData.find((object) => object.title === orderIndex); rowData.data.push(item); } @@ -202,15 +200,23 @@ export default class SearchService { static sortList(sourceData, sortFunc) { sourceData.sort( sortFunc || - function (a, b) { - if (!isCharacter(b.orderIndex) || b.orderIndex > a.orderIndex || b.isChinese > a.isChinese) { + ((a, b) => { + if ( + !isCharacter(b.orderIndex) || + b.orderIndex > a.orderIndex || + b.isChinese > a.isChinese + ) { return -1; } - if (!isCharacter(a.orderIndex) || b.orderIndex < a.orderIndex || b.isChinese < a.isChinese) { + if ( + !isCharacter(a.orderIndex) || + b.orderIndex < a.orderIndex || + b.isChinese < a.isChinese + ) { return 1; } return 0; - } + }) ); return sourceData; diff --git a/src/components/Empty.js b/src/components/Empty.js index 9704e77..aa46443 100644 --- a/src/components/Empty.js +++ b/src/components/Empty.js @@ -2,12 +2,10 @@ import React from 'react'; import { StyleSheet, View, Text } from 'react-native'; import styles from '../styles'; -const Empty = () => { - return ( - - No Content - - ); -}; +const Empty = () => ( + + No Content + +); export default Empty; diff --git a/src/components/EmptyResult.js b/src/components/EmptyResult.js index 8628b30..776d61f 100644 --- a/src/components/EmptyResult.js +++ b/src/components/EmptyResult.js @@ -2,18 +2,16 @@ import React from 'react'; import { StyleSheet, View, Text } from 'react-native'; import styles from '../styles'; -const EmptyResult = (searchStr) => { - return ( - - - {' '} - No Result For {searchStr} - - - Please search again - - - ); -}; +const EmptyResult = (searchStr) => ( + + + {' '} + No Result For {searchStr} + + + Please search again + + +); export default EmptyResult; diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js index 759a335..13cc46b 100644 --- a/src/components/SearchBar.js +++ b/src/components/SearchBar.js @@ -168,7 +168,8 @@ export default class SearchBar extends Component { styles.searchTextInputStyle, this.props.showSearchIcon ? '' : { paddingLeft: 8 }, { - color: this.props.searchInputTextColorActive && !this.state.isSearching + color: + this.props.searchInputTextColorActive && !this.state.isSearching ? this.props.searchInputTextColorActive : this.props.searchInputTextColor || '#979797' }, @@ -184,7 +185,10 @@ export default class SearchBar extends Component { {this.props.showSearchIcon ? ( - {' '}⚲ + + {' '} + ⚲ + ) : null} diff --git a/src/components/SectionHeader.js b/src/components/SectionHeader.js index 8f6f828..a1c85aa 100644 --- a/src/components/SectionHeader.js +++ b/src/components/SectionHeader.js @@ -2,18 +2,16 @@ import React from 'react'; import { StyleSheet, View, Text } from 'react-native'; import styles from '../styles'; -const SectionHeader = ({ title, sectionHeaderHeight }) => { - return ( - - - {title} - +const SectionHeader = ({ title, sectionHeaderHeight }) => ( + + + {title} - ); -}; + +); export default SectionHeader; diff --git a/src/components/SectionIndex.js b/src/components/SectionIndex.js index 6dc5156..eb9d2ea 100644 --- a/src/components/SectionIndex.js +++ b/src/components/SectionIndex.js @@ -49,19 +49,17 @@ export default class SectionIndex extends Component { const { renderSectionItem, sections } = this.props; const renderedSections = sections && sections.length > 0 ? ( - sections.map((section, index) => { - return ( - - {renderSectionItem ? ( - renderSectionItem(section) - ) : ( - - {section} - - )} - - ); - }) + sections.map((section, index) => ( + + {renderSectionItem ? ( + renderSectionItem(section) + ) : ( + + {section} + + )} + + )) ) : ( ); diff --git a/src/components/SectionIndexItem.js b/src/components/SectionIndexItem.js index 650d2fa..5140ef8 100644 --- a/src/components/SectionIndexItem.js +++ b/src/components/SectionIndexItem.js @@ -2,18 +2,16 @@ import React from 'react'; import { StyleSheet, View, Text } from 'react-native'; import styles from '../styles'; -const SectionIndexItem = ({ section, sectionIndexTextColor}) => { - return ( - - {section} - - ); -}; +const SectionIndexItem = ({ section, sectionIndexTextColor }) => ( + + {section} + +); export default SectionIndexItem; diff --git a/src/components/index.js b/src/components/index.js index 76e5672..f1bf0fb 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -9,25 +9,25 @@ import SectionIndexItem from './SectionIndexItem'; import Theme from './Theme'; export default { - SearchBar, - Toolbar, - SectionIndex, - HighlightableText, - Theme, - Empty, - EmptyResult, - SectionHeader, - SectionIndexItem + SearchBar, + Toolbar, + SectionIndex, + HighlightableText, + Theme, + Empty, + EmptyResult, + SectionHeader, + SectionIndexItem }; export { - SearchBar, - Toolbar, - SectionIndex, - HighlightableText, - Theme, - Empty, - EmptyResult, - SectionHeader, - SectionIndexItem + SearchBar, + Toolbar, + SectionIndex, + HighlightableText, + Theme, + Empty, + EmptyResult, + SectionHeader, + SectionIndexItem }; diff --git a/src/styles/index.js b/src/styles/index.js index 74829fa..d769f3a 100644 --- a/src/styles/index.js +++ b/src/styles/index.js @@ -1,7 +1,6 @@ import { StyleSheet } from 'react-native'; import Theme from '../components/Theme'; - export default StyleSheet.create({ emptyContainer: { flex: 1, @@ -25,5 +24,5 @@ export default StyleSheet.create({ sectionTitle: { color: '#979797', fontSize: 14 - }, -}); \ No newline at end of file + } +});