Skip to content

Commit

Permalink
chore: Lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
zanechua committed Jun 23, 2021
1 parent c3d8214 commit f76d51c
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 119 deletions.
4 changes: 2 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const SearchListExample = () => {
<View style={styles.container}>
<SearchList
data={dataSource}
itemOnPress={item => {
itemOnPress={(item) => {
console.log('Single Item :: ', item);
}}
rowHeight={40}
Expand Down Expand Up @@ -150,4 +150,4 @@ const styles = StyleSheet.create({
}
});

export default SearchListExample;
export default SearchListExample;
64 changes: 37 additions & 27 deletions src/SearchList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Image,
Platform,
SectionList,
TouchableOpacity, Alert
TouchableOpacity,
Alert
} from 'react-native';

import React, { Component } from 'react';
Expand All @@ -18,7 +19,7 @@ import { sTrim } from './utils';

import SearchService from './SearchService';

import {
import {
SearchBar,
Toolbar,
SectionIndex,
Expand All @@ -27,7 +28,7 @@ import {
Empty,
EmptyResult,
SectionHeader,
SectionIndexItem,
SectionIndexItem
} from './components';

export default class SearchList extends Component {
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -224,7 +228,7 @@ export default class SearchList extends Component {
*/
_renderSectionHeader({ section: { title } }) {
const { sectionHeaderHeight } = this.props;
return <SectionHeader title={title} sectionHeaderHeight={sectionHeaderHeight} />
return <SectionHeader title={title} sectionHeaderHeight={sectionHeaderHeight} />;
}

/**
Expand All @@ -235,8 +239,10 @@ export default class SearchList extends Component {
* @private
*/
_renderSectionIndexItem(section) {
const { colors: { sectionIndexTextColor } } = this.props;
return <SectionIndexItem section={section} sectionIndexTextColor={sectionIndexTextColor} />
const {
colors: { sectionIndexTextColor }
} = this.props;
return <SectionIndexItem section={section} sectionIndexTextColor={sectionIndexTextColor} />;
}

/**
Expand Down Expand Up @@ -295,18 +301,20 @@ export default class SearchList extends Component {
_renderRow({ index, item, section }) {
const { searchCursor, itemOnPress } = this.props;
return (
<TouchableOpacity
onPress={() => typeof itemOnPress === 'undefined' ? this.itemOnPress(item) : itemOnPress(item)} >
<View style={{ flex: 1, marginLeft: 20, height: 40, justifyContent: 'center' }}>
{/* use `HighlightableText` to highlight the search result */}
<HighlightableText
matcher={item.matcher}
text={item[searchCursor]}
textColor="#000000"
hightlightTextColor="#0069c0"
/>
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() =>
typeof itemOnPress === 'undefined' ? this.itemOnPress(item) : itemOnPress(item)
}>
<View style={{ flex: 1, marginLeft: 20, height: 40, justifyContent: 'center' }}>
{/* use `HighlightableText` to highlight the search result */}
<HighlightableText
matcher={item.matcher}
text={item[searchCursor]}
textColor="#000000"
hightlightTextColor="#0069c0"
/>
</View>
</TouchableOpacity>
);
}

Expand Down Expand Up @@ -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' ? <EmptyResult searchStr={searchStr} /> : renderEmptyResult(searchStr)
return typeof renderEmptyResult === 'undefined' ? (
<EmptyResult searchStr={searchStr} />
) : (
renderEmptyResult(searchStr)
);
}
if (data && data.length > 0 && isReady) {
return (
Expand Down Expand Up @@ -486,7 +498,9 @@ export default class SearchList extends Component {
/>
);
}
{typeof renderEmpty === 'undefined' ? <Empty/> : renderEmpty()}
{
typeof renderEmpty === 'undefined' ? <Empty /> : renderEmpty();
}
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 15 additions & 9 deletions src/SearchService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -94,7 +94,7 @@ export default class SearchService {
return 0;
}
return 0;
}
})
);

const { formattedData } = this.parseList(searchResultList);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions src/components/Empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import styles from '../styles';

const Empty = () => {
return (
<View style={styles.emptyContainer}>
<Text style={styles.emptyText}>No Content</Text>
</View>
);
};
const Empty = () => (
<View style={styles.emptyContainer}>
<Text style={styles.emptyText}>No Content</Text>
</View>
);

export default Empty;
24 changes: 11 additions & 13 deletions src/components/EmptyResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import styles from '../styles';

const EmptyResult = (searchStr) => {
return (
<View style={styles.emptyContainer}>
<Text style={styles.emptyText}>
{' '}
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>
);
};
const EmptyResult = (searchStr) => (
<View style={styles.emptyContainer}>
<Text style={styles.emptyText}>
{' '}
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>
);

export default EmptyResult;
8 changes: 6 additions & 2 deletions src/components/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand All @@ -184,7 +185,10 @@ export default class SearchBar extends Component {

<Animated.View pointerEvents="none" style={[styles.leftSearchIconStyle]}>
{this.props.showSearchIcon ? (
<Text style={[styles.searchIconStyle, { color: this.props.searchIconColor }]}>{' '}&#x26B2;</Text>
<Text style={[styles.searchIconStyle, { color: this.props.searchIconColor }]}>
{' '}
&#x26B2;
</Text>
) : null}
</Animated.View>
</Animated.View>
Expand Down
22 changes: 10 additions & 12 deletions src/components/SectionHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import styles from '../styles';

const SectionHeader = ({ title, sectionHeaderHeight }) => {
return (
<View style={[styles.sectionHeader, { height: sectionHeaderHeight }]}>
<View
style={{
justifyContent: 'center',
height: sectionHeaderHeight
}}>
<Text style={styles.sectionTitle}>{title}</Text>
</View>
const SectionHeader = ({ title, sectionHeaderHeight }) => (
<View style={[styles.sectionHeader, { height: sectionHeaderHeight }]}>
<View
style={{
justifyContent: 'center',
height: sectionHeaderHeight
}}>
<Text style={styles.sectionTitle}>{title}</Text>
</View>
);
};
</View>
);

export default SectionHeader;
24 changes: 11 additions & 13 deletions src/components/SectionIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<View key={index} pointerEvents="none">
{renderSectionItem ? (
renderSectionItem(section)
) : (
<View style={styles.item}>
<Text style={styles.text}>{section}</Text>
</View>
)}
</View>
);
})
sections.map((section, index) => (
<View key={index} pointerEvents="none">
{renderSectionItem ? (
renderSectionItem(section)
) : (
<View style={styles.item}>
<Text style={styles.text}>{section}</Text>
</View>
)}
</View>
))
) : (
<View />
);
Expand Down
24 changes: 11 additions & 13 deletions src/components/SectionIndexItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import styles from '../styles';

const SectionIndexItem = ({ section, sectionIndexTextColor}) => {
return (
<Text
style={{
textAlign: 'center',
color: sectionIndexTextColor,
fontSize: 14,
height: 20
}}>
{section}
</Text>
);
};
const SectionIndexItem = ({ section, sectionIndexTextColor }) => (
<Text
style={{
textAlign: 'center',
color: sectionIndexTextColor,
fontSize: 14,
height: 20
}}>
{section}
</Text>
);

export default SectionIndexItem;
Loading

0 comments on commit f76d51c

Please sign in to comment.