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