1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
import React from 'react';
import {
FlatList,
View,
StyleSheet,
TouchableOpacity,
} from 'react-native';
import _ from 'lodash';
import {
RkStyleSheet,
RkText,
RkTextInput,
} from 'react-native-ui-kitten';
import { data } from '../../data';
import { Avatar } from '../../components/avatar';
import { FontAwesome } from '../../assets/icons';
import NavigationType from '../../config/navigation/propTypes';
export class Contacts extends React.Component {
static propTypes = {
navigation: NavigationType.isRequired,
};
static navigationOptions = {
title: 'Contacts'.toUpperCase(),
};
state = {
data: {
original: data.getUsers(),
filtered: data.getUsers(),
},
};
extractItemKey = (item) => `${item.id}`;
onSearchInputChanged = (event) => {
const pattern = new RegExp(event.nativeEvent.text, 'i');
const contacts = _.filter(this.state.data.original, contact => {
const filterResult = {
firstName: contact.firstName.search(pattern),
lastName: contact.lastName.search(pattern),
};
return filterResult.firstName !== -1 || filterResult.lastName !== -1 ? contact : undefined;
});
this.setState({
data: {
original: this.state.data.original,
filtered: contacts,
},
});
};
onItemPressed = (item) => {
this.props.navigation.navigate('ProfileV1', { id: item.id });
};
renderItem = ({ item }) => (
<TouchableOpacity onPress={() => this.onItemPressed(item)}>
<View style={styles.container}>
<Avatar rkType='circle' style={styles.avatar} img={item.photo} />
<RkText>{`${item.firstName} ${item.lastName}`}</RkText>
</View>
</TouchableOpacity>
);
renderSeparator = () => (
<View style={styles.separator} />
);
renderHeaderLabel = () => (
<RkText rkType='awesome'>{FontAwesome.search}</RkText>
);
renderHeader = () => (
<View style={styles.searchContainer}>
<RkTextInput
autoCapitalize='none'
autoCorrect={false}
onChange={this.onSearchInputChanged}
label={this.renderHeaderLabel()}
rkType='row'
placeholder='Search'
/>
</View>
);
render = () => (
<FlatList
style={styles.root}
data={this.state.data.filtered}
renderItem={this.renderItem}
ListHeaderComponent={this.renderHeader}
ItemSeparatorComponent={this.renderSeparator}
keyExtractor={this.extractItemKey}
enableEmptySections
/>
)
}
const styles = RkStyleSheet.create(theme => ({
root: {
backgroundColor: theme.colors.screen.base,
},
searchContainer: {
backgroundColor: theme.colors.screen.bold,
paddingHorizontal: 16,
paddingVertical: 10,
height: 60,
alignItems: 'center',
},
container: {
flexDirection: 'row',
padding: 16,
alignItems: 'center',
},
avatar: {
marginRight: 16,
},
separator: {
flex: 1,
height: StyleSheet.hairlineWidth,
backgroundColor: theme.colors.border.base,
},
}));
|