-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
55 lines (52 loc) · 1.08 KB
/
App.js
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
import React, { useEffect, useState, useLayoutEffect } from 'react';
import nodejs from 'nodejs-mobile-react-native';
import io from 'socket.io-client';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Button,
Alert,
TextInput,
} from 'react-native';
const App = () => {
const [nodeStart, setNodeStart] = useState(false);
useEffect(() => {
nodejs.start('main.js');
nodejs.channel.addListener('message', (msg) => {
Alert.alert(msg);
console.log(msg);
});
});
if (nodeStart) {
nodejs.channel.addListener("message", (msg) => {
console.log("message :::" + msg)
})
setNodeStart(false)
}
const handlePress = () => {
setNodeStart(true);
};
return (
<SafeAreaView style={styles.container}>
<View>
<View>
<Button title="Server" onPress={handlePress} />
</View>
<View>
<Button title="Client" />
</View>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
margin: 10,
},
});
export default App;