use useOpenLink
hook for links in ALF (#2975)
* use `useOpenLink` hook for links in ALF * web only for `outline`
This commit is contained in:
parent
894f00d687
commit
35be8ec90e
1 changed files with 15 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {GestureResponderEvent, Linking} from 'react-native'
|
import {GestureResponderEvent} from 'react-native'
|
||||||
import {
|
import {
|
||||||
useLinkProps,
|
useLinkProps,
|
||||||
useNavigation,
|
useNavigation,
|
||||||
|
@ -20,6 +20,7 @@ import {
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
import {router} from '#/routes'
|
import {router} from '#/routes'
|
||||||
import {Text, TextProps} from '#/components/Typography'
|
import {Text, TextProps} from '#/components/Typography'
|
||||||
|
import {useOpenLink} from 'state/preferences/in-app-browser'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only available within a `Link`, since that inherits from `Button`.
|
* Only available within a `Link`, since that inherits from `Button`.
|
||||||
|
@ -80,6 +81,7 @@ export function useLink({
|
||||||
})
|
})
|
||||||
const isExternal = isExternalUrl(href)
|
const isExternal = isExternalUrl(href)
|
||||||
const {openModal, closeModal} = useModalControls()
|
const {openModal, closeModal} = useModalControls()
|
||||||
|
const openLink = useOpenLink()
|
||||||
|
|
||||||
const onPress = React.useCallback(
|
const onPress = React.useCallback(
|
||||||
(e: GestureResponderEvent) => {
|
(e: GestureResponderEvent) => {
|
||||||
|
@ -106,7 +108,7 @@ export function useLink({
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
Linking.openURL(href)
|
openLink(href)
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* A `GestureResponderEvent`, but cast to `any` to avoid using a bunch
|
* A `GestureResponderEvent`, but cast to `any` to avoid using a bunch
|
||||||
|
@ -124,7 +126,7 @@ export function useLink({
|
||||||
href.startsWith('http') ||
|
href.startsWith('http') ||
|
||||||
href.startsWith('mailto')
|
href.startsWith('mailto')
|
||||||
) {
|
) {
|
||||||
Linking.openURL(href)
|
openLink(href)
|
||||||
} else {
|
} else {
|
||||||
closeModal() // close any active modals
|
closeModal() // close any active modals
|
||||||
|
|
||||||
|
@ -145,15 +147,16 @@ export function useLink({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
href,
|
|
||||||
isExternal,
|
|
||||||
warnOnMismatchingTextChild,
|
|
||||||
navigation,
|
|
||||||
action,
|
|
||||||
displayText,
|
|
||||||
closeModal,
|
|
||||||
openModal,
|
|
||||||
outerOnPress,
|
outerOnPress,
|
||||||
|
warnOnMismatchingTextChild,
|
||||||
|
displayText,
|
||||||
|
isExternal,
|
||||||
|
href,
|
||||||
|
openModal,
|
||||||
|
openLink,
|
||||||
|
closeModal,
|
||||||
|
action,
|
||||||
|
navigation,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -260,7 +263,7 @@ export function InlineLink({
|
||||||
style={[
|
style={[
|
||||||
{color: t.palette.primary_500},
|
{color: t.palette.primary_500},
|
||||||
(hovered || focused || pressed) && {
|
(hovered || focused || pressed) && {
|
||||||
outline: 0,
|
...web({outline: 0}),
|
||||||
textDecorationLine: 'underline',
|
textDecorationLine: 'underline',
|
||||||
textDecorationColor: flattenedStyle.color ?? t.palette.primary_500,
|
textDecorationColor: flattenedStyle.color ?? t.palette.primary_500,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue