diff options
Diffstat (limited to 'src/view/com/util')
-rw-r--r-- | src/view/com/util/Link.tsx | 27 | ||||
-rw-r--r-- | src/view/com/util/RichText.tsx | 27 |
2 files changed, 37 insertions, 17 deletions
diff --git a/src/view/com/util/Link.tsx b/src/view/com/util/Link.tsx index 4931438b8..ff3d25cb5 100644 --- a/src/view/com/util/Link.tsx +++ b/src/view/com/util/Link.tsx @@ -1,6 +1,7 @@ import React from 'react' import {observer} from 'mobx-react-lite' import { + Linking, StyleProp, Text, TouchableOpacity, @@ -8,6 +9,7 @@ import { ViewStyle, } from 'react-native' import {useStores} from '../../../state' +import {RootStoreModel} from '../../../state' import {LinkActionsModel} from '../../../state/models/shell-ui' export const Link = observer(function Link({ @@ -23,13 +25,10 @@ export const Link = observer(function Link({ }) { const store = useStores() const onPress = () => { - store.shell.closeModal() // close any active modals - store.nav.navigate(href) + handleLink(store, href, false) } const onLongPress = () => { - store.shell.closeModal() // close any active modals - store.nav.newTab(href, title) - // store.shell.openModal(new LinkActionsModel(href, title || href)) + handleLink(store, href, true) } return ( <TouchableOpacity @@ -55,12 +54,10 @@ export const TextLink = observer(function Link({ }) { const store = useStores() const onPress = () => { - store.shell.closeModal() // close any active modals - store.nav.navigate(href) + handleLink(store, href, false) } const onLongPress = () => { - store.shell.closeModal() // close any active modals - store.nav.newTab(href, title) + handleLink(store, href, true) } return ( <Text style={style} onPress={onPress} onLongPress={onLongPress}> @@ -68,3 +65,15 @@ export const TextLink = observer(function Link({ </Text> ) }) + +function handleLink(store: RootStoreModel, href: string, longPress: boolean) { + if (href.startsWith('http')) { + Linking.openURL(href) + } else if (longPress) { + store.shell.closeModal() // close any active modals + store.nav.newTab(href) + } else { + store.shell.closeModal() // close any active modals + store.nav.navigate(href) + } +} diff --git a/src/view/com/util/RichText.tsx b/src/view/com/util/RichText.tsx index 35948455a..f865c873a 100644 --- a/src/view/com/util/RichText.tsx +++ b/src/view/com/util/RichText.tsx @@ -32,14 +32,25 @@ export function RichText({ if (typeof segment === 'string') { els.push(segment) } else { - els.push( - <TextLink - key={key} - text={segment.text} - href={`/profile/${segment.entity.value}`} - style={[style, s.blue3]} - />, - ) + if (segment.entity.type === 'mention') { + els.push( + <TextLink + key={key} + text={segment.text} + href={`/profile/${segment.entity.value}`} + style={[style, s.blue3]} + />, + ) + } else if (segment.entity.type === 'link') { + els.push( + <TextLink + key={key} + text={segment.text} + href={segment.entity.value} + style={[style, s.blue3]} + />, + ) + } } key++ } |