|
@@ -1,24 +1,61 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import * as React from 'react';
|
4
|
|
-import {Body, Card, CardItem, Container, Content, Left, List, ListItem, Right, Text,} from "native-base";
|
|
4
|
+import {
|
|
5
|
+ Body,
|
|
6
|
+ Card,
|
|
7
|
+ CardItem,
|
|
8
|
+ Container,
|
|
9
|
+ Content,
|
|
10
|
+ H1,
|
|
11
|
+ H3,
|
|
12
|
+ Left,
|
|
13
|
+ List,
|
|
14
|
+ ListItem,
|
|
15
|
+ Right,
|
|
16
|
+ Text,
|
|
17
|
+ Form,
|
|
18
|
+ Item,
|
|
19
|
+ Label,
|
|
20
|
+ Input,
|
|
21
|
+ Button
|
|
22
|
+} from "native-base";
|
5
|
23
|
import CustomHeader from "../components/CustomHeader";
|
6
|
24
|
import ThemeManager from '../utils/ThemeManager';
|
7
|
25
|
import i18n from "i18n-js";
|
8
|
26
|
import CustomMaterialIcon from "../components/CustomMaterialIcon";
|
9
|
27
|
import Touchable from "react-native-platform-touchable";
|
10
|
|
-import {Alert, Platform, Clipboard} from "react-native";
|
|
28
|
+import {Alert, View, Clipboard, Image} from "react-native";
|
11
|
29
|
import AsyncStorageManager from "../utils/AsyncStorageManager";
|
12
|
30
|
import NotificationsManager from "../utils/NotificationsManager";
|
|
31
|
+import Modalize from "react-native-modalize";
|
13
|
32
|
|
14
|
33
|
type Props = {
|
15
|
34
|
navigation: Object,
|
16
|
35
|
};
|
17
|
36
|
|
|
37
|
+type State = {
|
|
38
|
+ modalCurrentDisplayItem: Object,
|
|
39
|
+ currentPreferences: Object,
|
|
40
|
+}
|
|
41
|
+
|
18
|
42
|
/**
|
19
|
43
|
* Class defining the Debug screen. This screen allows the user to get detailed information on the app/device.
|
20
|
44
|
*/
|
21
|
|
-export default class DebugScreen extends React.Component<Props> {
|
|
45
|
+export default class DebugScreen extends React.Component<Props, State> {
|
|
46
|
+
|
|
47
|
+ modalRef: { current: null | Modalize };
|
|
48
|
+ modalInputValue = '';
|
|
49
|
+
|
|
50
|
+ constructor(props: any) {
|
|
51
|
+ super(props);
|
|
52
|
+ this.modalRef = React.createRef();
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ state = {
|
|
56
|
+ modalCurrentDisplayItem: {},
|
|
57
|
+ currentPreferences: JSON.parse(JSON.stringify(AsyncStorageManager.getInstance().preferences))
|
|
58
|
+ };
|
22
|
59
|
|
23
|
60
|
alertCurrentExpoToken() {
|
24
|
61
|
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
|
@@ -39,15 +76,19 @@ export default class DebugScreen extends React.Component<Props> {
|
39
|
76
|
}
|
40
|
77
|
|
41
|
78
|
|
42
|
|
- static getGeneralItem(onPressCallback: Function, icon: string, title: string, subtitle: string) {
|
|
79
|
+ static getGeneralItem(onPressCallback: Function, icon: ?string, title: string, subtitle: string) {
|
43
|
80
|
return (
|
44
|
|
- <CardItem
|
|
81
|
+ <ListItem
|
45
|
82
|
button
|
|
83
|
+ thumbnail
|
46
|
84
|
onPress={onPressCallback}
|
47
|
85
|
>
|
48
|
|
- <Left>
|
49
|
|
- <CustomMaterialIcon icon={icon}/>
|
50
|
|
- </Left>
|
|
86
|
+ {icon !== undefined ?
|
|
87
|
+ <Left>
|
|
88
|
+ <CustomMaterialIcon icon={icon}/>
|
|
89
|
+ </Left>
|
|
90
|
+ : <View/>
|
|
91
|
+ }
|
51
|
92
|
<Body>
|
52
|
93
|
<Text>
|
53
|
94
|
{title}
|
|
@@ -57,14 +98,71 @@ export default class DebugScreen extends React.Component<Props> {
|
57
|
98
|
</Text>
|
58
|
99
|
</Body>
|
59
|
100
|
<Right/>
|
60
|
|
- </CardItem>
|
|
101
|
+ </ListItem>
|
61
|
102
|
);
|
62
|
103
|
}
|
63
|
104
|
|
|
105
|
+ showEditModal(item: Object) {
|
|
106
|
+ this.setState({
|
|
107
|
+ modalCurrentDisplayItem: item
|
|
108
|
+ });
|
|
109
|
+ if (this.modalRef.current) {
|
|
110
|
+ this.modalRef.current.open();
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ getModalContent() {
|
|
115
|
+ return (
|
|
116
|
+ <View style={{
|
|
117
|
+ flex: 1,
|
|
118
|
+ padding: 20
|
|
119
|
+ }}>
|
|
120
|
+ <H1>{this.state.modalCurrentDisplayItem.key}</H1>
|
|
121
|
+ <H3>Default: {this.state.modalCurrentDisplayItem.default}</H3>
|
|
122
|
+ <H3>Current: {this.state.modalCurrentDisplayItem.current}</H3>
|
|
123
|
+ <Form>
|
|
124
|
+ <Item floatingLabel>
|
|
125
|
+ <Label>New Value</Label>
|
|
126
|
+ <Input onChangeText={(text) => this.modalInputValue = text}/>
|
|
127
|
+ </Item>
|
|
128
|
+ </Form>
|
|
129
|
+ <View style={{
|
|
130
|
+ flexDirection: 'row',
|
|
131
|
+ marginTop: 10,
|
|
132
|
+ }}>
|
|
133
|
+ <Button success
|
|
134
|
+ onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.modalInputValue)}>
|
|
135
|
+ <Text>Save new value</Text>
|
|
136
|
+ </Button>
|
|
137
|
+ <Button
|
|
138
|
+ onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.state.modalCurrentDisplayItem.default)}>
|
|
139
|
+ <Text>Reset to default</Text>
|
|
140
|
+ </Button>
|
|
141
|
+ </View>
|
|
142
|
+
|
|
143
|
+ </View>
|
|
144
|
+ );
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ saveNewPrefs(key: string, value: string) {
|
|
148
|
+ this.setState((prevState) => {
|
|
149
|
+ let currentPreferences = {...prevState.currentPreferences};
|
|
150
|
+ currentPreferences[key].current = value;
|
|
151
|
+ return {currentPreferences};
|
|
152
|
+ });
|
|
153
|
+ AsyncStorageManager.getInstance().savePref(key, value);
|
|
154
|
+ }
|
|
155
|
+
|
64
|
156
|
render() {
|
65
|
157
|
const nav = this.props.navigation;
|
66
|
158
|
return (
|
67
|
159
|
<Container>
|
|
160
|
+ <Modalize
|
|
161
|
+ ref={this.modalRef}
|
|
162
|
+ adjustToContentHeight
|
|
163
|
+ modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor}}>
|
|
164
|
+ {this.getModalContent()}
|
|
165
|
+ </Modalize>
|
68
|
166
|
<CustomHeader navigation={nav} title={i18n.t('screens.debug')} hasBackButton={true}/>
|
69
|
167
|
<Content padder>
|
70
|
168
|
<Card>
|
|
@@ -75,7 +173,21 @@ export default class DebugScreen extends React.Component<Props> {
|
75
|
173
|
</CardItem>
|
76
|
174
|
<List>
|
77
|
175
|
{DebugScreen.getGeneralItem(() => this.alertCurrentExpoToken(), 'bell', 'Get current Expo Token', '')}
|
78
|
|
- {DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(),'bell-ring', 'Force Expo token update', '')}
|
|
176
|
+ {DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(), 'bell-ring', 'Force Expo token update', '')}
|
|
177
|
+ </List>
|
|
178
|
+ </Card>
|
|
179
|
+ <Card>
|
|
180
|
+ <CardItem header>
|
|
181
|
+ <Text>
|
|
182
|
+ Preferences
|
|
183
|
+ </Text>
|
|
184
|
+ </CardItem>
|
|
185
|
+ <List>
|
|
186
|
+ {Object.values(this.state.currentPreferences).map((object) =>
|
|
187
|
+ <View>
|
|
188
|
+ {DebugScreen.getGeneralItem(() => this.showEditModal(object), undefined, object.key, 'Click to edit')}
|
|
189
|
+ </View>
|
|
190
|
+ )}
|
79
|
191
|
</List>
|
80
|
192
|
</Card>
|
81
|
193
|
</Content>
|