-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabsScreen.js
48 lines (44 loc) · 1.27 KB
/
TabsScreen.js
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
import { useContext } from 'react'
import { ScrollView } from 'react-native'
import { MainContext } from './MainContext'
import Tab from './components/Tab'
import Screen from './components/Screen'
export default function TabsScreen() {
const {
isDark,
tabsVisible,
setTabsVisible,
tabs,
setTabs,
setHistory
} = useContext(MainContext)
function addTab() {
setTabs((currTabs) => [
...currTabs,
{ tabName: 'Google', tabUrl: 'https://google.com/', visible: true },
])
setHistory(currVal => ([{ pageTitle: 'Google', pageUrl: 'https://google.com/' }, ...currVal]))
}
return <Screen
isDark={isDark}
component={<Component tabs={tabs} setTabs={setTabs} />}
title={`Tabs ${tabs.length}`}
iconName="plus"
iconSize={28}
iconOnPress={addTab}
screenVisible={tabsVisible}
onHideScreenPress={() => setTabsVisible(false)}
/>
}
export function Component({ tabs }) {
return <ScrollView contentContainerStyle={{ flexDirection: "row", flexWrap: "wrap"}} >
{tabs.map(({ tabName }, idx) => (
<Tab
key={idx}
marginRight={idx % 2 === 0 ? 12 : 0}
tabName={tabName}
idx={idx}
/>
))}
</ScrollView>
}