> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# `<overlay>`

APISummary
`<overlay>` is a container that does not participate in page layout. It occupies no space itself and requires neither width nor height.

When rendered, the content inside `<overlay>` is completely detached from the Lynx document flow and promoted to a rendering layer outside of Lynx.

By default, the only child of `<overlay>` uses the screen dimensions as its width and height. It is recommended to treat it as an independent drawing container for the full overlay content.

:::info

**Use cases**

- When embedding a Lynx sub-module in a native page, use `<overlay>` to build a dialog that covers the entire page.
- When the page is built entirely with Lynx, **do not** use `<overlay>`; simply use `position: fixed` instead.

:::

## Usage

### Requirements

- `<overlay>` **can only have one direct child node**.
- `<overlay>` **itself must set `position: fixed`**.

### Recommended Usage

- Use the only child node of `<overlay>` as the backdrop container:
  - Even if the background is transparent, it is still recommended to render it.
  - Explicitly set the size: **`width: 100%; height: 100%`**.
  - Explicitly create an independent stacking context: **`z-index: 0`**.

```tsx
<overlay class="overlay">
  <view class="backdrop">
    // Dialog Content
    <Dialog class="dialog-content" />
  </view>
</overlay>
```

```css
.overlay {
  overflow: visible;
  position: fixed;
}

.backdrop {
  width: 100%;
  height: 100%;
  z-index: 0;
}
```

- To adjust the dialog’s visual size, control it inside the backdrop (e.g. with `margin`) instead of changing the backdrop’s own size.

```css
.dialog-content {
  margin: 100px;
  position: absolute;
}
```

**This is an example below: overlay**

**Bundle:** `dist/base.lynx.bundle`

```tsx {19-72}
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { root, useState } from "@lynx-js/react";

const App = () => {
  const [visible, setVisible] = useState(true);

  return (
    <view
      style={{
        linearOrientation: "vertical",
        width: "100%",
        height: "100%",
        padding: "10px",
      }}
    >
      <overlay visible={visible} style={{ position: "fixed" }}>
        <view
          style={{
            width: "100%",
            height: "100%",
            backgroundColor: "rgba(0, 0, 0, 0.5)",
            display: "flex",
            justifyContent: "center",
            alignItems: "center",
          }}
          bindtap={() => setVisible(false)}
        >
          <view
            catchtap={() => console.log("tap inside the overlay")}
            style={{
              width: "80%",
              height: "50%",
              backgroundColor: "white",
              display: "flex",
              justifyContent: "center",
              alignItems: "center",
              borderRadius: "10px",
            }}
          >
            <text
              style={{
                fontSize: "30px",
                color: "red",
                textAlign: "center",
                width: "max-content",
              }}
            >
              Biz Content
            </text>
            <text
              catchtap={() => setVisible(false)}
              style={{
                position: "absolute",
                fontSize: "20px",
                color: "white",
                textAlign: "center",
                left: "20px",
                right: "20px",
                bottom: "20px",
                backgroundColor: "green",
                padding: "10px",
                borderRadius: "5px",
              }}
            >
              Dismiss
            </text>
          </view>
        </view>
      </overlay>
      <view
        bindtap={() => setVisible(true)}
        style={{
          width: "100%",
          padding: "10px",
          backgroundColor: "#12345678",
          borderRadius: "10px",
        }}
      >
        <text
          style={{
            fontSize: "30px",
            color: "red",
            textAlign: "center",
            width: "max-content",
          }}
        >
          Open the overlay
        </text>
      </view>
    </view>
  );
};

root.render(<App />);

if (import.meta.webpackHot) {
  import.meta.webpackHot.accept();
}

```

v0.7.0



## Attributes

### `ios-enable-swipe-back`

iOS
```tsx
// @defaultValue: false
'ios-enable-swipe-back'?: boolean;
```

When overlay is displayed, 'true' allows swiping right to close the current page, 'false' does not allow it

### `level`

Android
iOS
Desktop
Harmony
```tsx
// @defaultValue: 1
level?: 4 | 2 | 1 | 3;
```

Introduces the concept of layers, which are divided into four levels. The larger the layer, the closer it is to the bottom. By default, it is the first level. The layers are arranged in order from 1 to 4. The displayed layer is specified and is not affected by the order of display. Within each layer, the arrangement is based on the 'last in, first out' logic. The layer cannot be dynamically adjusted when the overlay is displayed, and can only be adjusted when it is hidden.     \*

### `mode`

iOS
```tsx
// @defaultValue: 'window'
mode?: string;
```

