about summary refs log tree commit diff
path: root/src/components/Link.tsx
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2025-06-09 20:29:53 +0100
committerGitHub <noreply@github.com>2025-06-09 22:29:53 +0300
commitf93896346269b117556b13898eba9c162d6098b6 (patch)
treeac1468a21a4683db39327371110a96cdfa8afe48 /src/components/Link.tsx
parent42c4da1ec7f2ad560ef1dbf7477da02b1ed8ad2c (diff)
downloadvoidsky-f93896346269b117556b13898eba9c162d6098b6.tar.zst
Update react-navigation (#5967)
Diffstat (limited to 'src/components/Link.tsx')
-rw-r--r--src/components/Link.tsx36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/components/Link.tsx b/src/components/Link.tsx
index cca93c0c8..d73a3db4a 100644
--- a/src/components/Link.tsx
+++ b/src/components/Link.tsx
@@ -1,7 +1,11 @@
-import React from 'react'
+import React, {useMemo} from 'react'
 import {type GestureResponderEvent} from 'react-native'
 import {sanitizeUrl} from '@braintree/sanitize-url'
-import {StackActions, useLinkProps} from '@react-navigation/native'
+import {
+  type LinkProps as RNLinkProps,
+  StackActions,
+  useLinkBuilder,
+} from '@react-navigation/native'
 
 import {BSKY_DOWNLOAD_URL} from '#/lib/constants'
 import {useNavigationDeduped} from '#/lib/hooks/useNavigationDeduped'
@@ -28,12 +32,11 @@ import {router} from '#/routes'
  */
 export {useButtonContext as useLinkContext} from '#/components/Button'
 
-type BaseLinkProps = Pick<
-  Parameters<typeof useLinkProps<AllNavigatorParams>>[0],
-  'to'
-> & {
+type BaseLinkProps = {
   testID?: string
 
+  to: RNLinkProps<AllNavigatorParams> | string
+
   /**
    * The React Navigation `StackAction` to perform when the link is pressed.
    */
@@ -92,10 +95,23 @@ export function useLink({
   shouldProxy?: boolean
 }) {
   const navigation = useNavigationDeduped()
-  const {href} = useLinkProps<AllNavigatorParams>({
-    to:
-      typeof to === 'string' ? convertBskyAppUrlIfNeeded(sanitizeUrl(to)) : to,
-  })
+  const {buildHref} = useLinkBuilder()
+  const href = useMemo(() => {
+    return typeof to === 'string'
+      ? convertBskyAppUrlIfNeeded(sanitizeUrl(to))
+      : to.screen
+      ? buildHref(to.screen, to.params)
+      : to.href
+      ? convertBskyAppUrlIfNeeded(sanitizeUrl(to.href))
+      : undefined
+  }, [to, buildHref])
+
+  if (!href) {
+    throw new Error(
+      'Link `to` prop must be a string or an object with `screen` and `params` properties',
+    )
+  }
+
   const isExternal = isExternalUrl(href)
   const {openModal, closeModal} = useModalControls()
   const openLink = useOpenLink()