-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
484 lines (466 loc) · 13.5 KB
/
App.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
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {Component, useState} from 'react';
import {
Image,
StyleSheet,
Text,
TextInput,
View,
Button,
TouchableOpacity,
Alert,
TouchableHighlight,
TouchableNativeFeedback,
Platform,
TouchableWithoutFeedback,
} from 'react-native';
import AppleComponent from './AppComponent';
// import {Colors} from './Colors';
import {render} from 'react-native/Libraries/Renderer/implementations/ReactFabric-prod';
import {createAppContainer, StackNavigator} from 'react-navigation';
import {RecyclerListView, DataProvider, LayoutProvider} from 'recyclerlistview';
// import DetailsScreen from './DetailsScreen';
// import SecondActivity from './SecondActivity';
// import Home from './HomeScreen';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import HomeScreen from './HomeScreen';
import DetailsScreen from './DetailsScreen';
import ModalScreen from './src/widget/detail/ModalScreen';
import WidgetDetails from './src/widget/WidgetDetails';
import KeyboardAvoiding from './KeyboardAvoiding';
import PressableWidget from './src/widget/detail/PressableWidget';
import RefreshControlWidget from './src/widget/detail/RefreshControlWidget';
import ScrollViewWidget from './src/widget/detail/ScrollViewWidget';
import {sectionListWidget} from './src/widget/detail/SectionListWidget';
import StatusBarWidget from './src/widget/detail/StatusBarWidget';
import SwitchWidget from './src/widget/detail/SwitchWidget';
import {TextInANest} from './src/widget/detail/TextWidget';
import UselessTextInputMultiline from './src/widget/detail/TextInputWidget';
const Cat = props => {
// const name = 'xiaoming';
return (
<View>
<Text>Hello,I am {props.name}</Text>
<TextInput
style={{
height: 40,
borderColor: 'gray',
borderWidth: 1,
marginHorizontal: 10,
marginTop: 10,
}}
defaultValue="Name me!"
/>
</View>
);
};
const Cafe = () => {
return (
<View>
<Text>Welcome</Text>
<Cat name="xiaopeng" />
<Cat name="xiaofei" />
<Cat name="kiki" />
<Cat name="solo hello" />
</View>
);
};
const CatApp = () => {
return (
<View style={{}}>
<Image
source={{
uri: 'https://reactnative.dev/docs/assets/p_cat1.png',
}}
style={{width: 200, height: 200}}
/>
<Text>Hello I am your cat!</Text>
</View>
);
};
// export default CatApp;
// State 状态
const MyCat = props => {
const [isHungry, setIsHungry] = useState(true);
return (
<View>
<Text>
I am {props.name} and I am {isHungry ? 'hungry' : 'full'}
</Text>
<Button
onPress={() => {
setIsHungry(false);
}}
disabled={!isHungry}
title={isHungry ? 'Pour me some milk,Please!' : 'Thank you!'}
/>
</View>
);
};
const MyCafe = () => {
return (
<>
<MyCat name="Munkustrap" />
<MyCat name="Spot" />
</>
);
};
const PizzaTranslator = () => {
const [text, setText] = useState('');
const [state, setState] = useState(true);
return (
<View>
<TextInput
style={{
padding: 10,
height: 40,
width: 400,
backgroundColor: '#f00f80',
}}
placeholder="Type here to translate!"
onChangeText={text => {
setText(text);
// console.log(text.split(' ').map(world => world));
}}
defaultValue={text}
/>
{/* eslint-disable-next-line react-native/no-inline-styles */}
<Text style={{padding: 10, fontSize: 40}}>
{text
.split(' ')
.map(world => world && '🍕')
.join('')}
</Text>
</View>
);
};
// const PreviewLayout = ({
// label,
// children,
// values,
// selectedValue,
// setSelectedValue,
// }) => (
// <View style={{margin: 10, flex: 1, backgroundColor: '#ffffff'}}>
// <Text style={styles.label}>{label}</Text>
// <View style={styles.row}>
// {values.map(value => (
// <TouchableOpacity
// key={value}
// onPress={() => {
// console.log(value);
// setSelectedValue(value);
// console.log(selectedValue);
// }}
// style={[styles.button, selectedValue === value && styles.selected]}>
// <Text
// style={[
// styles.buttonLabel,
// selectedValue === value && styles.selectedLabel,
// ]}>
// {value}
// </Text>
// </TouchableOpacity>
// ))}
// </View>
// <View style={(styles.container, {[label]: selectedValue})}>{children}</View>
// </View>
// );
//
// const FlexDirectionBasics = () => {
// const [flexDirection, setFlexDirection] = useState('column');
// return (
// <PreviewLayout
// label="flexDirection"
// values={['column', 'row', 'row-reverse', 'column-reverse']}
// selectedValue={flexDirection}
// setSelectedValue={setFlexDirection}>
// {/* eslint-disable-next-line react-native/no-inline-styles */}
// <View style={[styles.box, {backgroundColor: 'powderblue'}]} />
// <View style={[styles.box, {backgroundColor: 'skyblue'}]} />
// <View style={[styles.box, {backgroundColor: 'steelblue'}]} />
// </PreviewLayout>
// );
// };
const stylesNormal = StyleSheet.create({
container: {
flex: 1,
margin: 8,
backgroundColor: 'aliceblue',
},
box: {
width: 50,
height: 50,
},
row: {
flexDirection: 'row',
flexWrap: 'wrap',
},
test: {
fontSize: 16,
color: '#ff0000',
},
button: {
paddingHorizontal: 8,
paddingVertical: 6,
borderRadius: 4,
backgroundColor: 'oldlace',
alignSelf: 'flex-start',
marginHorizontal: '1%',
marginBottom: 6,
minWidth: '48%',
textAlign: 'center',
},
selected: {
backgroundColor: '#456792',
borderWidth: 1,
},
buttonLabel: {
fontSize: 12,
fontWeight: '500',
color: '#00ff00',
},
selectedLabel: {
color: 'white',
},
label: {
textAlign: 'center',
marginBottom: 10,
fontSize: 24,
color: '#67980d',
},
});
// export default class App extends Component<Props> {
// render(): React$Node {
// // eslint-disable-next-line react-hooks/rules-of-hooks
// // const [color, setColor] = useState('红色');
// const name = '文本';
// let params = {apple_color: '红色', apple_price: 9.9, apple_weight: 1.8};
// let {apple_color, apple_weight} = params;
// return (
// <View>
// <AppleComponent
// apple_color={apple_color}
// apple_weight={apple_weight}
// apple_price={9.9}
// />
// <Text
// style={{marginTop: 20}}
// onPress={() => {
// console.log('点击了');
// }}>
// {name}
// </Text>
// </View>
// );
// }
// }
// export default FlexDirectionBasics;
// JavaScript提供的逻辑与运算符(&&)的短路原理规定:当&&运算的左侧为false时,右侧不予计算。该运算符适合多分支的判定
let flag = true;
const element = () => {
return (
<View style={buttonStyles.row}>
{flag && <Text>我是box元素 </Text>}
{!flag && <Text>我是fox元素</Text>}
{getTarget()}
<Text style={{fontSize: 20, color: '#d99800', width: 300, height: 40}}>
Hao de
</Text>
<Button
title="button"
onPress={() => {
Alert.alert('你点击了按钮');
}}
/>
</View>
);
};
const buttonStyles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
buttonContainer: {
margin: 20,
},
alternativeLayoutButtonContainer: {
margin: 20,
flexDirection: 'row',
justifyContent: 'space-between',
},
row: {
flexDirection: 'column',
flexWrap: 'wrap',
},
});
function getTarget() {
if (flag) {
return <Text> 好呀</Text>;
} else {
return <Text>不好</Text>;
}
}
// export default class ButtonBasic extends Component {
// _onPressButton() {
// Alert.alert('You tapped the button!');
// }
// render() {
// return (
// <View style={buttonStyles.container}>
// <View style={buttonStyles.buttonContainer}>
// <Button title="Press Me" onPress={this._onPressButton} />
// </View>
// <View style={buttonStyles.buttonContainer}>
// <Button
// title="Press me"
// onPress={this._onPressButton}
// color="#841584"
// />
// </View>
// <View style={buttonStyles.alternativeLayoutButtonContainer}>
// <Button title="This looks great!" onPress={this._onPressButton} />
// <Button title="OK!" onPress={this._onPressButton} color="#841584" />
// </View>
// </View>
// );
// }
// }
// 使用Touchable 系列组件
// 一般使用 TouchableHighlight 来制作按钮或者链接,注意此组件的背景会在用户按下时变暗
//在 Android 上海可以使用TouchableNativeFeedback,它会在用户手指按下时行程类似墨水涟漪的视觉效果
// TouchableOpacity 会在用户手指按下时降低按钮的透明度,而不会改变背景的颜色
// 如果你想在处理点击事件的同时不显示任何视觉反馈,则需要使用 TouchableWithoutFeedback
const name = '';
class Touchables extends Component {
_onPressButton() {
// fetch('https://localhost:8080');
// bar();
var x = 6;
// foo01();
// console.log(add(1, 7, 9, 3));
// test();
// var a = [];
// push(a,1,2,3);
// testOperator();
// let myObj = {size: 10, label: 'Size 10 Object'};
// console.log(printLabel(myObj));
// console.log(obj01.c());
// printLabel_01({label: 'Size 10 Object -----'});
// let mySquare = createSquare({color: 'black'});
// console.log(mySquare);
// testPro();
// TypeScript 函数
// let cardPicker = deck.createCardPicker();
// let pickedCard = cardPicker();
// console.log("card: "+pickedCard.card + "of"+pickedCard.suit);
Alert.alert('You update the button');
}
_onLongPressButton() {
Alert.alert('You long-pressed the button!');
}
/**
* underlayColor 点击按下时的颜色
* @returns {JSX.Element}
*/
render() {
return (
<View style={touchStyles.container}>
<TouchableHighlight onPress={this._onPressButton} underlayColor="white">
<View style={touchStyles.button}>
<Text style={touchStyles.buttonText}>TouchableHighlight</Text>
</View>
</TouchableHighlight>
<TouchableOpacity onPress={this._onPressButton}>
<View style={touchStyles.button}>
<Text style={touchStyles.buttonText}>TouchableOpacity</Text>
</View>
</TouchableOpacity>
<TouchableNativeFeedback
onPress={this._onPressButton}
background={
Platform.OS === 'android'
? TouchableNativeFeedback.SelectableBackground()
: ''
}>
<View style={touchStyles.button}>
<Text style={touchStyles.buttonText}>TouchableNativeFeedback</Text>
</View>
</TouchableNativeFeedback>
<TouchableWithoutFeedback onPress={this._onPressButton}>
<View style={touchStyles.button}>
<Text style={touchStyles.buttonText}>
TouchableWithoutFeedback 001
</Text>
</View>
</TouchableWithoutFeedback>
<TouchableHighlight
onPress={this._onPressButton}
onLongPress={this._onLongPressButton}
underlayColor="white">
<View style={touchStyles.button}>
<Text style={touchStyles.buttonText}>
Touchable with long Press
</Text>
</View>
</TouchableHighlight>
{name ? <Text>prod 环境</Text> : <Text>未知环境</Text>}
</View>
);
}
}
const touchStyles = StyleSheet.create({
container: {
padding: 60,
alignItems: 'center',
},
button: {
marginBottom: 30,
width: 250,
backgroundColor: '#2196F3',
borderRadius: 30,
height: 60,
justifyContent: 'center',
},
buttonText: {
textAlign: 'center',
color: 'white',
fontSize: 16,
},
});
const Stack = createNativeStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
<Stack.Screen name="Modal" component={ModalScreen} />
<Stack.Screen name="WidgetDetails" component={WidgetDetails} />
<Stack.Screen name="KeyboardAvoiding" component={KeyboardAvoiding} />
<Stack.Screen name="PressableWidget" component={PressableWidget} />
<Stack.Screen
name="RefreshControlWidget"
component={RefreshControlWidget}
/>
<Stack.Screen name="ScrollView" component={ScrollViewWidget} />
<Stack.Screen name="SectionList" component={sectionListWidget} />
<Stack.Screen name="StatusBar" component={StatusBarWidget} />
<Stack.Screen name={'Switch'} component={SwitchWidget} />
<Stack.Screen name={'TextInANest'} component={TextInANest} />
<Stack.Screen
name={'TextInput'}
component={UselessTextInputMultiline}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;