Projekt

Obecné

Profil

Stáhnout (6.77 KB) Statistiky
| Větev: | Tag: | Revize:
1 f4af30c8 Fantič
import { HStack, CircleIcon, View, ScrollView, Button, Center, Heading, Pressable, Text, Box, Container, VStack, Icon, ArrowBackIcon, ChevronLeftIcon, ChevronRightIcon, useToast, Divider } from "native-base";
2 d281786c Fantič
import { CertaintyWithColors } from "../../stores/reducers/itemSlice";
3 c1161e82 Fantič
import { Certainty, Concordance } from "../../types/item";
4 a7a9a204 Fantič
import LoadingBox from "../loading/LoadingBox";
5 8ff3394e Fantič
import { DrawerNavigationProp } from "@react-navigation/drawer";
6 a62d7c92 Michal Schwob
import { RootStackParamList } from "../../pages/Navigation";
7 8ff3394e Fantič
import { InfoToast } from "../toast/InfoToast";
8 d281786c Fantič
9
// custom render Tab
10 f4af30c8 Fantič
const ItemTabBar = (props: { navigationState: { routes: any[] }, concordances: Concordance[], index: number, onIndexChange: any, onBackPressed: any, navigation: DrawerNavigationProp<RootStackParamList, "Item", undefined>, nextItem?: string | boolean, prevItem?: string | boolean }) => {
11 d281786c Fantič
12 8ff3394e Fantič
    const { concordances, onIndexChange, index, onBackPressed, nextItem, prevItem } = props
13
14
    const toast = useToast();
15 d281786c Fantič
16 f4af30c8 Fantič
    console.log(concordances)
17
18 faf84222 Fantič
    if (concordances && concordances.length > 0) {
19 a7a9a204 Fantič
        return (
20 ca637f52 Fantič
            /*
21
            NEXT ITEM switching
22
            
23
            <HStack h="16" >
24
                <HStack width="50%">
25
                    <Button variant="ghost" size="lg" marginLeft={0}
26
                        onPress={onBackPressed}
27
                        leftIcon={<ChevronLeftIcon size="lg" />}>
28
                        Back
29
                    </Button>
30
                </HStack>
31
                <HStack width="50%">
32 1054fe09 Fantič
                    <HStack width="50%">
33 ca637f52 Fantič
34
                    </HStack>
35
                    <HStack marginRight={0}>
36
                        <Button variant="ghost" size="lg"
37
                            onPress={() => {
38
                                if(prevItem){
39
                                    console.log(prevItem)
40
                                    props.navigation.navigate("Item", { itemId: prevItem.toString() })
41
                                }
42
                                else{
43
                                    toast.show({
44
                                        render: ({
45
                                            id
46
                                        }) => {
47
                                            return <InfoToast text={"No previous item..."} onClose={() => toast.close(id)} />;
48
                                        },
49
                                        duration: 3000
50
                                    });
51
                                }
52
                            }}
53 1054fe09 Fantič
                            leftIcon={<ChevronLeftIcon size="lg" />}>
54 ca637f52 Fantič
                        </Button>
55
                        <Button variant="ghost" size="lg"
56
                            onPress={() => {
57
                                
58
                                if(nextItem){
59
                                    props.navigation.navigate("Item", { itemId: nextItem.toString() })
60
                                }
61
                                else{
62
                                    toast.show({
63
                                        render: ({
64
                                            id
65
                                        }) => {
66
                                            return <InfoToast text={"No next item..."} onClose={() => toast.close(id)} />;
67
                                        },
68
                                        duration: 3000
69
                                    });
70
                                }
71
                            }}
72
                            leftIcon={<ChevronRightIcon size="lg" />}>
73 1054fe09 Fantič
                        </Button>
74
                    </HStack>
75 ca637f52 Fantič
                </HStack>
76
            </HStack> */
77 7e9d79f3 Fantič
            <HStack style={{height: 43}} backgroundColor={"#F5F4F1"}>
78 ca637f52 Fantič
                <ScrollView contentContainerStyle={{ flexGrow: 1 }} flex="1" horizontal={true}>
79
                    {concordances && concordances.length > 0 &&
80
                        <HStack flex="1" justifyContent="center" width="100%">
81
                            {concordances.length > 1 && concordances.map((concordance, i) => {
82
                                return (
83
                                    <Pressable onPress={() => { onIndexChange(i) }}>
84 7e9d79f3 Fantič
                                        <VStack alignItems={"center"} justifyContent={"center"} width={32}  style={{height: 43}}>
85
                                            <HStack alignItems={"center"} mt={i == index ? 1.5 : -1.5}>
86 ca637f52 Fantič
                                                {concordances?.[i]?.cert && <CircleIcon
87 1054fe09 Fantič
                                                    size="2"
88 ca637f52 Fantič
                                                    color={CertaintyWithColors[concordances?.[i]?.cert ?? Certainty.Unknown].color}
89
                                                />}
90
                                                <Text marginLeft={2} color={i == index ? "#654B07" : "#8F6A0A"} bold fontSize={"md"}>
91
                                                    {concordances?.[i]?.id}
92 191f2cc7 Fantič
                                                </Text>
93
                                            </HStack>
94 d0870262 Fantič
                                            {i == index && <Divider color="primary" borderWidth={2} borderRadius={5} width={105} mt={1.5} />}
95 f4af30c8 Fantič
                                        </VStack>
96
97 ca637f52 Fantič
                                    </Pressable>
98
                                );
99
                            })}
100
                            {concordances && concordances.length == 1 &&
101
                                <Pressable onPress={() => { onIndexChange(0) }}>
102 7e9d79f3 Fantič
                                    <VStack alignItems={"center"} justifyContent={"center"} width={32} style={{height: 43}}>
103
                                        <HStack alignItems={"center"} mt={0 == 0 ? 1.5 : -1.5}>
104 ca637f52 Fantič
                                            {concordances?.[0]?.cert && <CircleIcon
105
                                                size="2"
106
                                                color={CertaintyWithColors[concordances?.[0]?.cert ?? Certainty.Unknown].color}
107
                                            />}
108
                                            <Text marginLeft={2} color={0 == 0 ? "#654B07" : "#8F6A0A"} bold fontSize={"md"}>
109
                                                {concordances?.[0]?.id}
110
                                            </Text>
111
                                        </HStack>
112 d0870262 Fantič
                                        {0 == 0 && <Divider color="#654B07" borderWidth={2} borderRadius={5} width={105} mt={1.5} />}
113 ca637f52 Fantič
                                    </VStack>
114 1054fe09 Fantič
115 ca637f52 Fantič
                                </Pressable>
116
                            }
117
                        </HStack>
118
                    }
119
                </ScrollView>
120
            </HStack>
121 faf84222 Fantič
        );
122
    }
123 d281786c Fantič
    else {
124 a7a9a204 Fantič
        return <LoadingBox text={`Loading concordances...`}></LoadingBox>
125 d281786c Fantič
    }
126 a7a9a204 Fantič
};
127 d281786c Fantič
128 a7a9a204 Fantič
export default ItemTabBar