forked from rotemmiz/react-native-sample-app-movies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchBar.android.js
148 lines (138 loc) · 3.59 KB
/
SearchBar.android.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @providesModule SearchBar
* @flow
*/
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {
Image,
Platform,
ActivityIndicator,
TextInput,
StyleSheet,
TouchableOpacity,
TouchableNativeFeedback,
Text,
View,
} = ReactNative;
var IS_RIPPLE_EFFECT_SUPPORTED = Platform.Version >= 21;
class SearchBar extends React.Component {
render() {
var background = IS_RIPPLE_EFFECT_SUPPORTED ?
TouchableNativeFeedback.SelectableBackgroundBorderless() :
TouchableNativeFeedback.SelectableBackground();
return (
<View style={styles.searchBar}>
<TouchableNativeFeedback
background={background}
onPress={() => this.refs.input && this.refs.input.focus()}>
<View>
<Image
source={require('image!android_search_white')}
style={styles.icon}
/>
</View>
</TouchableNativeFeedback>
<TextInput
ref="input"
autoCapitalize="none"
autoCorrect={false}
autoFocus={true}
onChange={this.props.onSearchChange}
placeholder="Search a movie..."
placeholderTextColor="rgba(255, 255, 255, 0.5)"
onFocus={this.props.onFocus}
style={styles.searchBarInput}
/>
<ActivityIndicator
animating={this.props.isLoading}
color="white"
size="large"
style={styles.spinner}
/>
<TouchableOpacity onPress={this.actBusy.bind(this)}>
<View style={styles.button}>
<Text>Spam mqt_js</Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={this.spamBridge.bind(this)}>
<View style={styles.button}>
<Text>Spam bridge</Text>
</View>
</TouchableOpacity>
</View>
);
}
/**
* make mqt_js super busy
*/
actBusy() {
setTimeout(() => { this.actBusyFor(8000); }, 500);
}
actBusyFor(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
spamBridge() {
for (var i = 0; i < 1000; i++) {
this.initTimer();
}
}
/**
* will send a message over MessageQueue.js to trigger the Native "Timing.createTimer()"
*/
initTimer() {
const that = this;
setTimeout(function() {
that.initTimer();
}, 1);
}
}
var styles = StyleSheet.create({
searchBar: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#a9a9a9',
height: 56,
},
searchBarInput: {
flex: 1,
fontSize: 20,
fontWeight: 'bold',
color: 'white',
height: 50,
padding: 0,
backgroundColor: 'transparent'
},
spinner: {
width: 30,
height: 30,
marginRight: 16,
},
icon: {
width: 24,
height: 24,
marginHorizontal: 8,
},
button: {
margin: 2
}
});
module.exports = SearchBar;