-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.js
76 lines (67 loc) · 1.92 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
/***************************************************
*
* @Author: Matheus dos Reis <[email protected]>
* @Date: 15/12/2018
* @Description: Main Application component. It have
* a Header, the main view and a footer with tabs
* to access the main features of the application
*
**************************************************/
import React, { useState, useEffect } from "react";
import { StyleSheet, View, StatusBar } from "react-native";
import BluetoothSerial from "react-native-bluetooth-serial";
import { Header } from "react-native-elements";
import Router from "./src/router";
const App = props => {
const [btStatus, setBluetoothStatus] = useState(false);
const btManager = BluetoothSerial;
const getStatusFromDevice = async () => {
const status = await btManager.isEnabled();
setBluetoothStatus(status);
};
useEffect(() => {
getStatusFromDevice();
btManager.on("bluetoothEnabled", () => {
setBluetoothStatus(true);
});
btManager.on("bluetoothDisabled", () => {
setBluetoothStatus(false);
});
}, []);
const toggleBt = e => {
if (!btStatus) btManager.disable();
else btManager.enable();
};
return (
<View style={styles.container}>
<StatusBar hidden />
<Header
outerContainerStyles={{ height: 56 }}
backgroundColor={"#0F728F"}
centerComponent={{
text: "Natuino",
style: { color: "white", fontSize: 20 }
}}
rightComponent={{
icon: btStatus ? "bluetooth" : "bluetooth-disabled",
onPress: () => toggleBt(),
color: "white",
size: 25,
underlayColor: "transparent"
}}
/>
<Router />
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: "#fff",
flex: 3,
alignItems: "stretch",
justifyContent: "flex-start",
marginBottom: -2,
paddingBottom: -2
}
});
export default App;