Please provide the following:
- SDK Version: ~42.0.1
- Platforms(Android/iOS/web/all): Android
- Expo Sensors (Accelerometer)
Hey i was stuck at this issue since 2 days, i am trying to remove the subscription by calling subscription.remove() but subscription does not remove and other screens work very slow if i don’t remove the subscription, thanks for your help.
here the code
const _subscribe = () => {
setSubscription(
Accelerometer.addListener((gyroscopeData) => {
setData(gyroscopeData);
setZAngle((e) => e + gyroscopeData.z);
setXAngle((e) => e + gyroscopeData.x);
setYAngle((e) => e + gyroscopeData.y);
let norm_Of_g = Math.sqrt(
gyroscopeData.x * gyroscopeData.x +
gyroscopeData.y * gyroscopeData.y +
gyroscopeData.z * gyroscopeData.z
);
let g = [gyroscopeData.x, gyroscopeData.y, gyroscopeData.z];
g[0] = g[0] / norm_Of_g;
g[1] = g[1] / norm_Of_g;
g[2] = g[2] / norm_Of_g;
let inclination = Math.round(radians_to_degrees(Math.acos(g[2])));
let rotation = Math.round(radians_to_degrees(Math.atan2(g[0], g[1])));
setTiltInDeg(rotation);
setLyingFlat(inclination);
// console.log(rotation);
})
);
};
useEffect(() => {
if (subscription) return;
_slow();
_subscribe();
return () => _unsubscribe();
}, );