forked from mayu-496/file
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart.js
More file actions
122 lines (100 loc) · 2.88 KB
/
Start.js
File metadata and controls
122 lines (100 loc) · 2.88 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
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
StatusBar ,
TextInput,
TouchableOpacity ,
Image,
FlatList,
} from 'react-native';
import Logo from '../components/Logo';
import {Actions} from 'react-native-router-flux';
export default class Start extends Component<{}> {
constructor(props){
super(props);
this.state ={ isLoading: true, dataSource : [] }
}
async componentDidMount() {
//Have a try and catch block for catching errors.
try {
//Assign the promise unresolved first then get the data using the json method.
const response = await fetch('http://192.168.2.21/vanns/App/image.php');
const pokemon = await response.json();
this.setState({dataSource: pokemon, isLoading: false});
} catch(err) {
console.log("Error fetching data-----------", err);
}
}
renderItem(data) {
return (
<TouchableOpacity style={{backgroundColor: 'transparent'}}>
<View style={styles.listItemContainer}>
<Text style={styles.pokeItemHeader}>{data.item.id}</Text>
<Text style={styles.pokeItemHeader}>{data.item.image}</Text>
<Image
source={ {uri: data.item.image} }
style={styles.image}
/>
</View>
</TouchableOpacity>
);
}
render() {
if(this.state.isLoading){
return(
<View >
<FlatList
data={this.state.dataSource}
renderItem={this.renderItem}
keyExtractor={({id}, index) => id}
/>
</View>
);
}
else {
return(
<View style={styles.container}>
<Logo/>
<TouchableOpacity
onPress={Actions.ologin}>
<Text style={styles.buttonText}>OWNER</Text>
<Image
source={require('../images/tenant1.jpeg')}
style={styles.image}
/>
</TouchableOpacity>
<TouchableOpacity
onPress={Actions.ologin}>
<Text style={styles.buttonText}>TENANT</Text>
<Image
source={require('../images/tenant1.jpeg')}
style={styles.image}
/>
</TouchableOpacity>
</View>
);
}
}
}
const styles = StyleSheet.create({
container : {
backgroundColor:'#E0F0EC',
flex: 1,
alignItems:'center',
justifyContent :'center',
},
buttonText: {
fontSize:20,
fontWeight:'500',
color:'#02edd5',
textAlign:'center',
fontWeight: 'bold',
},
image:{
height:150,
width:150,
marginVertical:20,
}
});