about summary refs log tree commit diff
path: root/src/view/com/util/Link.tsx
blob: 1d8ec2309ee74fa205a66eb405a469cbf7163a48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react'
import {observer} from 'mobx-react-lite'
import {StyleProp, Text, TouchableOpacity, ViewStyle} from 'react-native'
import {useStores} from '../../../state'
import {LinkActionsModel} from '../../../state/models/shell-ui'

export const Link = observer(function Link({
  style,
  href,
  title,
  children,
}: {
  style?: StyleProp<ViewStyle>
  href: string
  title?: string
  children?: React.ReactNode
}) {
  const store = useStores()
  const onPress = () => {
    store.shell.closeModal() // close any active modals
    store.nav.navigate(href)
  }
  const onLongPress = () => {
    store.nav.newTab(href, title)
    // store.shell.openModal(new LinkActionsModel(href, title || href))
  }
  return (
    <TouchableOpacity
      style={style}
      onPress={onPress}
      onLongPress={onLongPress}
      delayPressIn={50}>
      {children ? children : <Text>{title || 'link'}</Text>}
    </TouchableOpacity>
  )
})