about summary refs log tree commit diff
path: root/src/view/shell/mobile/HistoryMenu.tsx
blob: d0b9b9751f5fcb28f46b7f2e65d38fa5c9ab3bf7 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react'
import {
  StyleSheet,
  Text,
  TouchableOpacity,
  TouchableWithoutFeedback,
  View,
} from 'react-native'
import RootSiblings from 'react-native-root-siblings'
import {NavigationTabModel} from '../../../state/models/navigation'

export function createBackMenu(tab: NavigationTabModel): RootSiblings {
  const onPressItem = (index: number) => {
    sibling.destroy()
    tab.goToIndex(index)
  }
  const onOuterPress = () => sibling.destroy()
  const sibling = new RootSiblings(
    (
      <>
        <TouchableWithoutFeedback onPress={onOuterPress}>
          <View style={styles.bg} />
        </TouchableWithoutFeedback>
        <View style={[styles.menu, styles.back]}>
          {tab.backTen.map((item, i) => (
            <TouchableOpacity
              key={item.index}
              style={[styles.menuItem, i !== 0 && styles.menuItemBorder]}
              onPress={() => onPressItem(item.index)}>
              <Text>{item.title || item.url}</Text>
            </TouchableOpacity>
          ))}
        </View>
      </>
    ),
  )
  return sibling
}

export function createForwardMenu(tab: NavigationTabModel): RootSiblings {
  const onPressItem = (index: number) => {
    sibling.destroy()
    tab.goToIndex(index)
  }
  const onOuterPress = () => sibling.destroy()
  const sibling = new RootSiblings(
    (
      <>
        <TouchableWithoutFeedback onPress={onOuterPress}>
          <View style={styles.bg} />
        </TouchableWithoutFeedback>
        <View style={[styles.menu, styles.forward]}>
          {tab.forwardTen.reverse().map((item, i) => (
            <TouchableOpacity
              key={item.index}
              style={[styles.menuItem, i !== 0 && styles.menuItemBorder]}
              onPress={() => onPressItem(item.index)}>
              <Text>{item.title || item.url}</Text>
            </TouchableOpacity>
          ))}
        </View>
      </>
    ),
  )
  return sibling
}

const styles = StyleSheet.create({
  bg: {
    position: 'absolute',
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    backgroundColor: '#000',
    opacity: 0.1,
  },
  menu: {
    position: 'absolute',
    bottom: 80,
    backgroundColor: '#fff',
    borderRadius: 8,
    opacity: 1,
  },
  back: {
    left: 10,
  },
  forward: {
    left: 60,
  },
  menuItem: {
    paddingVertical: 10,
    paddingLeft: 15,
    paddingRight: 30,
  },
  menuItemBorder: {
    borderTopWidth: 1,
    borderTopColor: '#ddd',
  },
})