React Native Orientation
npm install rn-detect-orientationCurently, works on Android and IOS
``sh`
npm install rn-detect-orientation
or
`sh`
yarn add rn-detect-orientation
`tsx
import { useEffect, useState } from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
import Orientation from 'rn-detect-orientation';
export default function App() {
const [result, setResult] = useState
const [orient, setOrient] = useState
const [isLocked, setLocked] = useState
const [sendValue, setValue] = useState
useEffect(() => {
Orientation.addOrientationListener(onOrientationDidUpdate);
return () => {
Orientation.removeOrientationListener();
};
}, []);
const onOrientationDidUpdate = (event) => {
setOrient(${event});
};
useEffect(() => {
let initialOrientation = Orientation.getInitialOrientation();
setOrient(${initialOrientation});
}, []);
const checkLocked = () => {
const locked = Orientation.isLocked();
if (locked !== isLocked) {
setLocked(locked);
}
};
return (
alignItems: 'center',
justifyContent: 'center',
}}>
);
}
`
- addOrientationListener: (cb: any) => import("react-native").EmitterSubscription;
- removeOrientationListener: () => void;
``See the contributing guide to learn how to contribute to the repository and the development workflow.