about summary refs log tree commit diff
path: root/src/view/com
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-11-18 11:37:25 -0600
committerPaul Frazee <pfrazee@gmail.com>2022-11-18 11:37:25 -0600
commit368286ad67436e379324be9f81f9e2949ebff12c (patch)
tree16ec9c08d76e1fe601d25516f896a603e38009c7 /src/view/com
parent2f9dd131f9d2db2e5d66c20f1ff576f292cdd46a (diff)
downloadvoidsky-368286ad67436e379324be9f81f9e2949ebff12c.tar.zst
Fix richtext link rendering
Diffstat (limited to 'src/view/com')
-rw-r--r--src/view/com/util/Link.tsx36
-rw-r--r--src/view/com/util/RichText.tsx24
2 files changed, 44 insertions, 16 deletions
diff --git a/src/view/com/util/Link.tsx b/src/view/com/util/Link.tsx
index 1d8ec2309..4931438b8 100644
--- a/src/view/com/util/Link.tsx
+++ b/src/view/com/util/Link.tsx
@@ -1,6 +1,12 @@
 import React from 'react'
 import {observer} from 'mobx-react-lite'
-import {StyleProp, Text, TouchableOpacity, ViewStyle} from 'react-native'
+import {
+  StyleProp,
+  Text,
+  TouchableOpacity,
+  TextStyle,
+  ViewStyle,
+} from 'react-native'
 import {useStores} from '../../../state'
 import {LinkActionsModel} from '../../../state/models/shell-ui'
 
@@ -21,6 +27,7 @@ export const Link = observer(function Link({
     store.nav.navigate(href)
   }
   const onLongPress = () => {
+    store.shell.closeModal() // close any active modals
     store.nav.newTab(href, title)
     // store.shell.openModal(new LinkActionsModel(href, title || href))
   }
@@ -34,3 +41,30 @@ export const Link = observer(function Link({
     </TouchableOpacity>
   )
 })
+
+export const TextLink = observer(function Link({
+  style,
+  href,
+  title,
+  text,
+}: {
+  style?: StyleProp<TextStyle>
+  href: string
+  title?: string
+  text: string
+}) {
+  const store = useStores()
+  const onPress = () => {
+    store.shell.closeModal() // close any active modals
+    store.nav.navigate(href)
+  }
+  const onLongPress = () => {
+    store.shell.closeModal() // close any active modals
+    store.nav.newTab(href, title)
+  }
+  return (
+    <Text style={style} onPress={onPress} onLongPress={onLongPress}>
+      {text}
+    </Text>
+  )
+})
diff --git a/src/view/com/util/RichText.tsx b/src/view/com/util/RichText.tsx
index 8fea5f63e..35948455a 100644
--- a/src/view/com/util/RichText.tsx
+++ b/src/view/com/util/RichText.tsx
@@ -1,6 +1,6 @@
 import React from 'react'
-import {Text, TextStyle, StyleProp} from 'react-native'
-import {Link} from './Link'
+import {Text, TextStyle, StyleProp, View} from 'react-native'
+import {TextLink} from './Link'
 import {s} from '../../lib/styles'
 
 type TextSlice = {start: number; end: number}
@@ -30,26 +30,20 @@ export function RichText({
   let key = 0
   for (const segment of segments) {
     if (typeof segment === 'string') {
-      els.push(
-        <Text key={key} style={style}>
-          {segment}
-        </Text>,
-      )
+      els.push(segment)
     } else {
       els.push(
-        <Link
+        <TextLink
           key={key}
-          title={segment.text}
-          href={`/profile/${segment.entity.value}`}>
-          <Text key={key} style={[style, s.blue3]}>
-            {segment.text}
-          </Text>
-        </Link>,
+          text={segment.text}
+          href={`/profile/${segment.entity.value}`}
+          style={[style, s.blue3]}
+        />,
       )
     }
     key++
   }
-  return <>{els}</>
+  return <Text style={style}>{els}</Text>
 }
 
 function sortByIndex(a: Entity, b: Entity) {