1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00
p61-project/presentation/react-native/ui/ExternalLink.tsx

28 lines
610 B
TypeScript

import { Link } from "expo-router"
import * as WebBrowser from "expo-web-browser"
import { Platform } from "react-native"
type LinkProps = React.ComponentProps<typeof Link>
export const ExternalLink: React.FC<
Omit<LinkProps, "href"> & {
href: string
}
> = (props) => {
const { href, ...rest } = props
return (
<Link
target="_blank"
href={href as unknown as LinkProps["href"]}
{...rest}
onPress={async (event) => {
if (Platform.OS !== "web") {
event.preventDefault()
await WebBrowser.openBrowserAsync(href)
}
}}
/>
)
}