Skip to content

Commit 2bde0c4

Browse files
committed
Merge branch 'master' into tableviewsimpletypes
* master: nativify android calendar detail
2 parents 7761083 + 33a2d87 commit 2bde0c4

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @flow
2+
import type {EventType} from './types'
3+
import {fastGetTrimmedText} from '../../lib/html'
4+
import getUrls from 'get-urls'
5+
import {times} from './times'
6+
7+
export function cleanEvent(event: EventType): EventType {
8+
const title = fastGetTrimmedText(event.summary || '')
9+
const summary = fastGetTrimmedText(event.extra.data.description || '')
10+
const rawSummary = cleanDescription(event.extra.data.description || '')
11+
const location = fastGetTrimmedText(event.location || '')
12+
const times = getTimes(event) ? getTimes(event) : ''
13+
14+
return {
15+
...event,
16+
title,
17+
summary,
18+
rawSummary,
19+
location,
20+
times,
21+
}
22+
}
23+
24+
function cleanDescription(desc: string) {
25+
const description = fastGetTrimmedText(desc || '')
26+
if (description == 'See more details') {
27+
return ''
28+
}
29+
30+
return description
31+
}
32+
33+
export function getTimes(event: EventType) {
34+
const {allDay, start, end} = times(event)
35+
36+
if (allDay) {
37+
return 'All-Day'
38+
}
39+
40+
return `${start}${end}`
41+
}
42+
43+
export function getLinksFromEvent(event: EventType) {
44+
// Clean up returns, newlines, tabs, and misc symbols...
45+
// ...and search for links in the text
46+
const description = event.extra.data.description || ''
47+
return Array.from(getUrls(description))
48+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// @flow
2+
import React from 'react'
3+
import {Text, ScrollView, StyleSheet, Share} from 'react-native'
4+
import type {EventType} from './types'
5+
import {ShareButton} from '../components/nav-buttons'
6+
import openUrl from '../components/open-url'
7+
import {Card} from '../components/card'
8+
import {cleanEvent, getTimes, getLinksFromEvent} from './clean-event'
9+
import * as c from '../components/colors'
10+
11+
const styles = StyleSheet.create({
12+
name: {
13+
textAlign: 'center',
14+
marginTop: 20,
15+
marginBottom: 15,
16+
paddingHorizontal: 5,
17+
color: c.black,
18+
fontSize: 32,
19+
fontWeight: '300',
20+
},
21+
card: {
22+
marginBottom: 20,
23+
},
24+
cardBody: {
25+
color: c.black,
26+
paddingTop: 13,
27+
paddingBottom: 13,
28+
paddingLeft: 16,
29+
paddingRight: 16,
30+
fontSize: 16,
31+
},
32+
})
33+
34+
function Title({event}: {event: EventType}) {
35+
return event.title ? <Text style={styles.name}>{event.title}</Text> : null
36+
}
37+
38+
function Description({event}: {event: EventType}) {
39+
return event.rawSummary
40+
? <Card header="Description" style={styles.card}>
41+
<Text style={styles.cardBody}>
42+
{event.rawSummary}
43+
</Text>
44+
</Card>
45+
: null
46+
}
47+
48+
function When({event}: {event: EventType}) {
49+
return event.times
50+
? <Card header="When" style={styles.card}>
51+
<Text style={styles.cardBody}>
52+
{event.times}
53+
</Text>
54+
</Card>
55+
: null
56+
}
57+
58+
function Location({event}: {event: EventType}) {
59+
return event.location
60+
? <Card header="Location" style={styles.card}>
61+
<Text style={styles.cardBody}>
62+
{event.location}
63+
</Text>
64+
</Card>
65+
: null
66+
}
67+
68+
function Links({event}: {event: EventType}) {
69+
const links = getLinksFromEvent(event)
70+
return links.length
71+
? <Card header="Links" style={styles.card}>
72+
{links.map(url =>
73+
<Text key={url} style={styles.cardBody} onPress={() => openUrl(url)}>
74+
{url}
75+
</Text>,
76+
)}
77+
</Card>
78+
: null
79+
}
80+
81+
const shareItem = (event: EventType) => {
82+
const times = getTimes(event)
83+
const message = `${event.summary}\n\n${times}\n\n${event.location}`
84+
Share.share({message})
85+
.then(result => console.log(result))
86+
.catch(error => console.log(error.message))
87+
}
88+
89+
export function EventDetail(props: {
90+
navigation: {state: {params: {event: EventType}}},
91+
}) {
92+
const event = cleanEvent(props.navigation.state.params.event)
93+
return (
94+
<ScrollView>
95+
<Title event={event} />
96+
<When event={event} />
97+
<Location event={event} />
98+
<Description event={event} />
99+
<Links event={event} />
100+
</ScrollView>
101+
)
102+
}
103+
104+
EventDetail.navigationOptions = ({navigation}) => {
105+
const {event} = navigation.state.params
106+
return {
107+
title: event.summary,
108+
headerRight: <ShareButton onPress={() => shareItem(event)} />,
109+
}
110+
}
File renamed without changes.

0 commit comments

Comments
 (0)