Add util for link static clicks
This commit is contained in:
@@ -329,6 +329,25 @@ export function InlineLinkText({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility to create a static `onPress` handler for a `Link` that would otherwise link to a URI
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* `<Link {...createStaticClick(e => {...})} />`
|
||||||
|
*/
|
||||||
|
export function createStaticClick(
|
||||||
|
onPressHandler: Exclude<BaseLinkProps['onPress'], undefined>,
|
||||||
|
): Pick<BaseLinkProps, 'to' | 'onPress'> {
|
||||||
|
return {
|
||||||
|
to: '#',
|
||||||
|
onPress(e: GestureResponderEvent) {
|
||||||
|
e.preventDefault()
|
||||||
|
onPressHandler(e)
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Pressable that uses useLink to handle navigation. It is unstyled, so can be used in cases where the Button styles
|
* A Pressable that uses useLink to handle navigation. It is unstyled, so can be used in cases where the Button styles
|
||||||
* in Link are not desired.
|
* in Link are not desired.
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {msg, Trans} from '@lingui/macro'
|
|||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useNavigation} from '@react-navigation/native'
|
import {useNavigation} from '@react-navigation/native'
|
||||||
|
|
||||||
import {makeSearchLink} from '#/lib/routes/links'
|
|
||||||
import {NavigationProp} from '#/lib/routes/types'
|
import {NavigationProp} from '#/lib/routes/types'
|
||||||
import {isInvalidHandle} from '#/lib/strings/handles'
|
import {isInvalidHandle} from '#/lib/strings/handles'
|
||||||
import {
|
import {
|
||||||
@@ -19,7 +18,7 @@ import {Divider} from '#/components/Divider'
|
|||||||
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as Search} from '#/components/icons/MagnifyingGlass2'
|
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as Search} from '#/components/icons/MagnifyingGlass2'
|
||||||
import {Mute_Stroke2_Corner0_Rounded as Mute} from '#/components/icons/Mute'
|
import {Mute_Stroke2_Corner0_Rounded as Mute} from '#/components/icons/Mute'
|
||||||
import {Person_Stroke2_Corner0_Rounded as Person} from '#/components/icons/Person'
|
import {Person_Stroke2_Corner0_Rounded as Person} from '#/components/icons/Person'
|
||||||
import {Link} from '#/components/Link'
|
import {createStaticClick,Link} from '#/components/Link'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
@@ -102,18 +101,13 @@ export function TagMenu({
|
|||||||
]}>
|
]}>
|
||||||
<Link
|
<Link
|
||||||
label={_(msg`Search for all posts with tag ${displayTag}`)}
|
label={_(msg`Search for all posts with tag ${displayTag}`)}
|
||||||
to={makeSearchLink({query: displayTag})}
|
{...createStaticClick(() => {
|
||||||
onPress={e => {
|
|
||||||
e.preventDefault()
|
|
||||||
|
|
||||||
control.close(() => {
|
control.close(() => {
|
||||||
navigation.push('Hashtag', {
|
navigation.push('Hashtag', {
|
||||||
tag: encodeURIComponent(tag),
|
tag: encodeURIComponent(tag),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})}>
|
||||||
return false
|
|
||||||
}}>
|
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
a.w_full,
|
a.w_full,
|
||||||
@@ -154,22 +148,14 @@ export function TagMenu({
|
|||||||
label={_(
|
label={_(
|
||||||
msg`Search for all posts by @${authorHandle} with tag ${displayTag}`,
|
msg`Search for all posts by @${authorHandle} with tag ${displayTag}`,
|
||||||
)}
|
)}
|
||||||
to={makeSearchLink({
|
{...createStaticClick(() => {
|
||||||
query: displayTag,
|
|
||||||
from: authorHandle,
|
|
||||||
})}
|
|
||||||
onPress={e => {
|
|
||||||
e.preventDefault()
|
|
||||||
|
|
||||||
control.close(() => {
|
control.close(() => {
|
||||||
navigation.push('Hashtag', {
|
navigation.push('Hashtag', {
|
||||||
tag: encodeURIComponent(tag),
|
tag: encodeURIComponent(tag),
|
||||||
author: authorHandle,
|
author: authorHandle,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})}>
|
||||||
return false
|
|
||||||
}}>
|
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
a.w_full,
|
a.w_full,
|
||||||
|
|||||||
Reference in New Issue
Block a user