forked from firofame/react-native-compass-heading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (22 loc) · 702 Bytes
/
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
import { NativeModules, NativeEventEmitter } from 'react-native';
const { CompassHeading } = NativeModules;
let listener;
//Monkey patching
let _start = CompassHeading.start;
CompassHeading.start = async (update_rate, callback) => {
if (listener) {
await CompassHeading.stop();
}
const compassEventEmitter = new NativeEventEmitter(CompassHeading);
listener = compassEventEmitter.addListener('HeadingUpdated', (data) => {
callback(data);
});
return await _start(update_rate === null ? 0 : update_rate);
}
let _stop = CompassHeading.stop;
CompassHeading.stop = async () => {
listener && listener.remove();
listener = null;
await _stop();
}
export default CompassHeading;