-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
118 lines (104 loc) · 2.67 KB
/
index.ios.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
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Dimensions,
FlatList,
NativeModules,
NativeEventEmitter,
Alert,
} from 'react-native';
import FlatItem from './FlatItem';
export default class FetchTest extends Component {
constructor(props) {
super(props);
this.state = {
data: []
}
const { SendToRN } = NativeModules;
const SendToRNEmitter = new NativeEventEmitter(SendToRN);
const subscription = SendToRNEmitter.addListener(
'RefreshEvent',
(dict) => {
alert(dict.value);
}
);
}
componentDidMount() {
this.loadData();
this.timer = setInterval(() => {
// console.log("aaaaaa");
this.loadData();
}, 2000);
}
componentWillUnmount() {
this.timer && clearInterval(this.timer);
subscription.remove();
}
Item = ({item}) => {
return(
<FlatItem item={item}/>
);
}
loadData = () => {
this.setState({
data:[]
});
var LoadHttp = NativeModules.LoadHttp;
LoadHttp.loadData((response) => {
// console.log("****" + response);
// console.log("****" + response.success);
if (response.success == 1){
//请求成功
this.setState({data: response.value});
}else {
//网络请求失败
Alert.alert("请求失败");
}
});
}
render() {
return (
<View>
<View style={styles.containerView}>
<FlatList style={styles.topFlat}
data={this.state.data}
renderItem={this.Item}
horizontal={true}
keyExtractor={(item, index) => item.code}
showsHorizontalScrollIndicator={false}
ItemSeparatorComponent = {SeparatorComponent}
showsVerticalScrollIndicator={false}
/>
</View>
</View>
);
}
}
class SeparatorComponent extends Component {
render() {
return (
<View style={styles.separatorComponent}/>
);
}
}
const {ScreenWidth, ScreenHeight} = Dimensions.get('window');
const styles = StyleSheet.create({
containerView: {
height: 90,
width:ScreenWidth,
backgroundColor:'azure',
},
topFlat: {
height: 90,
width:ScreenWidth,
},
separatorComponent:{
backgroundColor:'aliceblue',
width:2,
height:90,
}
});
AppRegistry.registerComponent('FetchTest', () => FetchTest);