ios: Open more links directly in apps

bump ver
This commit is contained in:
Nikolai R Kristiansen committed 2017-09-17 23:53:48 +02:00
1 parent 318158f2b3
commit 992f9ccffd
4 files changed
+74 -21

No files matched your search

+19 -2
View File
@@ -11,7 +11,10 @@ export default class About extends Component {
openFacebook() {
/* Ref: https://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app */
const url = 'fb://page/23664032291/';
const url = Platform.select({
ios: 'fb://page/?id=23664032291',
android: 'fb://page/23664032291/'
});
Linking.canOpenURL(url).then(supported => {
if (!supported) {
return Linking.openURL('https://www.facebook.com/studentersamfundet/');
@@ -36,6 +39,20 @@ export default class About extends Component {
}).catch(err => console.error('An error occurred', err));
}
openMap() {
const url = Platform.select({
ios: `comgooglemaps://?q=${CHATEAU_NEUF_ADDRESS}`,
android: `https://www.google.com/maps/search/?api=1&query=${CHATEAU_NEUF_ADDRESS}`
});
Linking.canOpenURL(url).then(supported => {
if (!supported) {
return Linking.openURL(`https://www.google.com/maps/search/?api=1&query=${CHATEAU_NEUF_ADDRESS}`);
} else {
return Linking.openURL(url);
}
}).catch(err => console.error('An error occurred', err));
}
render() {
return (
<ScrollView>
@@ -57,7 +74,7 @@ export default class About extends Component {
<Text style={styles.header}>Adresse</Text>
<Text style={[styles.paragraph, {textAlign: 'center'}]}>Det Norske Studentersamfund{"\n"}Slemdalsveien 15, 0369 Oslo</Text>
<View style={styles.section}>
<Button iconLeft onPress={() => Linking.openURL(`https://www.google.com/maps/search/?api=1&query=${CHATEAU_NEUF_ADDRESS}`)}>
<Button iconLeft onPress={this.openMap}>
<Icon name="map" style={styles.icon} /><NBText> Vis i kart</NBText>
</Button>
</View>
+24 -3
View File
@@ -73,9 +73,30 @@ export default class EventDetail extends Component {
return text;
}
onUrlPress(link) {
onTicketUrlPress(link) {
Linking.openURL(link);
}
onFacebookUrlPress(link) {
const fbEventPattern = /https?:\/\/www\.facebook\.com\/events\/(\d+)\/?/i;
const matches = fbEventPattern.exec(link);
let iosURL = link;
if( matches.length ) {
iosURL = 'fb://event/?id=' + matches[1];
}
const url = Platform.select({
ios: iosURL,
android: link
});
Linking.canOpenURL(url).then(supported => {
if (!supported) {
return Linking.openURL(link);
} else {
return Linking.openURL(url);
}
}).catch(err => console.error('An error occurred', err));
}
onLocationPress(venue) {
if( venue !== 'Annetsteds' ) {
Linking.openURL(`https://www.google.com/maps/dir/?api=1&destination=${CHATEAU_NEUF_ADDRESS}`);
@@ -92,7 +113,7 @@ export default class EventDetail extends Component {
if(item.ticket_url) {
return (
<TouchableOpacity style={styles.metaInner} onPress={() => this.onUrlPress(item.ticket_url)}>
<TouchableOpacity style={styles.metaInner} onPress={() => this.onTicketUrlPress(item.ticket_url)}>
<View style={styles.metaIcon}><Icon name="card" style={styles.icons} /></View>
<View style={{flexDirection: 'column'}}>
<Text style={styles.metaText}>{text}</Text>
@@ -116,7 +137,7 @@ export default class EventDetail extends Component {
if (!item.facebook_url) { return;}
return (
<TouchableOpacity onPress={() => this.onUrlPress(item.facebook_url)} style={styles.metaInner}>
<TouchableOpacity onPress={() => this.onFacebookUrlPress(item.facebook_url)} style={styles.metaInner}>
<View style={[styles.metaIcon, {marginTop: 0}]}><Icon name="logo-facebook" style={styles.icons} /></View>
<View>
<Text style={[styles.metaText, {paddingTop: 2}]}>På Facebook</Text>