-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.tsx
37 lines (32 loc) · 880 Bytes
/
index.tsx
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 { Interpolation, Theme } from '@emotion/react';
import { useViewport } from '../Effect/useViewport';
export interface SafeAreaProps extends React.HTMLProps<HTMLDivElement> {
children?: React.ReactNode;
// 目前只支持常见的顶部和底部
type: 'top' | 'bottom';
}
export function SafeArea(props: SafeAreaProps) {
const { children, type = 'bottom', ...extra } = props;
useViewport({ viewportFit: 'cover' });
let boxCss: Interpolation<Theme>;
if (type === 'top') {
boxCss = {
height: [
`constant(safe-area-inset-top, 0)`,
`env(safe-area-inset-top, 0)`,
],
};
} else if (type === 'bottom') {
boxCss = {
height: [
`constant(safe-area-inset-bottom, 0)`,
`env(safe-area-inset-bottom, 0)`,
],
};
}
return (
<div css={boxCss} {...extra}>
{children}
</div>
);
}