Skip to content

Instantly share code, notes, and snippets.

@Jahans3
Created August 18, 2017 12:53
Show Gist options
  • Save Jahans3/ff632dad937ede82d12449fa073b9c24 to your computer and use it in GitHub Desktop.
Save Jahans3/ff632dad937ede82d12449fa073b9c24 to your computer and use it in GitHub Desktop.
import React from 'react'
import PropTypes from 'prop-types'
import { Image, TouchableOpacity } from 'react-native'
import { View, Text } from 'native-base'
import moment from 'moment'
import style from './style'
const Post = ({
author,
title,
description,
urlToImage: uri,
url,
publishedAt: date,
onPress
}) => (
<TouchableOpacity onPress={onPress} style={style.containerWrapper}>
<View style={style.container}>
{
uri && (
<View style={style.imageWrapper}>
<Image source={{ uri }} style={style.image} />
</View>
)
}
<View style={style.contentWrapper}>
<View style={style.headerWrapper}>
{
author && (
<View style={style.authorWrapper}>
<Text style={style.author}>{author}</Text>
</View>
)
}
{
date && (
<View style={style.dateWrapper}>
<Text style={style.date}>{moment(date).format('L')}</Text>
</View>
)
}
</View>
{
title && (
<View style={style.titleWrapper}>
<Text style={style.title}>{title}</Text>
</View>
)
}
<View style={style.descriptionWrapper}>
<Text style={style.description}>{description}</Text>
</View>
</View>
</View>
</TouchableOpacity>
)
Post.propTypes = {
author: PropTypes.string,
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
urlToImage: PropTypes.string,
url: PropTypes.string.isRequired,
publishedAt: PropTypes.string,
onPress: PropTypes.func.isRequired
}
export default Post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment