UNPKG

@gluestack-ui/core

Version:

Universal UI components for React Native, Expo, and Next.js

37 lines 1.22 kB
import { Linking, Platform } from 'react-native'; const linkToHREF = (URL) => { Linking.openURL(URL).catch((err) => console.error('An error occurred', err)); }; const addOnPressFunctionality = (href, callback) => { href ? linkToHREF(href) : ''; callback ? callback() : () => { }; }; export function useLink(props) { const { href, isExternal, onPress, _ref, isDisabled } = props; let platformLinkProps = {}; if (Platform.OS === 'web') { platformLinkProps = { 'href': isDisabled ? undefined : href, 'onPress': isDisabled ? undefined : onPress, 'aria-disabled': isDisabled, 'tabIndex': isDisabled ? -1 : 0, }; if (isExternal && _ref.current) { _ref.current.target = '_blank'; _ref.current.rel = 'noopener'; } } else { platformLinkProps = { onPress: () => { if (!isDisabled) addOnPressFunctionality(href, onPress); }, href, }; } return { linkProps: Object.assign(Object.assign({}, platformLinkProps), { role: 'link', accessible: true }), }; } //# sourceMappingURL=UseLink.js.map