forked from firofame/react-native-compass-heading
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (22 loc) · 669 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (22 loc) · 669 Bytes
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 = (update_rate, callback) => {
if (listener) {
CompassHeading.stop();
}
const compassEventEmitter = new NativeEventEmitter(CompassHeading);
listener = compassEventEmitter.addListener('HeadingUpdated', (degree) => {
callback(degree);
});
_start(update_rate === null ? 0 : update_rate);
}
let _stop = CompassHeading.stop;
CompassHeading.stop = () => {
listener && listener.remove();
listener = null;
_stop();
}
export default CompassHeading;