Im learning how to use device orientation sensor in React Native app through https://www.w3.org/TR/orientation-event/ and https://developer.mozilla.org/en-US/docs/Web/API/Detecting_device_orientation.
My App.js:
const App = () => {
window.addEventListener("deviceorientation", onOrientationChanged,true);
function onOrientationChanged(event) {
var absolute = event.absolute;
var alpha = event.alpha;
var beta = event.beta;
var gamma = event.gamma;
console.log(beta);
}
return (
<>
<ScrollView
contentInsetAdjustmentBehavior="automatic">
<Text>kfkasdfasd</Text>
</ScrollView>
</>
);
};
Running this results in:
TypeError: window.addEventListener is not a function. (In 'window.addEventListener("deviceorientation", onOrientationChanged, true)', 'window.addEventListener' is undefined)
I couldnt google anyone having the same problem, so I am confused as how to solve this when I followed documentation and did not add anything extra.