/
SettingsScreen.tsx
323 lines (284 loc) · 9.91 KB
/
SettingsScreen.tsx
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import {
Button,
Heading,
Text,
Divider,
Row,
Spacer,
View,
ShakeDeviceIcon,
ShowMenuIcon,
ThreeFingerPressIcon,
CheckIcon,
} from 'expo-dev-client-components';
import * as React from 'react';
import { ScrollView, Switch } from 'react-native';
import { useQueryClient } from 'react-query';
import { SafeAreaTop } from '../components/SafeAreaTop';
import { ScreenContainer } from '../components/ScreenContainer';
import { Toasts } from '../components/Toasts';
import { copyToClipboardAsync } from '../native-modules/DevLauncherInternal';
import { useBuildInfo } from '../providers/BuildInfoProvider';
import { useDevMenuPreferences } from '../providers/DevMenuPreferencesProvider';
import { useQueryOptions } from '../providers/QueryProvider';
import { useToastStack } from '../providers/ToastStackProvider';
import { useUpdatesConfig } from '../providers/UpdatesConfigProvider';
import { useUser } from '../providers/UserContextProvider';
export function SettingsScreen() {
const { userData } = useUser();
const [, setClipboardError] = React.useState('');
const [clipboardContent, setClipboardContent] = React.useState('');
const {
showsAtLaunch,
setShowsAtLaunch,
touchGestureEnabled,
setTouchGestureEnabled,
motionGestureEnabled,
setMotionGestureEnabled,
} = useDevMenuPreferences();
const buildInfo = useBuildInfo();
const timerRef = React.useRef(null);
React.useEffect(() => {
if (clipboardContent) {
timerRef.current = setTimeout(() => {
setClipboardContent('');
}, 3000);
}
return () => {
clearTimeout(timerRef.current);
};
}, [clipboardContent]);
const onCopyPress = async () => {
const { runtimeVersion, sdkVersion, appName, appVersion } = buildInfo;
const content = JSON.stringify(
{
runtimeVersion,
sdkVersion,
appName,
appVersion,
},
null,
'\t'
);
setClipboardError('');
setClipboardContent(content);
await copyToClipboardAsync(content).catch((err) => {
setClipboardError(err.message);
setClipboardContent('');
});
};
const hasCopiedContent = Boolean(clipboardContent);
return (
<ScrollView testID="DevLauncherSettingsScreen" showsVerticalScrollIndicator={false}>
<ScreenContainer>
<SafeAreaTop />
<Spacer.Vertical size="medium" />
<View px="medium">
<Heading size="large">Settings</Heading>
</View>
<View py="large" px="medium">
<View bg="default" rounded="large">
<Row px="medium" py="small" align="center">
<ShowMenuIcon />
<Spacer.Horizontal size="small" />
<Text size="large">Show menu at launch</Text>
<Spacer.Horizontal />
<Switch
accessibilityRole="switch"
accessibilityLabel="Toggle showing menu at launch"
value={showsAtLaunch}
onValueChange={() => setShowsAtLaunch(!showsAtLaunch)}
/>
</Row>
</View>
<Spacer.Vertical size="large" />
<View padding="medium">
<Heading color="secondary">Menu gestures</Heading>
</View>
<View>
<Button.FadeOnPressContainer
bg="default"
roundedTop="large"
roundedBottom="none"
onPress={() => setMotionGestureEnabled(!motionGestureEnabled)}
accessibilityState={{ checked: motionGestureEnabled }}>
<Row px="medium" py="small" align="center" bg="default">
<ShakeDeviceIcon />
<Spacer.Horizontal size="small" />
<Text size="large" color="default">
Shake device
</Text>
<Spacer.Horizontal />
{motionGestureEnabled && <CheckIcon />}
</Row>
</Button.FadeOnPressContainer>
<Divider />
<Button.FadeOnPressContainer
bg="default"
roundedBottom="large"
roundedTop="none"
onPress={() => setTouchGestureEnabled(!touchGestureEnabled)}
accessibilityState={{ checked: touchGestureEnabled }}>
<Row px="medium" py="small" bg="default">
<ThreeFingerPressIcon />
<Spacer.Horizontal size="small" />
<Text size="large" color="default">
Three-finger long-press
</Text>
<Spacer.Horizontal />
{touchGestureEnabled && <CheckIcon />}
</Row>
</Button.FadeOnPressContainer>
</View>
<View padding="small">
<Text color="secondary" size="small" leading="large">
Selected gestures will toggle the developer menu while inside a preview. The menu
allows you to reload or return to home and exposes developer tools.
</Text>
</View>
<Spacer.Vertical size="medium" />
<View rounded="large" overflow="hidden">
<Row px="medium" py="small" align="center" bg="default">
<Text>Version</Text>
<Spacer.Horizontal />
<Text>{buildInfo?.appVersion}</Text>
</Row>
{Boolean(buildInfo.runtimeVersion) && (
<>
<Divider />
<Row px="medium" py="small" align="center" bg="default">
<Text>Runtime Version</Text>
<Spacer.Horizontal />
<Text>{buildInfo.runtimeVersion}</Text>
</Row>
</>
)}
{Boolean(buildInfo.sdkVersion) && !buildInfo.runtimeVersion && (
<>
<Divider />
<Row px="medium" py="small" align="center" bg="default">
<Text>SDK Version</Text>
<Spacer.Horizontal />
<Text>{buildInfo.sdkVersion}</Text>
</Row>
</>
)}
<Divider />
<Button.FadeOnPressContainer
onPress={onCopyPress}
disabled={hasCopiedContent}
bg="default"
roundedTop="none"
roundedBottom="large">
<Row px="medium" py="small" align="center" bg="default">
<Text color="link" size="medium">
{hasCopiedContent ? 'Copied to clipboard!' : 'Tap to Copy All'}
</Text>
</Row>
</Button.FadeOnPressContainer>
{userData?.isExpoAdmin && (
<>
<Spacer.Vertical size="medium" />
<DebugSettings />
<Spacer.Vertical size="medium" />
<UpdatesDebugSettings />
</>
)}
</View>
</View>
</ScreenContainer>
</ScrollView>
);
}
function DebugSettings() {
const queryClient = useQueryClient();
const { queryOptions, setQueryOptions } = useQueryOptions();
const toastStack = useToastStack();
function setPageSize(pageSize: number) {
setQueryOptions({
...queryOptions,
pageSize,
});
}
async function onClearQueryPress() {
await queryClient.resetQueries();
await queryClient.invalidateQueries();
toastStack?.push(() => <Toasts.Info>Network cache was reset!</Toasts.Info>);
}
const pageSizeOptions = [1, 5, 10];
return (
<View>
<View padding="medium">
<Heading color="secondary">Debug Settings</Heading>
</View>
<View>
<View>
<Button.FadeOnPressContainer
bg="default"
roundedTop="large"
roundedBottom="large"
onPress={onClearQueryPress}>
<Row px="medium" py="small" align="center" bg="default">
<Text size="large" color="default">
Clear network cache
</Text>
<Spacer.Horizontal />
</Row>
</Button.FadeOnPressContainer>
<Spacer.Vertical size="large" />
<View px="medium">
<Heading size="small" color="secondary">
Default Page Size
</Heading>
<Text color="secondary" size="small">
Sets the number of items fetched for branches and updates
</Text>
</View>
<Spacer.Vertical size="medium" />
<View>
{pageSizeOptions.map((pageSize, index, arr) => {
const isSelected = queryOptions.pageSize === pageSize;
const isFirst = index === 0;
const isLast = index === arr.length - 1;
return (
<View key={pageSize}>
<Button.FadeOnPressContainer
bg="default"
roundedTop={isFirst ? 'large' : 'none'}
roundedBottom={isLast ? 'large' : 'none'}
onPress={() => setPageSize(pageSize)}
accessibilityState={{ checked: isSelected }}>
<Row px="medium" py="small" align="center" bg="default">
<Text size="large" color="default">
{pageSize}
</Text>
<Spacer.Horizontal />
{isSelected && <CheckIcon />}
</Row>
</Button.FadeOnPressContainer>
{!isLast && <Divider />}
</View>
);
})}
</View>
</View>
</View>
</View>
);
}
function UpdatesDebugSettings() {
const updatesConfig = useUpdatesConfig();
return (
<View my="medium">
<View px="medium">
<Heading color="secondary">EAS Update configuration</Heading>
<Spacer.Vertical size="medium" />
</View>
<View bg="default" padding="medium" rounded="large">
<Text type="mono" size="small">
{JSON.stringify(updatesConfig, null, 2)}
</Text>
</View>
</View>
);
}