about summary refs log tree commit diff
path: root/src/view/com/util/Link.tsx
blob: 4931438b8768fc446a5e9ee98445179a11533d47 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react'
import {observer} from 'mobx-react-lite'
import {
  StyleProp,
  Text,
  TouchableOpacity,
  TextStyle,
  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.shell.closeModal() // close any active modals
    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>
  )
})

export const TextLink = observer(function Link({
  style,
  href,
  title,
  text,
}: {
  style?: StyleProp<TextStyle>
  href: string
  title?: string
  text: string
}) {
  const store = useStores()
  const onPress = () => {
    store.shell.closeModal() // close any active modals
    store.nav.navigate(href)
  }
  const onLongPress = () => {
    store.shell.closeModal() // close any active modals
    store.nav.newTab(href, title)
  }
  return (
    <Text style={style} onPress={onPress} onLongPress={onLongPress}>
      {text}
    </Text>
  )
})