Skip to content

useScreenSafeArea

Category
Export Size
1.63 kB
Last Changed
2 months ago

Reactive env(safe-area-inset-*)

image

Demo

top:
right:
bottom:
left:

Usage

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:

html
<meta name="viewport" content="initial-scale=1, viewport-fit=cover" />

Then we could use useScreenSafeArea in the component as shown below:

ts
import { 
useScreenSafeArea
} from '@vueuse/core'
const {
top
,
right
,
bottom
,
left
,
} =
useScreenSafeArea
()

For further details, you may refer to this documentation: Designing Websites for iPhone X

Component Usage

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

vue
<template>
  <UseScreenSafeArea 
top
right
bottom
left
>
content </UseScreenSafeArea> </template>

Type Declarations

ts
/**
 * Reactive `env(safe-area-inset-*)`
 *
 * @see https://vueuse.org/useScreenSafeArea
 */
export declare function 
useScreenSafeArea
(): {
top
:
ShallowRef
<string, string>
right
:
ShallowRef
<string, string>
bottom
:
ShallowRef
<string, string>
left
:
ShallowRef
<string, string>
update
: () => void
}

Source

SourceDemoDocs

Contributors

Anthony Fu
Anthony Fu
Melkumyants Danila
Fernando Fernández
vaakian X
Ayaka Rizumu
Jelf

Changelog

v13.4.0 on
ae573 - fix: сhanged initial value update (#4789)
v12.4.0 on
dd316 - feat: use passive event handlers everywhere is possible (#4477)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.

Build faster with AI
New Masterclass to help you leverage AI in your Vue workflow
Get Early Access