-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
84 lines (76 loc) · 2.26 KB
/
App.tsx
File metadata and controls
84 lines (76 loc) · 2.26 KB
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
import * as React from 'react';
import { Button, SafeAreaView, ScrollView, StyleSheet, TextInput, View, Text } from 'react-native';
import { performThreadedDownload } from 'react-native-threaded-downloader';
const BUTTON_TEXT = 'Perform HTTP GET';
const TIMEOUT_SECONDS = 60;
function processError(e: any) {
let result = e.toString();
result = result.replace(/Error: /g, '');
return 'Error: ' + result;
}
export default function App() {
const [url, setUrl] = React.useState<string>('https://example.com/');
const [timeoutSeconds, setTimeoutSeconds] = React.useState<Number | undefined>();
const [output, setOutput] = React.useState<string>("Enter a URL above and press '" + BUTTON_TEXT + "'");
function onSubmit() {
setOutput('Executing ' + url + ' with a timeout of ' + timeoutSeconds + ' seconds...');
performThreadedDownload(url, timeoutSeconds ?? TIMEOUT_SECONDS)
.then((response) => setOutput(response))
.catch((e) => setOutput(processError(e)));
}
return (
<SafeAreaView style={styles.container}>
<TextInput
style={styles.input}
onChangeText={setUrl}
value={url}
placeholder="URL"
clearButtonMode="always"
inputMode="url"
autoCapitalize="none"
keyboardType="url"
autoCorrect={false}
autoComplete="url"
/>
<TextInput
style={styles.input}
onChangeText={(val) => setTimeoutSeconds(parseFloat(val))}
value={timeoutSeconds?.toString()}
placeholder="Timeout (seconds)"
clearButtonMode="always"
inputMode="decimal"
autoCapitalize="none"
keyboardType="numeric"
autoCorrect={false}
/>
<View style={styles.buttonWrapper}>
<Button title={BUTTON_TEXT} onPress={onSubmit} />
</View>
<ScrollView style={styles.outputContainer}>
<Text>{output}</Text>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
input: {
height: 40,
marginVertical: 10,
borderWidth: 1,
padding: 10,
width: '75%',
},
outputContainer: {
borderWidth: 1,
padding: 10,
width: '90%',
},
buttonWrapper: {
marginVertical: 10,
},
});