|
@@ -1,13 +1,14 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import * as React from 'react';
|
4
|
|
-import {Alert, FlatList, Linking, Platform} from 'react-native';
|
|
4
|
+import {FlatList, Linking, Platform, View} from 'react-native';
|
5
|
5
|
import {Body, Card, CardItem, Container, Content, H1, Left, Right, Text, Thumbnail} from 'native-base';
|
6
|
6
|
import CustomHeader from "../../components/CustomHeader";
|
7
|
7
|
import i18n from "i18n-js";
|
8
|
8
|
import appJson from '../../app';
|
9
|
9
|
import packageJson from '../../package';
|
10
|
10
|
import CustomMaterialIcon from "../../components/CustomMaterialIcon";
|
|
11
|
+import AsyncStorageManager from "../../utils/AsyncStorageManager";
|
11
|
12
|
|
12
|
13
|
const links = {
|
13
|
14
|
appstore: 'https://qwant.com',
|
|
@@ -27,6 +28,10 @@ type Props = {
|
27
|
28
|
navigation: Object,
|
28
|
29
|
};
|
29
|
30
|
|
|
31
|
+type State = {
|
|
32
|
+ isDebugUnlocked: boolean,
|
|
33
|
+};
|
|
34
|
+
|
30
|
35
|
/**
|
31
|
36
|
* Opens a link in the device's browser
|
32
|
37
|
* @param link The link to open
|
|
@@ -38,7 +43,13 @@ function openWebLink(link) {
|
38
|
43
|
/**
|
39
|
44
|
* Class defining an about screen. This screen shows the user information about the app and it's author.
|
40
|
45
|
*/
|
41
|
|
-export default class AboutScreen extends React.Component<Props> {
|
|
46
|
+export default class AboutScreen extends React.Component<Props, State> {
|
|
47
|
+
|
|
48
|
+ debugTapCounter = 0;
|
|
49
|
+
|
|
50
|
+ state = {
|
|
51
|
+ isDebugUnlocked: AsyncStorageManager.getInstance().preferences.debugUnlocked.current === '1'
|
|
52
|
+ };
|
42
|
53
|
|
43
|
54
|
/**
|
44
|
55
|
* Data to be displayed in the app card
|
|
@@ -80,6 +91,13 @@ export default class AboutScreen extends React.Component<Props> {
|
80
|
91
|
text: i18n.t('aboutScreen.license'),
|
81
|
92
|
showChevron: true
|
82
|
93
|
},
|
|
94
|
+ {
|
|
95
|
+ onPressCallback: () => this.props.navigation.navigate('DebugScreen'),
|
|
96
|
+ icon: 'bug-check',
|
|
97
|
+ text: i18n.t('aboutScreen.debug'),
|
|
98
|
+ showChevron: true,
|
|
99
|
+ showOnlyDebug: true
|
|
100
|
+ },
|
83
|
101
|
];
|
84
|
102
|
|
85
|
103
|
/**
|
|
@@ -87,7 +105,7 @@ export default class AboutScreen extends React.Component<Props> {
|
87
|
105
|
*/
|
88
|
106
|
authorData: Array<Object> = [
|
89
|
107
|
{
|
90
|
|
- onPressCallback: () => Alert.alert('Coucou', 'Whaou'),
|
|
108
|
+ onPressCallback: () => this.tryUnlockDebugMode(),
|
91
|
109
|
icon: 'account-circle',
|
92
|
110
|
text: 'Arnaud VERGNET',
|
93
|
111
|
showChevron: false
|
|
@@ -137,26 +155,48 @@ export default class AboutScreen extends React.Component<Props> {
|
137
|
155
|
* @param icon The icon name to use from MaterialCommunityIcons
|
138
|
156
|
* @param text The text to show
|
139
|
157
|
* @param showChevron Whether to show a chevron indicating this button will change screen
|
|
158
|
+ * @param showOnlyInDebug Should we show te current item only in debug mode?
|
140
|
159
|
* @returns {React.Node}
|
141
|
160
|
*/
|
142
|
|
- static getCardItem(onPressCallback: Function, icon: string, text: string, showChevron: boolean) {
|
143
|
|
- return (
|
144
|
|
- <CardItem button
|
145
|
|
- onPress={onPressCallback}>
|
146
|
|
- <Left>
|
147
|
|
- <CustomMaterialIcon icon={icon}/>
|
148
|
|
- <Text>{text}</Text>
|
149
|
|
- </Left>
|
150
|
|
- {showChevron ?
|
151
|
|
- <Right>
|
152
|
|
- <CustomMaterialIcon icon="chevron-right"
|
153
|
|
- fontSize={20}/>
|
154
|
|
- </Right>
|
155
|
|
- :
|
156
|
|
- <Right/>
|
157
|
|
- }
|
158
|
|
- </CardItem>)
|
159
|
|
- ;
|
|
161
|
+ getCardItem(onPressCallback: Function, icon: string, text: string, showChevron: boolean, showOnlyInDebug: boolean) {
|
|
162
|
+ let shouldShow = !showOnlyInDebug || (showOnlyInDebug && this.state.isDebugUnlocked);
|
|
163
|
+ if (shouldShow) {
|
|
164
|
+ return (
|
|
165
|
+ <CardItem button
|
|
166
|
+ onPress={onPressCallback}>
|
|
167
|
+ <Left>
|
|
168
|
+ <CustomMaterialIcon icon={icon}/>
|
|
169
|
+ <Text>{text}</Text>
|
|
170
|
+ </Left>
|
|
171
|
+ {showChevron ?
|
|
172
|
+ <Right>
|
|
173
|
+ <CustomMaterialIcon icon="chevron-right"
|
|
174
|
+ fontSize={20}/>
|
|
175
|
+ </Right>
|
|
176
|
+ :
|
|
177
|
+ <Right/>
|
|
178
|
+ }
|
|
179
|
+ </CardItem>)
|
|
180
|
+ ;
|
|
181
|
+ } else {
|
|
182
|
+ return <View/>
|
|
183
|
+ }
|
|
184
|
+
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ tryUnlockDebugMode() {
|
|
188
|
+ this.debugTapCounter = this.debugTapCounter + 1;
|
|
189
|
+ console.log(this.debugTapCounter);
|
|
190
|
+ if (this.debugTapCounter >= 4) {
|
|
191
|
+ this.unlockDebugMode();
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ unlockDebugMode() {
|
|
196
|
+ console.log('unlocked');
|
|
197
|
+ this.setState({isDebugUnlocked: true});
|
|
198
|
+ let key = AsyncStorageManager.getInstance().preferences.debugUnlocked.key;
|
|
199
|
+ AsyncStorageManager.getInstance().savePref(key, '1');
|
160
|
200
|
}
|
161
|
201
|
|
162
|
202
|
render() {
|
|
@@ -168,9 +208,9 @@ export default class AboutScreen extends React.Component<Props> {
|
168
|
208
|
<Card>
|
169
|
209
|
<CardItem>
|
170
|
210
|
<Left>
|
171
|
|
- <Thumbnail square source={require('../../assets/amicale.png')}/>
|
|
211
|
+ <Thumbnail square source={require('../../assets/icon.png')}/>
|
172
|
212
|
<Body>
|
173
|
|
- <H1>Amicale INSA Toulouse</H1>
|
|
213
|
+ <H1>CAMPUS - Amicale INSAT</H1>
|
174
|
214
|
<Text note>
|
175
|
215
|
v.{appJson.expo.version}
|
176
|
216
|
</Text>
|
|
@@ -179,9 +219,10 @@ export default class AboutScreen extends React.Component<Props> {
|
179
|
219
|
</CardItem>
|
180
|
220
|
<FlatList
|
181
|
221
|
data={this.appData}
|
|
222
|
+ extraData={this.state}
|
182
|
223
|
keyExtractor={(item) => item.icon}
|
183
|
224
|
renderItem={({item}) =>
|
184
|
|
- AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
|
|
225
|
+ this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
|
185
|
226
|
}
|
186
|
227
|
/>
|
187
|
228
|
</Card>
|
|
@@ -192,9 +233,10 @@ export default class AboutScreen extends React.Component<Props> {
|
192
|
233
|
</CardItem>
|
193
|
234
|
<FlatList
|
194
|
235
|
data={this.authorData}
|
|
236
|
+ extraData={this.state}
|
195
|
237
|
keyExtractor={(item) => item.icon}
|
196
|
238
|
renderItem={({item}) =>
|
197
|
|
- AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
|
|
239
|
+ this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
|
198
|
240
|
}
|
199
|
241
|
/>
|
200
|
242
|
</Card>
|
|
@@ -205,9 +247,10 @@ export default class AboutScreen extends React.Component<Props> {
|
205
|
247
|
</CardItem>
|
206
|
248
|
<FlatList
|
207
|
249
|
data={this.technoData}
|
|
250
|
+ extraData={this.state}
|
208
|
251
|
keyExtractor={(item) => item.icon}
|
209
|
252
|
renderItem={({item}) =>
|
210
|
|
- AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
|
|
253
|
+ this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
|
211
|
254
|
}
|
212
|
255
|
/>
|
213
|
256
|
</Card>
|