This repository was archived by the owner on Jul 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
93 lines (86 loc) · 2.15 KB
/
Copy pathApp.js
File metadata and controls
93 lines (86 loc) · 2.15 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
85
86
87
88
89
90
91
92
93
import React, {useState} from 'react';
import {
SafeAreaView,
StyleSheet,
View,
Text,
StatusBar,
NativeModules,
TouchableOpacity,
} from 'react-native';
import {Icon} from 'react-native-elements';
// we import our native module
const {WebServerManager} = NativeModules;
const App: () => React$Node = () => {
const [endpoint, setEndpint] = useState('');
const [isServerRunning, setServerState] = useState(false);
const startServer = () => {
WebServerManager.startServer()
.then(url => setEndpint(url))
.then(() => setServerState(true))
.catch(err => console.error(err));
};
const stopServer = () => {
WebServerManager.stopServer();
setEndpint('');
setServerState(false);
};
return (
<>
<StatusBar barStyle="light-content" />
<SafeAreaView style={styles.safeView}>
<View style={styles.infoBlock}>
<Text style={styles.text}>
Press button to turn {isServerRunning ? 'Off' : 'On'} server
</Text>
</View>
<View style={styles.container}>
<TouchableOpacity>
<Icon
raised
name="power-off"
type="font-awesome"
color={isServerRunning ? '#01b907' : '#f44336'}
onPress={() => (isServerRunning ? stopServer() : startServer())}
/>
</TouchableOpacity>
</View>
{isServerRunning ? (
<View style={styles.container}>
<Text style={{...styles.text, ...styles.urlEndpoint}}>
Server is available at this Url : {endpoint}
</Text>
</View>
) : (
<View style={styles.container} />
)}
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
safeView: {
backgroundColor: '#282c34',
height: '100%',
},
urlEndpoint: {
paddingTop: 20,
},
text: {
color: '#FFF',
fontWeight: '900',
fontSize: 20,
textAlign: 'center',
},
infoBlock: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
export default App;