|
1 | 1 | 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'; |
3 | 4 | import { compose } from 'redux'; |
4 | 5 | import fetch from 'fetch-hoc'; |
5 | 6 |
|
6 | 7 | import styles from '../Shared.style'; |
7 | 8 | import withHeader from '../../HOCs/withHeader'; |
8 | 9 |
|
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 | +} |
14 | 65 |
|
15 | 66 | 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') |
18 | 69 | )(CommitList); |
0 commit comments