-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (25 loc) · 809 Bytes
/
index.js
File metadata and controls
30 lines (25 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// eslint-disable-next-line no-unused-vars
import { useState, useEffect } from 'react';
import { Dimensions } from 'react-native';
export const ORIENTATION = {
LANDSCAPE: 'landscape',
PORTRAIT: 'portrait',
};
function getWindowOrientation() {
const { width, height } = Dimensions.get('window');
return height >= width ? ORIENTATION.PORTRAIT : ORIENTATION.LANDSCAPE;
}
function useDeviceOrientation() {
const [deviceOrientation, setDeviceOrientation] = useState(
getWindowOrientation,
);
useEffect(() => {
function updateState() {
setDeviceOrientation(getWindowOrientation());
}
const subscription = Dimensions.addEventListener('change', updateState);
return () => subscription.remove();
}, []);
return deviceOrientation;
}
export default useDeviceOrientation;