eletrotupi / tcc/ frontend/components/misc/external-link.tsxc901c35af9c84b6a29e5185545ced1129f33b8f4
794 B | 25 lines Raw
1
import { Href, Link } from 'expo-router';
2
import { openBrowserAsync, WebBrowserPresentationStyle } from 'expo-web-browser';
3
import { type ComponentProps } from 'react';
4

5
type Props = Omit<ComponentProps<typeof Link>, 'href'> & { href: Href & string };
6

7
export function ExternalLink({ href, ...rest }: Props) {
8
  return (
9
    <Link
10
      target="_blank"
11
      {...rest}
12
      href={href}
13
      onPress={async (event) => {
14
        if (process.env.EXPO_OS !== 'web') {
15
          // Prevent the default behavior of linking to the default browser on native.
16
          event.preventDefault();
17
          // Open the link in an in-app browser.
18
          await openBrowserAsync(href, {
19
            presentationStyle: WebBrowserPresentationStyle.AUTOMATIC,
20
          });
21
        }
22
      }}
23
    />
24
  );
25
}