-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathSearchScreen.js
184 lines (157 loc) · 4.21 KB
/
SearchScreen.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
'use strict';
var React = require('react-native');
var {
View,
StyleSheet,
Text,
Image,
Animated,
Dimensions,
ToastAndroid,
TextInput,
TouchableHighlight,
TouchableNativeFeedback,
Platform,
} = React;
var dismissKeyboard = require('dismissKeyboard');
var SearchResultScreen = require('./SearchResultScreen');
var deviceWidth = Dimensions.get('window').width;
var titleBarHeight = Dimensions.get('window').height / 12;
var textInputHeight = titleBarHeight - 20;
var TouchableElement = TouchableHighlight;
if (Platform.OS === 'android') {
TouchableElement = TouchableNativeFeedback;
}
var titleBarMarginTop = 0;
if (Platform.OS === 'ios') {
titleBarMarginTop = 10;
}
var SearchScreen = React.createClass({
getInitialState: function() {
return {
isFirstIn: true,
};
},
onBackPress: function() {
if (this.props.navigator) {
this.props.navigator.pop();
dismissKeyboard();
}
},
onSearchPress: function() {
if(!this.state.text || this.state.text === ""){
ToastAndroid.show("请输入关键字", ToastAndroid.SHORT);
}else{
dismissKeyboard();
if(this.props.navigator){
this.props.navigator.push({
keyword: this.state.text,
name: 'result',
});
}
}
},
render: function () {
return (
<View style={styles.container}>
<View style={styles.titleBarContainer}>
<TouchableElement onPress={this.onBackPress}>
<View style={styles.actionItem}>
<Image
style={styles.searchButton}
source={require('./images/ic_back.png')}
resizeMode='contain' />
</View>
</TouchableElement>
<TextInput
style={styles.textInput}
placeholder="输入您想看的电影..."
placeholderTextColor="#888888"
underlineColorAndroid="transparent"
onChangeText={(text) => this.setState({text})}
value={this.state.text}
autoFocus={true}
multiline={false} />
<TouchableElement onPress={this.onSearchPress}>
<View style={styles.actionItem}>
<Image
style={styles.searchButton}
source={require('./images/ic_search_white_48dp.png')}
resizeMode='contain' />
</View>
</TouchableElement>
</View>
<View style={styles.midContainer}>
<Text style={styles.welcome}>
电影搜索
</Text>
</View>
</View>
);
},
renderResultView: function() {
return (
<View style={styles.container}>
<SearchResultScreen
style={{flex: 1, width: deviceWidth}}
navigator={this.props.navigator}
keyword="张艺谋" />
</View>
);
},
});
var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
titleBarContainer: {
flexDirection: "row",
marginTop: titleBarMarginTop,
alignItems: 'center',
height: titleBarHeight,
backgroundColor: '3e9ce9',
},
midContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
welcome: {
fontSize: 26,
fontWeight: '400',
color: '#888888',
textAlign: 'center',
},
titleText: {
fontSize: 18,
marginLeft: 10,
color: 'white'
},
titleBarSplitLine: {
height: 0,
backgroundColor: '#e5e5e5',
},
searchButton: {
width: 32,
height: 32,
marginLeft: 8,
marginRight: 8,
},
actionItem: {
height: 56,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
paddingLeft: 8,
paddingRight: 8,
},
textInput: {
flex: 1,
color: '#888888',
backgroundColor: 'white',
height: textInputHeight,
}
});
module.exports = SearchScreen;