Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async componentDidMount() {
if (!(await Accelerometer.isAvailableAsync())) {
this.setState({
error:
'Cannot start demo!' +
'\nEnable device orientation in Settings > Safari > Motion & Orientation Access' +
'\nalso ensure that you are hosting with https as DeviceMotion is now a secure API on iOS Safari.',
isSetup: false,
});
return;
}
Accelerometer.addListener(({ x, y }) => {
this.state.items.forEach((_, index) => {
// All that matters is that the values are the same on iOS, Android, Web, ect...
const { perspective } = this.props;
const nIndex = index + 1;
onPress={async () => {
this.setState({
isAvailable: await Accelerometer.isAvailableAsync(),
});
}}>
Is Available: {isAvailable ? 'true' : 'false'}
watchAccelerometer() {
Accelerometer.isAvailableAsync().then(motionAvailable => {
if (
!motionAvailable ||
!this.mounted ||
this.subscription ||
AppState.currentState !== "active"
)
return;
Accelerometer.setUpdateInterval(1000);
this.subscription = Accelerometer.addListener(acc => {
this.acceleration = acc;
});
});
}
useEffect(() => {
if (availability) {
Accelerometer.isAvailableAsync().then(setAvailable);
}
if (options.interval !== undefined) {
Accelerometer.setUpdateInterval(options.interval);
}
return Accelerometer.addListener(setData).remove;
}, []);