-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
93 lines (86 loc) · 2.35 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
import React, { Component } from "react";
import { View, Text, StyleSheet, FlatList, ActivityIndicator } from "react-native";
import { List, ListItem, SearchBar, withTheme } from "react-native-elements";
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
class HomeScreen extends Component {
state = {
data: [],
}
componentDidMount() {
fetch(`https://jsonplaceholder.typicode.com/users`)
.then(res => res.json())
.then(res => {
this.setState({
data: res,
});
})
.catch(error => {
console.log(error)
});
}
render() {
return (
<View style={styles.container}>
<Text style={{ width: "90%", textAlign: "center", marginTop: "8%", color: "white", fontSize: 20 }}>Fetched Data</Text>
<View style={{borderBottomColor: 'lightgrey', width:"90%",
borderBottomWidth: 0.5,
marginLeft: 5,
paddingLeft:5,
paddingRight:5,
paddingBottom:10,
marginBottom:"8%",
marginRight: 5}}></View>
<FlatList style={{width:"90%",
}}
data={this.state.data}
renderItem={({ item }) => (
<ListItem
roundAvatar
title={item.name}
subtitle={item.email}
contentContainerStyle={{
borderBottomColor: 'lightgrey',
borderBottomWidth: 0.5,
marginLeft: 5,
paddingLeft:5,
paddingRight:5,
paddingBottom:10,
marginRight: 5
}}
/>
)}
/>
</View>
);
}
}
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer >
<Stack.Navigator >
<Stack.Screen name="Home" component={HomeScreen}
options={{
title: 'My home',
headerStyle: {
backgroundColor: 'white',
},
headerTintColor: '#000',
headerTitleStyle: {
fontWeight: 'bold',
},
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
backgroundColor: '#282C34',
},
});