-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tab1.js
84 lines (69 loc) · 1.83 KB
/
Tab1.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
import React, { Component } from 'react';
import { Alert, View, ActivityIndicator } from 'react-native';
import { Container, Content, List, Text } from 'native-base';
import {getArticles} from './service/news';
import DataItem from './component/dataitem';
import Modal from './component/modal';
export default class Tab1 extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
data: null,
setModalVisible:false,
modalArticleData:{}
}
}
handleItemDataOnPress = (articleData) => {
this.setState({
setModalVisible: true,
modalArticleData: articleData
});
}
handleModalClose = () => {
this.setState({
setModalVisible: false,
modalArticleData: {}
});
}
componentDidMount() {
getArticles().then(data => {
this.setState({
isLoading: false,
data: data
});
}, error => {
Alert.alert('Error', 'Something went wrong!');
}
)
}
render() {
console.log(this.state.data);
let view = this.state.isLoading ? (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center',marginTop:20 }}>
<ActivityIndicator animating={this.state.isLoading} color="#00f0ff" />
<Text style={{marginTop: 10}} children="Please Wait.." />
</View>
) : (
<List
dataArray={this.state.data}
renderRow={(item) => {
return (
<DataItem onPress={this.handleItemDataOnPress} data={item} />
)
}} />
)
return (
<Container>
<Content>
{view}
</Content>
<Modal
showModal={this.state.setModalVisible}
articleData={this.state.modalArticleData}
onClose={this.handleModalClose}
/>
</Container>
);
}
}