forked from PhilipMortiboy/react-native-search-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchBar.coffee
70 lines (54 loc) · 1.87 KB
/
SearchBar.coffee
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
React = require 'react'
ReactNative = require 'react-native'
RNSearchBar = ReactNative.requireNativeComponent 'RNSearchBar', null
PropTypes = React.PropTypes
NativeModules = ReactNative.NativeModules
SearchBar = React.createClass
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: ->
barStyle: 'default'
searchBarStyle: 'default'
editable: true
_onChange: (e) ->
@props.onChange? e
@props.onChangeText? e.nativeEvent.text
_onPress: (e) ->
button = e.nativeEvent.button
if button == 'search'
@props.onSearchButtonPress? e.nativeEvent.searchText
else if button == 'cancel'
@props.onCancelButtonPress?()
blur: ->
NativeModules.RNSearchBarManager.blur ReactNative.findNodeHandle(this)
focus: ->
NativeModules.RNSearchBarManager.focus ReactNative.findNodeHandle(this)
unFocus: ->
NativeModules.RNSearchBarManager.unFocus(ReactNative.findNodeHandle(this))
resetText: ->
NativeModules.RNSearchBarManager.resetText(ReactNative.findNodeHandle(this))
render: ->
`<RNSearchBar
style={{height: NativeModules.RNSearchBarManager.ComponentHeight}}
onChange={this._onChange}
onPress={this._onPress}
{...this.props}
/>`
module.exports = SearchBar