Skip to content

Commit 16fb064

Browse files
committed
docs: add useScreenSafeArea docs & demo
1 parent 392f676 commit 16fb064

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

public/safe-areas-1.png

147 KB
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* title: Basic Usage
3+
* desc: Get the safe area of the screen.
4+
*
5+
* title.zh-CN: 基础用法
6+
* desc.zh-CN: 获取屏幕安全区域。
7+
*/
8+
import { useScreenSafeArea } from '@any-hooks/solid'
9+
10+
export default () => {
11+
const safeArea = useScreenSafeArea()
12+
13+
return (
14+
<div>
15+
<pre>
16+
{JSON.stringify(safeArea(), null, 2)}
17+
</pre>
18+
</div>
19+
)
20+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# useScreenSafeArea
2+
3+
Reactive `env(safe-area-inset-*)`
4+
5+
Get the safe area of the screen.
6+
7+
<img src="/safe-areas-1.png" alt="safe-area" style="max-width: 80%;display:block;margin:24px auto" />
8+
9+
## Examples
10+
11+
### Basic Usage
12+
13+
>>> ./demo/demo1.tsx
14+
15+
16+
## Usage
17+
18+
In order to make the page to be fully rendered in the screen, the additional attribute `viewport-fit=cover` within `viewport` meta tag must be set firstly, the `viewport` meta tag may look like this:
19+
20+
```html
21+
<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>
22+
```
23+
24+
## API
25+
26+
```ts
27+
const safeArea = useScreenSafeArea()
28+
```
29+
30+
### Result
31+
32+
| 参数 | 说明 | 类型 |
33+
| -------- | -------- | ---------------- |
34+
| safeArea | 安全区域 | `Accessor<Area>` |
35+
36+
### Area
37+
38+
| 参数 | 说明 | 类型 |
39+
| -------- | ------------ | ---------------- |
40+
| top | 顶部安全区域 | `string` |
41+
| bottom | 底部安全区域 | `string` |
42+
| left | 左侧安全区域 | `string` |
43+
| right | 右侧安全区域 | `string` |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# useScreenSafeArea
2+
3+
响应式 `env(safe-area-inset-*)`
4+
5+
获取屏幕可交互的安全区域。
6+
7+
<img src="/safe-areas-1.png" alt="safe-area" style="max-width: 80%;display:block;margin:24px auto" />
8+
9+
## 代码演示
10+
11+
### 基础用法
12+
13+
>>> ./demo/demo1.tsx
14+
15+
16+
## 使用
17+
18+
为了使页面在屏幕上完全呈现,必须首先设置 `viewport meta` 标签中的附加属性 `viewport-fit=cover`,
19+
`viewport meta` 标签可能看起来像这样:
20+
21+
```html
22+
<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>
23+
```
24+
25+
## API
26+
27+
```ts
28+
const safeArea = useScreenSafeArea()
29+
```
30+
31+
### Result
32+
33+
| Property | Description | Type |
34+
| -------- | --------------- | ---------------- |
35+
| safeArea | Safe area | `Accessor<Area>` |
36+
37+
### Area
38+
39+
| Property | Description | Type |
40+
| -------- | ------------------- | ---------------- |
41+
| top | Safe area of top | `string` |
42+
| bottom | Safe area of bottom | `string` |
43+
| left | Safe area of left | `string` |
44+
| right | Safe area of right | `string` |

0 commit comments

Comments
 (0)