attempt to fix link component
This commit is contained in:
+24
-14
@@ -1,7 +1,11 @@
|
|||||||
import React from 'react'
|
import React, {useMemo} from 'react'
|
||||||
import {type GestureResponderEvent} from 'react-native'
|
import {type GestureResponderEvent} from 'react-native'
|
||||||
import {sanitizeUrl} from '@braintree/sanitize-url'
|
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 {BSKY_DOWNLOAD_URL} from '#/lib/constants'
|
||||||
import {useNavigationDeduped} from '#/lib/hooks/useNavigationDeduped'
|
import {useNavigationDeduped} from '#/lib/hooks/useNavigationDeduped'
|
||||||
@@ -28,12 +32,11 @@ import {router} from '#/routes'
|
|||||||
*/
|
*/
|
||||||
export {useButtonContext as useLinkContext} from '#/components/Button'
|
export {useButtonContext as useLinkContext} from '#/components/Button'
|
||||||
|
|
||||||
type BaseLinkProps = Pick<
|
type BaseLinkProps = {
|
||||||
Parameters<typeof useLinkProps<AllNavigatorParams>>[0],
|
|
||||||
'to'
|
|
||||||
> & {
|
|
||||||
testID?: string
|
testID?: string
|
||||||
|
|
||||||
|
to: RNLinkProps<AllNavigatorParams> | string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The React Navigation `StackAction` to perform when the link is pressed.
|
* The React Navigation `StackAction` to perform when the link is pressed.
|
||||||
*/
|
*/
|
||||||
@@ -92,14 +95,21 @@ export function useLink({
|
|||||||
shouldProxy?: boolean
|
shouldProxy?: boolean
|
||||||
}) {
|
}) {
|
||||||
const navigation = useNavigationDeduped()
|
const navigation = useNavigationDeduped()
|
||||||
const {href} = useLinkProps<AllNavigatorParams>({
|
const {buildHref} = useLinkBuilder()
|
||||||
params: typeof to === 'string' ? undefined : to.params,
|
const href = useMemo(() => {
|
||||||
screen: typeof to === 'string' ? undefined : to.screen,
|
return typeof to === 'string'
|
||||||
href:
|
? convertBskyAppUrlIfNeeded(sanitizeUrl(to))
|
||||||
typeof to === 'string'
|
: !to.screen
|
||||||
? convertBskyAppUrlIfNeeded(sanitizeUrl(to))
|
? convertBskyAppUrlIfNeeded(sanitizeUrl(to.href))
|
||||||
: undefined,
|
: buildHref(to.screen, to.params)
|
||||||
})
|
}, [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 isExternal = isExternalUrl(href)
|
||||||
const {openModal, closeModal} = useModalControls()
|
const {openModal, closeModal} = useModalControls()
|
||||||
const openLink = useOpenLink()
|
const openLink = useOpenLink()
|
||||||
|
|||||||
Reference in New Issue
Block a user