Skip to content
On this page

useScreenSafeArea

Category
Last Changed
7 months ago

Reactive env(safe-area-inset-*)

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:

<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>
<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>

Then we could use useScreenSafeAreain the component as shown below:

import { useScreenSafeArea } from '@vueuse/core'

const {
  top,
  right,
  bottom,
  left,
} = useScreenSafeArea()
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.

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

Type Declarations

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

Source

SourceDemoDocs

Contributors

Anthony Fu
Ayaka Rizumu
Jelf

Changelog

v7.3.0 on 12/12/2021
3de76 - feat(useSafeArea): new function (#985)
useScreenSafeArea has loaded