-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
111 lines (102 loc) · 3.21 KB
/
App.tsx
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
// App.tsx
import React, {useState} from 'react';
import {Text, View} from 'react-native';
import AppleHealthKit, {HealthValue} from 'react-native-health';
import HealthData from './Healthdata';
import {
heightPercentageToDP as hp,
widthPercentageToDP as wp,
} from 'react-native-responsive-screen';
const App = () => {
const [heartRate, setHeartRate] = useState<any>();
const [stepCount, setStepCount] = useState<any>();
const [activeEngy, setActiveEngy] = useState<any>();
const [bloodSat, setBloodSat] = useState<any>();
const fetchData = () => {
// Define options for data retrieval
const options = {
startDate: '2023-11-05T18:30:00.000Z',
// if the data is not coming, tryna do tweak with above date,
// somewhere they have time limit exceptions
};
// // Retrieve Heart Rate data
AppleHealthKit.getHeartRateSamples(
{startDate: '2023-11-05T18:30:00.000Z'},
(error: string, heartRateResults: HealthValue[]) => {
if (!error) {
setHeartRate(heartRateResults);
console.log(options, 'Heart Rate Data: ', heartRateResults);
}
},
);
// // Retrieve Step count data
AppleHealthKit.getStepCount(
options,
(error: string, stepCountResults: HealthValue) => {
if (!error) {
setStepCount(stepCountResults);
console.log('Step Count Data:', stepCountResults);
}
},
);
// // need to calculate energy burned
AppleHealthKit.getActiveEnergyBurned(
options,
(error: string, results: Array<HealthValue>) => {
if (!error) {
setActiveEngy(results);
console.log('Active Energy Burned Data:', results);
}
},
);
// AppleHealthKit.getOxygenSaturationSamples(
// options,
// (callbackError: Object, results: Array<HealthValue>) => {
// if (callbackError) {
// console.log('oxy sat Error---', callbackError);
// }
// setBloodSat(results);
// console.log('this is oxygen saturation --<', results);
// },
// );
};
return (
<View style={{flex: 1}}>
<HealthData
onUpdateData={fetchData}
heartRate={heartRate}
stepCount={stepCount}
activeEngy={activeEngy}
bloodSat={bloodSat}
setHeartRate={setHeartRate}
setStepCount={setStepCount}
setActiveEngy={setActiveEngy}
setBloodSat={setBloodSat}
/>
<View
style={{
backgroundColor: 'limegreen',
padding: 10,
}}>
<Text>RESULTS: </Text>
<View
style={{
borderRadius: 10,
backgroundColor: 'aliceblue',
width: wp(80),
justifyContent: 'center',
}}>
<View style={{paddingHorizontal: 15}}>
<Text>HeartRate : {JSON.stringify(heartRate)}</Text>
<Text>StepCount : {JSON.stringify(stepCount)}</Text>
<Text>ActiveEnergy: {JSON.stringify(activeEngy)}</Text>
<Text>BloodSaturation: {JSON.stringify(bloodSat)}</Text>
</View>
{/* <Icon name='plus' color='red' size={26} /> */}
{/* {myIcon} */}
</View>
</View>
</View>
);
};
export default App;