about summary refs log tree commit diff
path: root/src/components/Link.tsx
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-02-20 11:03:04 -0600
committerGitHub <noreply@github.com>2024-02-20 11:03:04 -0600
commitdf5a8f15427f8efeded692e21585e48df4907c3a (patch)
treebfee3cd3c31bd07a63109012d2e21d350d555f8b /src/components/Link.tsx
parent8a169dc6a14d422f65ea4afb5af7fe30efacf2bb (diff)
downloadvoidsky-df5a8f15427f8efeded692e21585e48df4907c3a.tar.zst
Swap `RichText` (#2934)
* Switch to new RT

* Allow early exit from links

* Build in tracking to text atoms

* Clean up FeedSourceCard

* Clean up leading after new default

* Add deprecated notice
Diffstat (limited to 'src/components/Link.tsx')
-rw-r--r--src/components/Link.tsx9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/components/Link.tsx b/src/components/Link.tsx
index 85c13270a..593b0863a 100644
--- a/src/components/Link.tsx
+++ b/src/components/Link.tsx
@@ -51,11 +51,12 @@ type BaseLinkProps = Pick<
   warnOnMismatchingTextChild?: boolean
 
   /**
-   * Callback for when the link is pressed.
+   * Callback for when the link is pressed. Prevent default and return `false`
+   * to exit early and prevent navigation.
    *
    * DO NOT use this for navigation, that's what the `to` prop is for.
    */
-  onPress?: (e: GestureResponderEvent) => void
+  onPress?: (e: GestureResponderEvent) => void | false
 
   /**
    * Web-only attribute. Sets `download` attr on web.
@@ -82,7 +83,9 @@ export function useLink({
 
   const onPress = React.useCallback(
     (e: GestureResponderEvent) => {
-      outerOnPress?.(e)
+      const exitEarlyIfFalse = outerOnPress?.(e)
+
+      if (exitEarlyIfFalse === false) return
 
       const requiresWarning = Boolean(
         warnOnMismatchingTextChild &&