-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
222 lines (206 loc) · 8.49 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import * as Font from "expo-font";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { Provider } from "react-redux";
import { store } from "./src/store/store";
import { ActivityIndicator, Alert, BackHandler, Image, StatusBar, StyleSheet, Text, View, NativeModules } from "react-native";
import React from "react";
import { Button } from "react-native-elements";
import { widthPercentageToDP as wp } from "react-native-responsive-screen";
import { NavigationContainer } from "@react-navigation/native";
import { Tutorial } from "./src/components/TutorialComponent";
import { SelectPlayer } from "./src/components/SelectPlayerComponent";
import { SelectDifficulty } from "./src/components/SelectDifficultyComponent";
import { Card } from "./src/components/CardComponent";
import { SelectOtherPlayer } from "./src/components/SelectOtherPlayerComponent";
import { SelectCategoryOneVersusAll } from "./src/components/SelectCategoryOneVersusAllComponent";
import { All } from "./src/components/AllComponent";
import { Question } from "./src/components/QuestionComponent";
import { AnswerQuestion } from "./src/components/AnswerQuestionComponent";
import { EveryonePlay } from "./src/components/EveryonePlayComponent";
import { WinLoose } from "./src/components/WinLooseComponent";
import { EndGame } from "./src/components/EndGameComponent";
import { createStackNavigator } from "@react-navigation/stack";
import { ApplicationText } from "./src/components/helpers/ApplicationText";
import { changeLang } from "./src/store/actions/textAction";
import {registerYodoAds} from "./src/components/helpers/YodoHelper";
const Stack = createStackNavigator();
registerYodoAds();
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
fontIsLoaded: false,
startPage: 'SelectPlayer',
alert: true,
playButton: false
};
// AsyncStorage.removeItem('tutorial')
// AsyncStorage.removeItem('isFirstGame')
}
async componentDidMount() {
await this.getStorageData();
await Font.loadAsync({
'MainTitle': require('./assets/fonts/RAPIDSQUAD.otf'),
'ABeeZee-Regular': require('./assets/fonts/ABeeZee-Regular.ttf'),
'titre': require('./assets/fonts/Qualy_Bold.ttf'),
'questionText': require('./assets/fonts/OpenSans-Regular.ttf'),
'gorgeesText': require('./assets/fonts/OpenSans-LightItalic.ttf'),
'TheTitle': require('./assets/fonts/Designero.ttf')
});
this.setState({fontIsLoaded: true})
}
async getStorageData() {
try {
await AsyncStorage.multiGet(['tutorial', 'lang']).then(response => {
if (response[0][0] === "tutorial") {
if (response[0][1] !== 'true') {
this.setState({
startPage: 'Tutorial'
});
}
}
if (response[1][0] === "lang") {
let lang = response[1][1]
if (lang === null) {
const deviceLang = this.getDeviceLanguage()
lang = deviceLang.split('_')[0];
AsyncStorage.setItem("lang", lang)
}
store.dispatch(changeLang(lang))
}
});
} catch (error) {
console.log(error);
}
}
getDeviceLanguage() {
return Platform.OS === 'ios'
? NativeModules.SettingsManager.settings.AppleLocale ||
NativeModules.SettingsManager.settings.AppleLanguages[0] //iOS 13
: NativeModules.I18nManager.localeIdentifier;
}
alert() {
Alert.alert(ApplicationText("text.alert.title"),
ApplicationText("text.alert.content"),
[
{
text: ApplicationText("text.alert.ok"),
onPress: () => this.setState({alert: false, playButton: false})
},
{text: ApplicationText("text.alert.close"), onPress: () => {
this.setState({playButton: true});
BackHandler.exitApp()
}}
],
{cancelable: false})
}
renderPlayerButton() {
return (
<View style={styles.container}>
<View style={styles.content}>
<Image source={require('./assets/logo_captain.png')} />
</View>
<View style={styles.middle}>
<Button titleStyle={{
textAlign: 'center', fontSize: wp("8%")
}} buttonStyle={{
backgroundColor: "#D42A2A",
borderRadius: wp("3%"), width: wp("70%"),
marginLeft: wp("3%"),
}}
title={ApplicationText("text.play")}
onPress={() => this.alert()}
/>
</View>
</View>
)
}
renderAlert() {
this.alert()
return (
<View style={styles.container}>
<View style={styles.content}>
</View>
</View>
)
}
renderFontNotLoaded() {
return (
<View style={styles.container}>
<ActivityIndicator
animating = {true}
color = '#bc2b78'
size = "large"/>
<Text style={styles.text}>
{ApplicationText('text.loading')}
</Text>
</View>
);
}
renderFontLoaded() {
const { startPage } = this.state;
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName={startPage}
headerMode={"none"}
gestureEnabled={true}
>
<Stack.Screen name="Tutorial" component={Tutorial}/>
<Stack.Screen name="SelectPlayer" component={SelectPlayer}/>
<Stack.Screen name="SelectDifficulty" component={SelectDifficulty}/>
<Stack.Screen name="Card" component={Card} gesturesEnabled={false}/>
<Stack.Screen name="SelectOtherPlayer" component={SelectOtherPlayer}/>
<Stack.Screen name="SelectCategory" component={SelectCategoryOneVersusAll}/>
<Stack.Screen name="All" component={All}/>
<Stack.Screen name="Question" component={Question}/>
<Stack.Screen name="AnswerQuestion" component={AnswerQuestion}/>
<Stack.Screen name="EveryonePlay" component={EveryonePlay}/>
<Stack.Screen name="WinLoose" component={WinLoose}/>
<Stack.Screen name="EndGame" component={EndGame}/>
</Stack.Navigator>
</NavigationContainer>
);
}
handlerRender() {
const {playButton, fontIsLoaded, alert} = this.state;
if(playButton) {
return this.renderPlayerButton()
}
if(!fontIsLoaded) {
return this.renderFontNotLoaded()
}
if(alert) {
return this.renderAlert()
}
return this.renderFontLoaded()
}
render() {
return (
<Provider store={store}>
<StatusBar hidden={true}/>
{this.handlerRender()}
</Provider>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#2A2A2A',
justifyContent: 'center',
alignItems: 'center'
},
content: {
flex: 0.6,
},
middle: {
flex: 0.2,
},
text: {
textAlign: 'center',
color: '#fff',
fontSize: wp("7.5%"),
}
})
export default App;