This repository was archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathSearchLayout.js
More file actions
69 lines (60 loc) · 1.87 KB
/
SearchLayout.js
File metadata and controls
69 lines (60 loc) · 1.87 KB
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
import React from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import SearchBar from './SearchBar';
import Header from './Header';
const DEFAULT_TINT_COLOR = Platform.OS === 'ios' ? '#007AFF' : '#000';
export default class SearchLayout extends React.Component {
static SearchBar = SearchBar;
static Header = Header;
static DefaultTintColor = DEFAULT_TINT_COLOR;
static defaultProps = {
debounce: 500,
headerBackgroundColor: '#fff',
headerTintColor: DEFAULT_TINT_COLOR,
};
state = {
q: '',
};
_handleSubmit = q => {
this.props.onSubmit && this.props.onSubmit(q);
};
// TODO: debounce
_handleChangeQuery = q => {
this.props.onChangeQuery && this.props.onChangeQuery(q);
this.setState({ q });
};
render() {
return (
<View style={styles.container}>
<Header
backgroundColor={this.props.headerBackgroundColor}
tintColor={this.props.headerTintColor}
backButton={Platform.OS === 'android'}>
<SearchBar
onChangeQuery={this._handleChangeQuery}
onSubmit={this._handleSubmit}
placeholderTextColor={this.props.searchInputPlaceholderTextColor}
textColor={this.props.searchInputTextColor}
selectionColor={this.props.searchInputSelectionColor}
underlineColorAndroid={
this.props.searchInputUnderlineColorAndroid ||
this.props.headerBackgroundColor
}
tintColor={
this.props.searchInputTintColor || this.props.headerTintColor
}
cancelButtonText={this.props.cancelButtonText}
/>
</Header>
{this.props.renderResults
? this.props.renderResults(this.state.q)
: this.props.children}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});