This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
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)
}
}}
/>
)
}