Geen omschrijving

external-link.tsx 794B

1234567891011121314151617181920212223242526
  1. import { Href, Link } from 'expo-router';
  2. import { openBrowserAsync, WebBrowserPresentationStyle } from 'expo-web-browser';
  3. import { type ComponentProps } from 'react';
  4. type Props = Omit<ComponentProps<typeof Link>, 'href'> & { href: Href & string };
  5. export function ExternalLink({ href, ...rest }: Props) {
  6. return (
  7. <Link
  8. target="_blank"
  9. {...rest}
  10. href={href}
  11. onPress={async (event) => {
  12. if (process.env.EXPO_OS !== 'web') {
  13. // Prevent the default behavior of linking to the default browser on native.
  14. event.preventDefault();
  15. // Open the link in an in-app browser.
  16. await openBrowserAsync(href, {
  17. presentationStyle: WebBrowserPresentationStyle.AUTOMATIC,
  18. });
  19. }
  20. }}
  21. />
  22. );
  23. }