import React from 'react' import {observer} from 'mobx-react-lite' import { Linking, StyleProp, TouchableWithoutFeedback, TouchableOpacity, TextStyle, View, ViewStyle, } from 'react-native' import {Text} from './text/Text' import {TypographyVariant} from 'lib/ThemeContext' import {useStores, RootStoreModel} from 'state/index' import {convertBskyAppUrlIfNeeded} from 'lib/strings/url-helpers' export const Link = observer(function Link({ style, href, title, children, noFeedback, }: { style?: StyleProp href?: string title?: string children?: React.ReactNode noFeedback?: boolean }) { const store = useStores() const onPress = () => { if (href) { handleLink(store, href, false) } } const onLongPress = () => { if (href) { handleLink(store, href, true) } } if (noFeedback) { return ( {children ? children : {title || 'link'}} ) } return ( {children ? children : {title || 'link'}} ) }) export const TextLink = observer(function TextLink({ type = 'md', style, href, text, }: { type?: TypographyVariant style?: StyleProp href: string text: string }) { const store = useStores() const onPress = () => { handleLink(store, href, false) } const onLongPress = () => { handleLink(store, href, true) } return ( {text} ) }) function handleLink(store: RootStoreModel, href: string, longPress: boolean) { href = convertBskyAppUrlIfNeeded(href) if (href.startsWith('http')) { Linking.openURL(href) } else if (longPress) { store.shell.closeModal() // close any active modals store.nav.newTab(href) } else { store.shell.closeModal() // close any active modals store.nav.navigate(href) } }