Created
August 6, 2020 16:40
-
-
Save FrankGerold/998497d932ad5ebf48cd3916166e960e to your computer and use it in GitHub Desktop.
Snippet from expo docs, edited into minimal component showing accelerometer readings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import { Accelerometer } from 'expo-sensors'; | |
export default function App() { | |
const [data, setData] = useState({}); | |
useEffect(() => { | |
_subscribe(); | |
}, []); | |
const _subscribe = () => { | |
this._subscription = Accelerometer.addListener(accelerometerData => { | |
setData(accelerometerData); | |
}); | |
}; | |
let { x, y, z } = data; | |
return ( | |
<View> | |
<Text>Accelerometer: (in Gs where 1 G = 9.81 m s^-2)</Text> | |
<Text> | |
x: {round(x)} y: {round(y)} z: {round(z)} | |
</Text> | |
</View> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment