Skip to content

Commit 27a7867

Browse files
committed
Render commits data
1 parent 334197c commit 27a7867

1 file changed

Lines changed: 59 additions & 8 deletions

File tree

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,69 @@
11
import React from 'react';
2-
import { Text, View } from 'react-native';
2+
import { ActivityIndicator, Dimensions, FlatList, Platform, View } from 'react-native';
3+
import { Avatar, ListItem } from 'react-native-elements';
34
import { compose } from 'redux';
45
import fetch from 'fetch-hoc';
56

67
import styles from '../Shared.style';
78
import withHeader from '../../HOCs/withHeader';
89

9-
const CommitList = () => (
10-
<View style={styles.container}>
11-
<Text>Placeholder for second screen</Text>
12-
</View>
13-
);
10+
const containerStyle = {
11+
alignItems: 'flex-start',
12+
borderBottomWidth: 1,
13+
flex: 1,
14+
width: Dimensions.get('window').width
15+
};
16+
17+
const subtitleStyle = { color: 'rgba(0, 0, 0, 0.54)' };
18+
19+
const leftElementStyle = {
20+
height: '100%',
21+
marginRight: Platform.OS === 'web' ? 10 : 0
22+
};
23+
24+
class CommitList extends React.PureComponent {
25+
keyExtractor = (item) => item.sha
26+
27+
renderLeftElement = (item) => (
28+
<View style={leftElementStyle}>
29+
<Avatar
30+
source={{ uri: item.author.avatar_url }}
31+
size='medium'
32+
rounded
33+
/>
34+
</View>
35+
)
36+
37+
renderItem = ({ item }) => (
38+
<ListItem
39+
title={item.commit.author.name}
40+
subtitle={item.commit.message}
41+
leftElement={this.renderLeftElement(item)}
42+
containerStyle={containerStyle}
43+
subtitleStyle={subtitleStyle}
44+
/>
45+
)
46+
47+
renderContent = () => (
48+
this.props.loading ?
49+
<ActivityIndicator color='#87ceeb' /> :
50+
<FlatList
51+
keyExtractor={this.keyExtractor}
52+
data={this.props.data}
53+
renderItem={this.renderItem}
54+
/>
55+
)
56+
57+
render() {
58+
return (
59+
<View style={styles.container}>
60+
{this.renderContent()}
61+
</View>
62+
);
63+
}
64+
}
1465

1566
export default compose(
16-
fetch('https://api.github.com/repos/react-native-training/react-native-elements/commits'),
17-
withHeader({ title: 'Commits' })
67+
withHeader({ title: 'Commits' }),
68+
fetch('https://api.github.com/repos/react-native-training/react-native-elements/commits')
1869
)(CommitList);

0 commit comments

Comments
 (0)