forked from umhan35/react-native-search-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchBar.js
96 lines (83 loc) · 2.49 KB
/
SearchBar.js
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
var NativeModules, PropTypes, RNSearchBar, React, ReactNative;
React = require("react");
ReactNative = require("react-native");
PropTypes = require("prop-types");
RNSearchBar = ReactNative.requireNativeComponent("RNSearchBar", null);
NativeModules = ReactNative.NativeModules;
export default class SearchBar extends React.Component {
constructor(props) {
super(props);
this._onChange = this._onChange.bind(this);
this._onPress = this._onPress.bind(this);
}
_onChange(e) {
var base, base1;
if (typeof (base = this.props).onChange === "function") {
base.onChange(e);
}
return typeof (base1 = this.props).onChangeText === "function"
? base1.onChangeText(e.nativeEvent.text)
: void 0;
}
_onPress(e) {
var base, base1, button;
button = e.nativeEvent.button;
if (button === "search") {
return typeof (base = this.props).onSearchButtonPress === "function"
? base.onSearchButtonPress(e.nativeEvent.searchText)
: void 0;
} else if (button === "cancel") {
return typeof (base1 = this.props).onCancelButtonPress === "function"
? base1.onCancelButtonPress()
: void 0;
}
}
blur() {
return NativeModules.RNSearchBarManager.blur(
ReactNative.findNodeHandle(this)
);
}
focus() {
return NativeModules.RNSearchBarManager.focus(
ReactNative.findNodeHandle(this)
);
}
unFocus() {
return NativeModules.RNSearchBarManager.unFocus(
ReactNative.findNodeHandle(this)
);
}
render() {
return (
<RNSearchBar
style={{ height: NativeModules.RNSearchBarManager.ComponentHeight }}
onChange={this._onChange}
onPress={this._onPress}
barStyle={"default"}
searchBarStyle={"default"}
editable={true}
{...this.props}
/>
);
}
}
SearchBar.propTypes = {
placeholder: PropTypes.string,
text: PropTypes.string,
barTintColor: PropTypes.string,
tintColor: PropTypes.string,
textColor: PropTypes.string,
textFieldBackgroundColor: PropTypes.string,
showsCancelButton: PropTypes.bool,
onChange: PropTypes.func,
onChangeText: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
onSearchButtonPress: PropTypes.func,
onCancelButtonPress: PropTypes.func,
enablesReturnKeyAutomatically: PropTypes.bool,
hideBackground: PropTypes.bool,
barStyle: PropTypes.oneOf(["default", "black"]),
searchBarStyle: PropTypes.oneOf(["default", "prominent", "minimal"]),
editable: PropTypes.bool
};