Skip to content

Commit 8056e46

Browse files
bug fix
1 parent 63b0266 commit 8056e46

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

.DS_Store

-6 KB
Binary file not shown.

index.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React, { Component } from 'react';
1+
import React, { Component } from "react";
22
import {
33
StyleSheet,
44
Text,
55
View,
66
FlatList,
77
TextInput,
88
RefreshControl,
9-
KeyboardAvoidingView,
10-
} from 'react-native';
11-
import PropTypes from 'prop-types';
9+
KeyboardAvoidingView
10+
} from "react-native";
11+
import PropTypes from "prop-types";
1212

1313
class CompleteFlatList extends Component {
1414
constructor(props) {
@@ -18,9 +18,9 @@ class CompleteFlatList extends Component {
1818
this.refresh = this.refresh.bind(this);
1919

2020
this.state = {
21-
behavior: 'padding',
21+
behavior: "padding",
2222
refreshing: false,
23-
searchText: '',
23+
searchText: ""
2424
};
2525
}
2626

@@ -34,7 +34,7 @@ class CompleteFlatList extends Component {
3434

3535
refresh() {
3636
if (this.props.data.length === 0) {
37-
filtereddata = [{ type: 'emptyrow', name: 'No data available' }];
37+
filtereddata = [{ type: "emptyrow", name: "No data available" }];
3838
}
3939
filtereddata = this.props.data;
4040
this.setState({ refreshing: false, data: filtereddata });
@@ -44,7 +44,7 @@ class CompleteFlatList extends Component {
4444
const { data, searchKey } = this.props;
4545
const { searchText } = this.state;
4646

47-
if (searchText === '') {
47+
if (searchText === "") {
4848
return data;
4949
}
5050

@@ -56,6 +56,7 @@ class CompleteFlatList extends Component {
5656
const target = dt[sk];
5757
if (target.toLowerCase().indexOf(searchText.toLowerCase()) !== -1) {
5858
filteredData.push(dt);
59+
break;
5960
}
6061
}
6162
}
@@ -82,11 +83,7 @@ class CompleteFlatList extends Component {
8283
underlineColorAndroid="transparent"
8384
autoCapitalize="none"
8485
keyboardType="email-address"
85-
onChangeText={text =>
86-
this.setState({
87-
searchText: text.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, ''),
88-
})
89-
}
86+
onChangeText={searchText => this.setState({ searchText })}
9087
value={this.state.searchText}
9188
maxLength={100}
9289
/>
@@ -111,9 +108,11 @@ class CompleteFlatList extends Component {
111108
refreshControl={refreshcontrol}
112109
data={filteredData}
113110
renderItem={item =>
114-
(filteredData.length === 1 && filteredData[0].showEmptyRow !== null
111+
filteredData.length === 1 &&
112+
filteredData[0].showEmptyRow !== null &&
113+
typeof filteredData[0].showEmptyRow !== "undefined"
115114
? this.renderEmptyRow()
116-
: renderItem(item.item))
115+
: renderItem(item.item)
117116
}
118117
style={styles.flatList}
119118
ItemSeparatorComponent={renderSeparator}
@@ -128,40 +127,39 @@ CompleteFlatList.propTypes = {
128127
data: PropTypes.array,
129128
renderItem: PropTypes.func,
130129
renderSeparator: PropTypes.func,
131-
pullToRefreshCallback: PropTypes.func,
130+
pullToRefreshCallback: PropTypes.func
132131
};
133132
CompleteFlatList.defaultProps = {
134133
searchKey: [],
135134
data: [],
136135
renderItem: null,
137136
renderSeparator: () => <View style={styles.defaultSeparator} />,
138-
pullToRefreshCallback: null,
137+
pullToRefreshCallback: null
139138
};
140139

141140
const styles = StyleSheet.create({
142-
noData: { alignSelf: 'center', textAlign: 'center', marginTop: 20 },
141+
noData: { alignSelf: "center", textAlign: "center", marginTop: 20 },
143142
searchBarContainer: {
144-
justifyContent: 'center',
143+
justifyContent: "center",
145144
padding: 10,
146-
backgroundColor: '#a7a7a8',
147-
width: '100%',
145+
backgroundColor: "#a7a7a8",
146+
width: "100%"
148147
},
149148
searchBar: {
150149
borderRadius: 5,
151-
// borderWidth: 1,
152-
backgroundColor: 'white',
150+
backgroundColor: "white",
153151
height: 44,
154-
width: '100%',
155-
paddingHorizontal: 10,
152+
width: "100%",
153+
paddingHorizontal: 10
156154
},
157155
container: {
158156
flex: 1,
159-
justifyContent: 'center',
160-
alignItems: 'center',
161-
backgroundColor: 'white',
157+
justifyContent: "center",
158+
alignItems: "center",
159+
backgroundColor: "white"
162160
},
163-
defaultSeparator: { height: 1, backgroundColor: '#CCCCCC' },
164-
flatList: { height: '100%', width: '100%', backgroundColor: 'transparent' },
161+
defaultSeparator: { height: 1, backgroundColor: "#CCCCCC" },
162+
flatList: { height: "100%", width: "100%", backgroundColor: "transparent" }
165163
});
166164

167165
export default CompleteFlatList;

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-complete-flatlist",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "A complete flatlist with search bar etc is ready to use",
55
"main": "index.js",
66
"scripts": {
@@ -18,7 +18,9 @@
1818
"searchbar",
1919
"list",
2020
"listview",
21-
"scroll"
21+
"scroll",
22+
"listview with search bar",
23+
"flatlist with search bar"
2224
],
2325
"author": "Fattah Muhyiddeen <[email protected]>",
2426
"license": "MIT",

0 commit comments

Comments
 (0)