Specifies the level at which the overlay content resides on iOS. window: Mounted on the window, the top level of the app; top: Mounted on the topViewController; page: Mounted on UINavigationController; others: customize the name of class in the client.

### `visible`

Android
iOS
Desktop
Harmony
```tsx
// @defaultValue: false
visible?: boolean;
```

Control whether the overlay is displayed

## Events

Frontend can bind corresponding event callbacks to listen for runtime behaviors of the element, as shown below.

### `binddismissoverlay`

Android
iOS
Desktop
Harmony
```tsx
binddismissoverlay = (e: BaseEvent) => {};
```

Callback when the overlay is hidden.

### `binderror`

Android
2.18

```tsx
binderror = (e: OverlayErrorEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| errorCode | string | No | – | Android |  | Error code: 0 - Display normally; non-0 - Unable to display, you can try to solve it by using the preloading scheme mentioned below for adapting containers. |
| errorMsg | string | No | – | Android |  | Error message |

Callback when touch on the overlay

### `bindoverlaytouch`

Android
iOS
Desktop
```tsx
bindoverlaytouch = (e: OverlayTouchEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| state | OverlayTouchState | No | – | Android iOS Desktop |  | Touch state |
| x | number | No | – | Android iOS Desktop |  | x position relative to the window, in px |
| y | number | No | – | Android iOS Desktop |  | y position relative to the window, in px |

Callback when touch on the overlay

### `bindrequestclose`

Android
Desktop
Harmony
```tsx
bindrequestclose = (e: BaseEvent) => {};
```

Callback when the back button is clicked.

### `bindshowoverlay`

Android
iOS
Desktop
Harmony
```tsx
bindshowoverlay = (e: BaseEvent) => {};
```

Callback when the overlay is displayed

## Compatibility

**Compatibility Table**

**Query:** `elements.overlay`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/elements/overlay.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| overlay | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| attributes | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| attributes.visible | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| attributes.level | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | No |
| attributes.ios-enable-swipe-back | No | No | Yes (3.5) | No | No | No |
| attributes.mode | No | Yes (4.0) | Yes (3.5) | No | No | No |
| attributes.android-navigation-bar-style | Yes (4.1) | No | No | No | No | No |
| attributes.android-overlay-scope | Yes (4.3) | No | No | No | No | No |
| events.binddismissoverlay | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| events.binderror | No | No | No | No | No | No |
| events.bindoverlaytouch | Yes (3.5) | Yes (4.0) | Yes (3.5) | Yes (3.5) | Yes (3.5) | No |
| events.bindrequestclose | Yes (3.5) | Yes (3.5) | No | Yes (3.5) | Yes (3.5) | No |
| events.bindshowoverlay | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| methods.boundingClientRect | Yes (3.5) | Yes (4.0) | Yes (4.0) | No | No | Yes |
| methods.requestAccessibilityFocus | Yes (3.5) | No | Yes (3.5) | No | No | No |
| methods.scrollIntoView | Yes (3.5) | Yes (3.5) | Yes (3.5) | No | No | Yes |
| methods.setFocus | No | No | No | No | No | No |
| methods.takeScreenshot | Yes (3.5) | Yes (3.5) | Yes (3.5) | No | No | No |

**`overlay`**

overlay

**`attributes`**

attributes

**`attributes.visible`**

<code>visible</code>

**`attributes.level`**

<code>level</code>

**`attributes.ios-enable-swipe-back`**

<code>ios-enable-swipe-back</code>

**`attributes.mode`**

<code>mode</code>

**`attributes.android-navigation-bar-style`**

<code>android-navigation-bar-style</code>

**`attributes.android-overlay-scope`**

<code>android-overlay-scope</code>

**`events.binddismissoverlay`**

<code>binddismissoverlay</code>

**`events.binderror`**

<code>binderror</code>

**`events.bindoverlaytouch`**

<code>bindoverlaytouch</code>

**`events.bindrequestclose`**

<code>bindrequestclose</code>

**`events.bindshowoverlay`**

<code>bindshowoverlay</code>

**`methods.boundingClientRect`**

<code>boundingClientRect</code>

**`methods.requestAccessibilityFocus`**

<code>requestAccessibilityFocus</code>

**`methods.scrollIntoView`**

<code>scrollIntoView</code>

- **Web — Supported (version unknown):** Uses the browser element method.

**`methods.setFocus`**

<code>setFocus</code>

**`methods.takeScreenshot`**

<code>takeScreenshot</code>

