forked from smekalka/react-native-universal-pedometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (42 loc) · 1.4 KB
/
index.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
import { NativeModules, NativeEventEmitter } from 'react-native';
const { BMDPedometer } = NativeModules;
const EventEmitter = new NativeEventEmitter(BMDPedometer);
let subscription;
let stepsSubscription;
export default {
isStepCountingAvailable: (callback) => {
BMDPedometer.isStepCountingAvailable(callback);
},
isDistanceAvailable: (callback) => {
BMDPedometer.isDistanceAvailable(callback);
},
isFloorCountingAvailable: (callback) => {
BMDPedometer.isFloorCountingAvailable(callback);
},
isCadenceAvailable: (callback) => {
BMDPedometer.isCadenceAvailable(callback);
},
startPedometerUpdatesFromDate: (date, handler) => {
BMDPedometer.startPedometerUpdatesFromDate(date);
subscription = EventEmitter.addListener('pedometerDataDidUpdate', handler);
},
startStepsDetection: (handler) => {
BMDPedometer.startStepsDetection();
stepsSubscription = EventEmitter.addListener('pedometerWasStep', handler);
},
queryPedometerDataBetweenDates: (startDate, endDate, handler) => {
BMDPedometer.queryPedometerDataBetweenDates(startDate, endDate, handler);
},
authorizationStatus: (callback) => {
BMDPedometer.authorizationStatus(callback);
},
stopPedometerUpdates: () => {
BMDPedometer.stopPedometerUpdates();
if (subscription) {
subscription.remove();
}
if (stepsSubscription) {
stepsSubscription.remove();
}
}
};