import React, { Component } from 'react';
import {
ScrollView,
StyleSheet,
TouchableOpacity,
Image,
View,
RefreshControl,
} from 'react-native';
import HTMLView from 'react-native-htmlview'
import htmlStyles from '../components/htmlStyles'
import ClearText from '../components/text'
import Heading from '../components/heading'
import Definition from '../components/definition'
import Close from '../components/close'
const isIphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))
const isIpad = (navigator.userAgent.match(/iPad/i))
const isAndroid = (navigator.userAgent.match(/Android/i))
const isMobile = isIphone || isIpad || isAndroid
const isDesktop = ! isMobile
const imageHeight = isMobile ? 250 : 450
const imageWidth = isMobile ? 400 : 1000
export default class TimelineFull extends Component {
constructor() {
super()
this.onRefresh = this.onRefresh.bind(this)
this.onPickTag = this.onPickTag.bind(this)
}
onRefresh() {
this.props.onClose()
}
onPickTag(tag) {
this.props.onFilter(tag)
}
render() {
const item = this.props.item
let image, links;
if (! item) {
return ( )
}
if (item.image) {
const caption = item.credit ? (
{item.credit}
) : (
)
const originalWidth = Number(item.image.width)
const originalHeight = Number(item.image.height)
let height = originalHeight > imageHeight ? imageHeight : originalHeight
let width = originalWidth * height / originalHeight
console.warn(width, imageWidth)
if (width > imageWidth) {
width = imageWidth
height = originalHeight * imageWidth / originalWidth
}
image = (
{caption}
)
} else {
image = ( )
}
if (item.links.length) {
const linkItems = item.links.map((link, i) => {
const url = link.uri
let name = link.text
if (! name || name.match(/Link Text/i)) {
name = linkTextFromUrl(url)
}
return (
this.props.onLinkPress(url)}>
{name}
)
})
links = (
{linkItems}
)
}
const tags = item.keywords.map((tag, i) => {
return `${tag}`
}).join(', ')
const description = '
' + item.description.replace(/\n+/g,'\n\n') + '
'
return (
{image}
{item.title}
{item.date}
{item.medium}
this.onPickTag(item.category)}>
{item.category}
' + tags + ''} stylesheet={tagHTMLStyles} onLinkPress={this.onPickTag} />
{links}
)
}
}
function linkTextFromUrl (url) {
const url_parts = url.split('/')
const domain = url_parts[2]
const terms = domain.split('.')
const len = terms.length
let term = (len > 2 && terms[len-1].length == 2) ? terms[len-3] : terms[len-2]
if (term == 'wikipedia') {
term += url_parts[4].replace(/\#.*/,'').replace('_', ' ')
}
return capitalize(term)
}
function capitalize (s){
return s.charAt(0).toUpperCase() + s.slice(1)
}
const mobileStyles = StyleSheet.create({
item: {
maxWidth: 400,
maxHeight: 250,
padding: 40,
paddingTop: 50,
},
bodyContainer: {
width: '100%',
},
metadataContainer: {
width: '100%',
},
})
const styles = StyleSheet.create({
container: {
flex: 1,
},
scrollView: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'black',
},
item: {
maxWidth: isMobile ? 400 : 1000,
padding: 40,
},
imageContainer: {
width: '100%',
marginBottom: 10,
alignItems: 'center',
},
imageWrapper: {
width: '100%',
marginBottom: 5,
alignItems: 'center',
},
caption: {
fontSize: 12,
},
bodyContainer: {
left: '0%',
width: '60%',
paddingRight: 50,
},
metadataContainer: {
position: 'absolute',
top: 0,
left: '60%',
width: '40%',
},
title: {
textAlign: 'left',
fontWeight: 'bold',
fontSize: 18,
},
date: {
textAlign: 'left',
},
description: {
flex: 1,
flexDirection: 'column',
},
link: {
textDecorationLine: 'underline',
textAlign: 'left',
},
tag: {
marginRight: 5,
},
})
const tagHTMLStyles = StyleSheet.create({
p: {
color: 'white',
fontFamily: '"Futura-Medium", sans-serif',
textAlign: 'justify',
fontSize: 16,
lineHeight: 30,
},
b: {
fontFamily: '"Futura-MediumItalic", sans-serif',
color: 'white',
fontSize: 16,
lineHeight: 30,
},
i: {
fontFamily: '"Futura-MediumItalic", sans-serif',
color: 'white',
fontSize: 16,
lineHeight: 30,
},
a: {
color: 'white',
fontFamily: '"Futura-Medium", sans-serif',
textDecorationLine: 'underline',
fontSize: 16,
lineHeight: 30,
},
})