-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathSensorComponent.js
More file actions
118 lines (92 loc) · 2.21 KB
/
Copy pathSensorComponent.js
File metadata and controls
118 lines (92 loc) · 2.21 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React, { useState, useEffect } from "react";
import { Pedometer } from "expo-sensors";
import styled from "styled-components/native";
import { watchStepCount } from "expo-sensors/build/Pedometer";
// = Styled components
const StepContainer = styled.View`
display:flex;
flex-direction:column;
margin-top:10px;
`;
const StepTitle = styled.Text`
font-size: 70px;
color: #97BFB4;
text-align:left;
font-style:italic;
opacity:0.7;
margin-bottom:-30px;
margin-left:20px;
`;
const StepTitle2 = styled.Text`
font-size: 70px;
color: #97BFB4;
text-align:center;
`;
const StepTitle3 = styled.Text`
font-size: 42px;
color: #F5EEDC;
text-align:left;
padding:20px;
margin-left:20px;
margin-top:-10px;
`;
const CountingContainer = styled.View`
background-color:#F5EEDC;
opacity:0.5;
margin-top:20px;
margin-bottom:20px;
padding:30px;
`
const StepText = styled.Text`
font-size: 90px;
font-weight: bold;
color: #4F091D;
text-align:center;
`;
const StepText2 = styled.Text`
font-size: 40px;
color:#F5EEDC;
text-align:center;
`;
const AvaiabilityOnDevice= styled.Text`
`;
// = Functions
export const SensorComponent= () => {
const [StepAvailability, setStepAvailability] =
useState("");
const [stepCounter, updateStepCounter] = useState(0)
useEffect(()=>{
subscribe()
},[])
const subscribe = () => {
const subscription=Pedometer.watchStepCount((result)=>{
updateStepCounter(result.steps);
})
const _unsubscribe = () => {
subscription && subscription.remove();
watchStepCount(null);
}
// Checks if pedometer function is available on device
Pedometer.isAvailableAsync().then(
(result) => {
setStepAvailability((result));
},
(error) => {
setStepAvailability(error);
}
);
}
return (
<StepContainer >
<StepTitle>STEP</StepTitle>
<StepTitle2>TRACKER</StepTitle2>
<StepTitle3>How much have you been walking today???</StepTitle3>
<CountingContainer>
<StepText>{stepCounter}</StepText>
</CountingContainer>
<StepText2>steps...</StepText2>
<StepText2>...SO FAR!!</StepText2>
<AvaiabilityOnDevice> {StepAvailability}</AvaiabilityOnDevice>
</StepContainer >
);
};