-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.android.js
More file actions
490 lines (478 loc) · 13.9 KB
/
Copy pathindex.android.js
File metadata and controls
490 lines (478 loc) · 13.9 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react";
//引入所需要用的组件
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
TextInput,
ScrollView,
Image,
FlatList,
SectionList
} from "react-native";
//引入 navigation库
import { StackNavigator } from "react-navigation";
export default class HomeScreen extends Component {
static navigationOptions = {
title: "Welcome"
};
constructor(props) {
super(props);
this.state = { text: "" };
}
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<Button
onPress={() => navigate("Chat", { user: "123213" })}
title="Chat with Lucy"
/>
<Button onPress={() => navigate("Blink")} title="Blink" />
<Button onPress={() => navigate("LotsOfStyles")} title="LotsOfStyles" />
<Button
onPress={() => navigate("FlexDimensionsBasics")}
title="FlexDimensionsBasics"
/>
<View style={{ padding: 10 }}>
<TextInput
style={{ height: 40, width: 300 }}
placeholder="Type here to translate!"
onChangeText={text => this.setState({ text })}
/>
<Text style={{ padding: 10, fontSize: 42 }}>
{this.state.text.split(" ").map(word => word && "🍕").join(" ")}
</Text>
</View>
<ScrollView>
<Text style={{ fontSize: 16 }}>Scroll me plz</Text>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Text style={{ fontSize: 16 }}>If you like</Text>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Text style={{ fontSize: 16 }}>Scrolling down</Text>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Text style={{ fontSize: 16 }}>What's the best</Text>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Text style={{ fontSize: 16 }}>Framework around?</Text>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Image
source={{
uri:
"http://img.zcool.cn/community/0198cb574dd3266ac72525ae5006f1.jpg"
}}
style={{ width: 40, height: 40 }}
/>
<Text style={{ fontSize: 16 }}>React Native</Text>
</ScrollView>
</View>
);
}
}
class ChatScreen extends React.Component {
// 设置titlebar的标题
static navigationOptions = ({ navigation }) => ({
title: `Chat with ${navigation.state.params.user}`
});
render() {
//定义一个变量params = this.props的navigation的状态
//this.props 是这个类被传入的属性
//自定义的组件也可以使用props。通过在不同的场景使用不同的属性定制,
// 可以尽量提高自定义组件的复用范畴。
// 只需在render函数中引用this.props,然后按需处理
const { params } = this.props.navigation.state;
return (
<View>
<Text>
Chat with {params.user}
</Text>
// 包含 dat数据源 renderItem 里面包含item的布局
<FlatList
data={[
{ key: "Devin" },
{ key: "Jackson" },
{ key: "James" },
{ key: "Joel" },
{ key: "John" },
{ key: "Jillian" },
{ key: "Jimmy" },
{ key: "Julie" },
{ key: "1" },
{ key: "12" },
{ key: "2" },
{ key: "3" },
{ key: "44" },
{ key: "55" },
{ key: "565" },
{ key: "555" }
]}
renderItem={({ item }) =>
<Text style={styles.item}>
{item.key}
</Text>}
/>
</View>
);
}
}
class Blink extends Component {
constructor(props) {
//props是组件创建就被父组件传入的 不可以改变
//state是可以改变的
super(props);
//在该也在方法中 初始化state 数据状态
//并且使用this.setState() 方法来改变状态 (里面类似一个json)
this.state = { showText: true };
// 每1000毫秒对showText状态做一次取反操作
setInterval(() => {
// setState 有一个参数 之前的状态 返回一个新的数据状态
this.setState(previousState => {
return { showText: !previousState.showText };
});
}, 1000);
}
render() {
// 根据当前showText的值决定是否显示text内容
//let 局部变量
// 这里的this.props.text就是父控件传入的text <Blink text='xxxxx'>
let display = this.state.showText ? this.props.text : " ";
return (
<Text>
{display}
</Text>
);
}
}
class BlinkApp extends Component {
componentWithUnmount() {}
static navigationOptions = ({ navigation }) => ({
title: `BlinkApp`
});
render() {
return (
<View>
// 这里的blink是自定一个一个组件 上面 text就会通过props当做参数传入
<Blink text="I love to blink" />
<Blink text="Yes blinking is so great" />
<Blink text="Why did they ever take this out of HTML" />
<Blink text="Look at me look at me look at me" />
<SectionList
sections={[
{ title: "D", data: ["Devin"] },
{
title: "J",
data: [
"Jackson",
"James",
"Jillian",
"Jimmy",
"Joel",
"John",
"Julie"
]
},
{
title: "gf",
data: [
"Ja3ck5son",
"Jam3e5s",
"Ji3llia5n",
"Jim5my",
"J5oel",
"Joh5n",
"Ju5lie"
]
},
{
title: "hg",
data: [
"Ja3ckson",
"Jam3es",
"Jil4lian",
"Jim55my",
"Joel",
"John",
"Julie"
]
}
]}
renderItem={({ item }) =>
<Text style={styles.item}>
{item}
</Text>}
renderSectionHeader={({ section }) =>
<Text style={styles.sectionHeader}>
{section.title}
</Text>}
/>
</View>
);
}
}
class LotsOfStyles extends Component {
static navigationOptions = ({ navigation }) => ({
title: `LotsOfStyles`
});
render() {
return (
<View>
<Text style={styles.red}>just red</Text>
<Text style={styles.bigblue}>just bigblue</Text>
<Text style={[styles.bigblue, styles.red]}>bigblue, then red</Text>
<Text style={[styles.red, styles.bigblue]}>red, then bigblue</Text>
</View>
);
}
}
class FlexDimensionsBasics extends Component {
render() {
return (
// 试试去掉父View中的`flex: 1`。
// 则父View不再具有尺寸,因此子组件也无法再撑开。
// 然后再用`height: 300`来代替父View的`flex: 1`试试看?
// <View style={{flex:1,flexDirection:'column'}}>
// <View style={{ flex: 1,
// flexDirection: 'column',
// justifyContent: 'center',}}>
// <View style={{ flex: 1, width:100,backgroundColor: "powderblue" }} />
// <View style={{ flex: 2,width:100, backgroundColor: "skyblue" }} />
// <View style={{ flex: 3, width:100,backgroundColor: "steelblue" }} />
// </View>
// <View style={{ flex: 2 }}>
// <View style={{ flex: 1, backgroundColor: "steelblue" }} />
// <View style={{ flex: 2, backgroundColor: "powderblue" }} />
// <View style={{ flex: 3, backgroundColor: "skyblue" }} />
// </View>
// </View>
<View
style={{
flex: 1,
flexDirection: "column",
alignItems: "stretch",
justifyContent: "space-around"
}}
>
<View style={{ height: 100, backgroundColor: "powderblue" }} />
<View style={{ height: 100, backgroundColor: "skyblue" }} />
<View style={{ height: 100, backgroundColor: "steelblue" }} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5
},
bigblue: {
color: "blue",
fontWeight: "bold",
fontSize: 30
},
red: {
color: "red"
},
sectionHeader: {
paddingTop: 2,
paddingLeft: 10,
paddingRight: 10,
paddingBottom: 2,
fontSize: 14,
fontWeight: "bold",
backgroundColor: "rgba(247,247,247,1.0)"
},
item: {
padding: 10,
fontSize: 18,
height: 44
}
});
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
Blink: { screen: BlinkApp },
LotsOfStyles: { screen: LotsOfStyles },
FlexDimensionsBasics: { screen: FlexDimensionsBasics }
});
AppRegistry.registerComponent("SimpleApp", () => SimpleApp);