-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.ios.js
361 lines (334 loc) · 9.23 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/* @flow */
import bugsnag from './bugsnag-native';
import regenerator from 'regenerator/runtime';
import React from 'react-native';
import Icon from 'FAKIconImage';
import dedent from 'dedent';
import Parse from './parse';
var {
AlertIOS,
AppRegistry,
AsyncStorage,
Image,
LinkingIOS,
NavigatorIOS,
PushNotificationIOS,
StatusBarIOS,
StyleSheet,
Text,
TouchableOpacity,
View
} = React;
ErrorUtils.setGlobalHandler(error => bugsnag.notify(error));
// TODO: Bind
class LondonReact extends React.Component {
componentWillMount() {
StatusBarIOS.setStyle('light-content');
PushNotificationIOS.addEventListener('register', this._savePushToken);
PushNotificationIOS.addEventListener('notification', this._notificationReceived);
PushNotificationIOS.requestPermissions(this._savePushToken);
}
async _savePushToken(token) {
await AsyncStorage.setItem('pushToken', token);
await Parse.registerInstallation(token);
}
async _registerInstallation() {
let pushToken = await AsyncStorage.getItem('pushToken');
try {
return await Parse.registerInstallation(pushToken);
} catch (e) {
AlertIOS.alert(`Unable to register installation. ${e}`);
}
}
_notificationReceived(notification) {
AlertIOS.alert(notification);
}
render() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={{
component: CurrentMeetup,
title: 'London React Meetup',
}}
tintColor="#7ed3f4"
barTintColor="#1b1d24"
titleTextColor="#ffffff"
/>
);
}
}
class CurrentMeetup extends React.Component {
state = {
attending: null
}
talks = [
{
name: 'Yacine Rezgui',
title: 'Import.io',
talk: 'Live coding with Native modules ',
synopsis: dedent`
Yacine will create a small application that uses the microphone to do speech to text with a native module communicating to the React code (iOS).
`,
bioPic: 'https://pbs.twimg.com/profile_images/533643942131425280/PZbS9agy.jpeg',
twitter: 'yrezgui',
github: 'yrezgui'
},
{
name: 'Viktor Charypar',
title: 'Red Badger',
talk: 'GraphQL at The Financial Times',
synopsis: dedent`
Recently released by Facebook, GraphQL isn't only useful for client-server communication. Viktor will show how Red Badger used the reference implementation - graphql-js - at theFinancial Times as a generic data presentation layer over a set of backend APIs and how to deal with related requirements like caching or authorisation.
`,
bioPic: 'https://pbs.twimg.com/profile_images/567296628315267073/BKibFa5T_400x400.jpeg',
twitter: 'charypar',
github: 'charypar'
},
{ name: 'Prospective Speaker', talk: 'Speaking Slot Available', empty: true },
];
constructor() {
super();
this._fetchAttendees();
}
async _fetchAttendees() {
const apiKey = process.env.MEETUP_API_KEY;
const eventId = 224090322;
const url = `https://api.meetup.com/2/event/${eventId}?key=${apiKey}&sign=true&photo-host=public&page=20`;
let json;
try {
const response = await fetch(url);
json = await response.json();
} catch(e) {
AlertIOS.alert('Failed to fetch attendees');
}
this.setState({attending: json.yes_rsvp_count});
}
render() {
return (
<View style={styles.emptyPage}>
<Date date="Tuesday, August 4, 2015" />
<Venue name="Facebook HQ" address="10 Brock Street, Regents Place, London" />
<Talks talks={this.talks} navigator={this.props.navigator} />
<Attending count={this.state.attending} />
</View>
);
}
}
// @PureRender / @Debug
class Date extends React.Component {
_openCalendar() {
LinkingIOS.openURL('calshow://');
}
render() {
return (
<TouchableOpacity onPress={this._openCalendar.bind(this)}>
<View style={styles.section} onPress={this._openCalendar}>
<StyledText style={styles.sectionTitle}>Date</StyledText>
<StyledText>{this.props.date}</StyledText>
</View>
</TouchableOpacity>
);
}
}
class Venue extends React.Component {
_openMaps() {
LinkingIOS.openURL('http://maps.apple.com/?q=' + encodeURIComponent(`${this.props.name}, ${this.props.address}`));
}
render() {
return (
<TouchableOpacity onPress={this._openMaps.bind(this)}>
<View style={styles.section}>
<StyledText style={styles.sectionTitle}>Venue</StyledText>
<StyledText>{this.props.name}</StyledText>
<StyledText>{this.props.address}</StyledText>
</View>
</TouchableOpacity>
);
}
}
class Button extends React.Component {
render() {
return (
<TouchableOpacity onPress={this.props.onPress}>
<View style={[this.props.style, styles.button]}>
{this.props.icon && <Icon
name={`fontawesome|${this.props.icon}`}
size={30}
color="rgba(255, 255, 255, 0.8)"
style={styles.icon}
/>}
<StyledText style={styles.buttonText}>{this.props.text}</StyledText>
</View>
</TouchableOpacity>
);
}
}
class Twitter extends React.Component {
_open() {
const twitterAppURL = `twitter://user?screen_name=${this.props.handle}`;
const browserURL = `https://twitter.com/${this.props.handle}`;
LinkingIOS.canOpenURL(twitterAppURL, supported => {
LinkingIOS.openURL(supported ? twitterAppURL : browserURL);
});
}
render() {
return (
<Button icon="twitter" text={`@${this.props.handle}`} onPress={this._open.bind(this)} />
);
}
}
class Github extends React.Component {
_open() {
LinkingIOS.openURL(`https://github.com/${this.props.handle}`);
}
render() {
return (
<Button icon="github" text={this.props.handle} onPress={this._open.bind(this)} style={{borderLeftWidth: 1}} />
);
}
}
class TalkDetails extends React.Component {
render() {
return (
<View style={styles.emptyPage}>
<StyledText>{this.props.title}</StyledText>
<View style={styles.bioContainer}>
<View>
<Image
style={styles.bioPic}
source={{uri: this.props.speaker.bioPic}}
/>
</View>
<StyledText style={styles.sectionTitle}>{this.props.speaker.name}</StyledText>
<StyledText>{this.props.speaker.title}</StyledText>
<StyledText style={styles.synopsis} numberOfLines={16}>{this.props.speaker.synopsis}</StyledText>
</View>
<View style={styles.buttonContainer}>
<Twitter handle={this.props.speaker.twitter} />
<Github handle={this.props.speaker.github} />
</View>
</View>
);
}
}
class Talks extends React.Component {
render() {
return (
<View style={[styles.section, {flex: 1}]}>
<StyledText style={styles.sectionTitle}>Talks</StyledText>
{this.props.talks.map(speaker => <Talk speaker={speaker} navigator={this.props.navigator} />)}
</View>
);
}
}
class Talk extends React.Component {
_talkDetails() {
if (this.props.speaker.empty) { return; }
this.props.navigator.push({
title: this.props.speaker.talk,
component: TalkDetails,
passProps: this.props
});
}
render() {
const {speaker} = this.props;
return (
<TouchableOpacity onPress={this._talkDetails.bind(this)}>
<View style={styles.talk}>
<StyledText style={styles.talkTitle}>{speaker.talk}</StyledText>
<StyledText>{speaker.name}</StyledText>
<StyledText>{speaker.title}</StyledText>
</View>
</TouchableOpacity>
);
}
}
class Attending extends React.Component {
render() {
return (
<View style={[styles.section, {borderBottomWidth: 0}]}>
<StyledText>{this.props.count ? `${this.props.count} Attending` : 'Loading...'}</StyledText>
</View>
);
}
}
class StyledText extends React.Component {
render() {
return (
<Text {...this.props} style={[styles.text, this.props.style]}/>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#1b1d24'
},
text: {
color: 'white'
},
emptyPage: {
flex: 1,
paddingTop: 64,
backgroundColor: '#1b1d24',
},
emptyPageText: {
margin: 10,
},
section: {
marginLeft: 20,
marginRight: 20,
padding: 20,
borderBottomWidth: 1,
borderColor: '#484848'
},
talk: {
paddingTop: 20,
paddingBottom: 10
},
sectionTitle: {
fontSize: 20,
},
talkTitle: {
fontSize: 16,
fontWeight: 'bold',
},
bioContainer: {
flex: 1,
alignItems: 'center'
},
bioPic: {
width: 180,
height: 180,
borderRadius: 90,
borderColor: 'white',
borderWidth: 3
},
attending: {
justifyContent: 'center'
},
buttonContainer: {
marginTop: 10,
flexDirection: 'row',
},
button: {
flex: 1,
alignItems: 'center',
borderTopWidth: 1,
borderTopColor: 'rgba(255, 255, 255, 0.2)',
borderLeftColor: 'rgba(255, 255, 255, 0.2)',
padding: 5,
},
buttonText: {
color: 'rgba(255, 255, 255, 0.8)'
},
icon: {
width: 30,
height: 30
},
synopsis: {
margin: 10,
}
});
AppRegistry.registerComponent('LondonReact', () => LondonReact);