-
Notifications
You must be signed in to change notification settings - Fork 8
/
App.js
149 lines (138 loc) · 3.79 KB
/
App.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useRef, useState, useEffect} from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Dimensions,
} from 'react-native';
import SplashScren from 'react-native-splash-screen';
import AsyncStorage from '@react-native-async-storage/async-storage';
import IntroductionCard from './src/components/IntroductionCard';
import GhostCard from './src/components/GhostCard';
import ToolCard from './src/components/ToolCard';
import EvidenceCard from './src/components/EvidenceCard';
import TimerCard from './src/components/TimerCard';
import SettingsCard from './src/components/SettingsCard';
import BottomBar from './src/components/BottomBar';
import Carousel, {snapToItem} from 'react-native-snap-carousel';
import cards from './src/cards';
import {storeData, getData, LANGUAGE_KEY} from './src/util/dataStorage';
import {
introCardSwitch,
ghostCardSwitch,
toolCardSwitch,
LANGUAGES,
} from './src/util/translationSwitch';
const {width, height} = Dimensions.get('window');
const renderCard = (
item,
index,
language,
setLanguage,
languageIndex,
setLanguageIndex,
) => {
let card = item;
switch (item.type) {
case 'intro':
card = introCardSwitch(item, language);
return <IntroductionCard name={card.name} desc={card.desc} />;
case 'ghost':
card = ghostCardSwitch(item, language);
return (
<GhostCard
name={card.name}
desc={card.desc}
strength={card.strength}
weakness={card.weakness}
evidence={card.evidence}
language={language}
/>
);
case 'tool':
card = toolCardSwitch(item, language);
return <ToolCard name={card.name} desc={card.desc} language={language} />;
case 'evidence':
return <EvidenceCard language={language} />;
case 'timer':
return <TimerCard language={language} />;
case 'settings':
return (
<SettingsCard
language={language}
setLanguage={setLanguage}
languageIndex={languageIndex}
setLanguageIndex={setLanguageIndex}
/>
);
}
};
const App = () => {
const [language, setLanguage] = useState('en');
const [languageIndex, setLanguageIndex] = useState(0);
const carouselRef = useRef('carousel');
const [activeIndex, setActiveIndex] = useState(1);
useEffect(() => {
getData(LANGUAGE_KEY, setLanguage, setLanguageIndex);
SplashScren.hide();
}, []);
return (
<>
<View style={styles.mainContainer}>
<StatusBar barStyle="transparent" backgroundColor="black" />
<Carousel
initialNumToRender={cards.length}
ref={carouselRef}
data={cards}
renderItem={({item, index}) => {
return renderCard(
item,
index,
language,
setLanguage,
languageIndex,
setLanguageIndex,
);
}}
sliderWidth={width}
itemWidth={width / 1.2}
layout={'default'}
containerCustomStyle={styles.carouselContainer}
contentContainerCustomStyle={{alignSelf: 'center'}}
onSnapToItem={() => {
setActiveIndex(carouselRef.current.currentIndex);
}}
removeClippedSubviews={true}
firstItem={1}
/>
<BottomBar
activeIndex={activeIndex}
carouselRef={carouselRef}
language={language}
/>
</View>
</>
);
};
const styles = StyleSheet.create({
mainContainer: {
flex: 1,
display: 'flex',
justifyContent: 'space-between',
backgroundColor: 'black',
},
carouselContainer: {
display: 'flex',
},
});
export default App;