Reputation: 417
Long story short I'm writing a calculator app in react-native and i want to have 2 different views for when the phone is vertiacly and horizontaly, is there a quick way to get the phone orientation without installing any packages
Upvotes: 0
Views: 89
Reputation: 2877
import { Dimensions } from 'react-native';
function useIsHorizonal() {
const [isHorizonal, setIsHorizonal] = useState( Dimensions.screen.width > Dimensions.screen.height )
useEffect(()=> {
Dimensions.addEventListener(
'change',
({ screen: { width, height }}) =>
setIsHorizonal(width > height)
)
}, [])
return isHorizonal
}
Upvotes: 2