Skip to content

Commit

Permalink
New link component and display
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoether committed Aug 28, 2020
1 parent c18c7e2 commit 2a8d240
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
53 changes: 53 additions & 0 deletions components/Link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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
},
})

15 changes: 15 additions & 0 deletions screens/NodeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {NavigationActions} from "react-navigation";
import Colors from "../constants/Colors";
import MicroTask from "../components/MicroTask";
import TextArea from "../components/TextArea";
import Link from "../components/Link";

class NodeScreen extends React.Component {
static navigationOptions = ({navigation}) => {
Expand Down Expand Up @@ -590,6 +591,20 @@ class NodeScreen extends React.Component {
}
}

if (fieldObject.view_mode_properties.type === 'link_default') {
let items = node[fieldName][lang];
for (let i = 0; i < items.length; i++) {
renderedNode.push(
<Link
key={`${fieldName}_link_${i}`}
navigation={this.props.navigation}
link={node[fieldName][lang][i]}
terms={this.props.terms}
nodes={this.props.screenProps.nodes}
/>)
}
}

});

let star = null;
Expand Down

0 comments on commit 2a8d240

Please sign in to comment.