-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorientationContext.tsx
More file actions
37 lines (31 loc) · 1.01 KB
/
orientationContext.tsx
File metadata and controls
37 lines (31 loc) · 1.01 KB
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
31
32
33
34
35
36
37
import * as React from 'react';
import useOrientationChange from './useOrientationChange';
const OrientationContext = React.createContext({
isLandscape: false,
});
interface Props {
isMobile: boolean;
children: React.ReactNode;
}
/**
* Передает контекст с полем isLandscape, указывающим на текущую ориентацию экрана.
* @param {boolean} isMobile
* @param {React.ReactNode} children
*/
export const OrientationProvider: React.FC<Props> = ({
isMobile,
children,
}: Props) => {
const isLandscape = useOrientationChange(isMobile);
return (
<OrientationContext.Provider value={{ isLandscape }}>
{children}
</OrientationContext.Provider>
);
};
/**
* Берет из контекста, передаваемого OrientationProvider, поле isLandscape,
* указывающее на текущую ориентацию экрана.
*/
export const useOrientationContext = (): boolean =>
React.useContext(OrientationContext).isLandscape;