-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathupdateSample.js
31 lines (28 loc) · 1.04 KB
/
updateSample.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
const timer = require('react-native-timer');
export const beginUpdate = (context, callback) => {
// Check if timer exists before executing - if it does, cancel it
endUpdate(context);
// Create timer that sends data across
timer.setInterval(context, 'updatingInterval', () => {
// I'll be sending a location update through the callback to simulate
// server pings
if (typeof(callback) === 'function') {
callback(
{
overlayReferenceId: 'graphicsOverlay',
updates: [{
referenceId: 'movingImage',
latitude: 39.739235 - (20 * Math.random()),
longitude: -104.990250 - (20 * Math.random()),
rotation: 360 * Math.random(),
}]
});
console.log('Update logged');
}
}, 1500);
}
export const endUpdate = (context) => {
if (timer.intervalExists(context, 'updatingInterval')) {
timer.clearInterval(context, 'updatingInterval')
}
}