-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
208 lines (197 loc) · 4.02 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
import React from 'react';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import {
View,
Text,
FlatList,
AppRegistry,
ActivityIndicator,
ListView,
Alert,
Image,
Plat,
TouchableHighlight,
SafeAreaView,
StyleSheet,
ScrollView,
StatusBar,
ImageBackground,
} from 'react-native';
class ActivityHome extends React.Component<Props> {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
}
class ActivityProfile extends React.Component<Props> {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Hi Profile!</Text>
</View>
);
}
}
class ActivityList extends React.Component<Props> {
render() {
return (
<View style={styles.container}>
<FlatList
data={[
{key: 'Devin'},
{key: 'Dan'},
{key: 'Dominic'},
{key: 'Jackson'},
{key: 'James'},
{key: 'Joel'},
{key: 'John'},
{key: 'Jillian'},
{key: 'Jimmy'},
{key: 'Julie'},
]}
renderItem={({item}) => <Text style={styles.item}>{item.key}</Text>}
/>
</View>
);
}
}
class ActivityRow extends React.Component<Props> {
constructor(props) {
super(props);
this.state = {
isLoading: true,
navigate: this.props.navigation,
}
}
componentDidMount() {
return fetch('https://jsonplaceholder.typicode.com/users')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson,
}, function() {
});
},(err) => {
console.warn('error',err)
})
.catch((error) => {
console.error(error);
return error;
});
}
FlatListItemSeparator = () => {
return (
<View style={{height: 1,width: "100%",backgroundColor: "#607D8B"}} />
);
}
GetFlatListItem (fruit_name) {
Alert.alert(fruit_name);
}
renderItem(item) {
item.image='https://avatars2.githubusercontent.com/u/46446002?s=460&v=4';
return (
<TouchableHighlight underlayColor='#dddddd' onPress={() => this.state.navigate('Profile', {name: item.name})}>
<View style={styles.itemRow}>
<Image source={{uri: item.image}} style={styles.imageViewContainer}/>
<View style={styles.textViewContainer}>
<Text style={styles.Itemtitle} onPress={this.GetFlatListItem.bind(this, item.name)}>
{item.name}
</Text>
<Text style={styles.Itemsubtitle} onPress={this.GetFlatListItem.bind(this, item.name)}>
{item.company.catchPhrase}
</Text>
</View>
</View>
</TouchableHighlight>
);
}
static navigationOptions = {
title: 'Finder',
};
render() {
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return (
<View style={styles.MainContainer}>
<FlatList
data={ this.state.dataSource }
// ItemSeparatorComponent = {this.FlatListItemSeparator}
renderItem={({item}) => this.renderItem(item)}
keyExtractor={(item, index) => index}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 22
},
item: {
padding: 10,
fontSize: 18,
height: 44,
},
MainContainer :{
justifyContent: 'center',
flex:1,
margin: 5,
paddingTop: (Platform.OS === 'ios') ? 20 : 0,
},
itemRow: {
direction: 'rtl',
flex: 1,
flexDirection: 'row-reverse',
// flexWrap: 'wrap',
alignItems: 'flex-end'
},
imageViewContainer: {
width: 44,
height: 44,
margin: 10,
borderRadius: 22,
},
textViewContainer: {
width:'auto',
paddingTop: 10,
// padding:20
},
Itemtitle: {
width: '100%',
textAlign: 'right',
},
Itemsubtitle: {
width: '100%',
color: '#ababab',
// backgroundColor: 'green',
textAlign: 'right',
},
})
const AppNavigator = createStackNavigator({
Home: {
screen: ActivityHome,
},
List: {
screen: ActivityList,
},
Row: {
screen: ActivityRow,
},
Profile: {
screen: ActivityProfile,
},
}, {
initialRouteName: "Row",
});
export default createAppContainer(AppNavigator);