-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLink.js
53 lines (44 loc) · 1.21 KB
/
Link.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
import React from 'react'
import {Linking, Text, TouchableOpacity, StyleSheet} from "react-native";
import {get, has} from 'lodash';
import {NavigationActions} from "react-navigation";
import Colors from "../constants/Colors";
export default function Link({link, navigation, nodes, terms}) {
const inAppLink = get(link, ['attributes', 'muk-app'], false);
let nid = null;
if (inAppLink) {
const linkParts = link.url.split('/');
nid = linkParts.slice(-1)[0];
if (!has(nodes, [nid])) {
return null;
}
}
const onLinkPress = () => {
if (nid != null) {
const navigateAction = NavigationActions.navigate({
routeName: 'Node',
params: {
contentType: nodes[nid].type,
contentTypeLabel: nodes[nid].title,
node: nodes[nid],
terms: terms
},
key: `node-view-${nid}`
});
navigation.dispatch(navigateAction);
}
else {
Linking.openURL(link.url);
}
}
return (<TouchableOpacity onPress={onLinkPress}>
<Text style={styles.nodeTitle}>{link.title}</Text>
</TouchableOpacity>);
}
const styles = StyleSheet.create({
nodeTitle: {
fontSize: 16,
marginBottom: 3,
color: Colors.primary
},
})