forked from RobertBiehl/react-native-search-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchBar.js
More file actions
78 lines (70 loc) · 2.45 KB
/
SearchBar.js
File metadata and controls
78 lines (70 loc) · 2.45 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
70
71
72
73
74
75
76
77
78
var NativeModules, PropTypes, RNSearchBar, React, ReactNative, SearchBar;
React = require('react');
ReactNative = require('react-native');
RNSearchBar = ReactNative.requireNativeComponent('RNSearchBar', null);
PropTypes = require('prop-types')
var createReactClass = require('create-react-class');
NativeModules = ReactNative.NativeModules;
SearchBar = createReactClass({
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
},
getDefaultProps: function() {
return {
barStyle: 'default',
searchBarStyle: 'default',
editable: true
};
},
_onChange: function(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: function(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: function() {
return NativeModules.RNSearchBarManager.blur(ReactNative.findNodeHandle(this));
},
focus: function() {
return NativeModules.RNSearchBarManager.focus(ReactNative.findNodeHandle(this));
},
unFocus: function() {
return NativeModules.RNSearchBarManager.unFocus(ReactNative.findNodeHandle(this));
},
render: function() {
return <RNSearchBar
style={{height: NativeModules.RNSearchBarManager.ComponentHeight}}
onChange={this._onChange}
onPress={this._onPress}
{...this.props}
/>;
}
});
module.exports = SearchBar;