-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
96 lines (85 loc) · 2.11 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
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
import {
View,
StyleSheet,
NativeModules,
NativeEventEmitter,
Button,
TextInput,
ScrollView,
SafeAreaView,
} from 'react-native';
import React from 'react';
const CounterEvents = new NativeEventEmitter(NativeModules.Counter);
export default function App() {
const [msgTxt, setMsgText] = React.useState('');
const [name, setName] = React.useState('');
React.useEffect(() => {
CounterEvents.addListener('msgRcv', result =>
console.log('Rcvd Message : ', result[0]),
);
return () => {
try {
CounterEvents.removeAllListeners();
} catch (e) {}
};
}, []);
// async function increment() {
// try {
// NativeModules.Counter.increment(val => {
// console.info('Count is ' + val);
// });
// } catch (e) {
// console.log(e);
// }
// }
// async function decrement() {
// try {
// var res = await NativeModules.Counter.decrement();
// console.log(res);
// } catch (error) {
// console.log(error.message, error.code);
// }
// }
function setUpDevice() {
NativeModules.Counter.setUpDevice(name);
}
function host() {
NativeModules.Counter.host();
}
function join() {
NativeModules.Counter.join();
}
function sendMsg() {
NativeModules.Counter.sendMsg(msgTxt);
}
return (
<SafeAreaView>
<ScrollView>
<View style={styles.container}>
<TextInput
placeholder="Device Name"
onChangeText={newText => setName(newText)}
value={name}
/>
<Button title="Set Up Device" onPress={setUpDevice} />
<Button title="Host" onPress={host} />
<Button title="Join" onPress={join} />
<TextInput
placeholder="Type your message"
onChangeText={newText => setMsgText(newText)}
value={msgTxt}
/>
<Button title="Send" onPress={sendMsg} />
</View>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
height: 500,
},
});