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

# `<refresh>`

APISummary
`<refresh>` element provides a pull-to-refresh gesture that reveals a customizable header view while new data is being fetched.

It fires the `refresh` event when the user pulls down past a configurable threshold, allowing you to trigger asynchronous updates and automatically hide the header once the operation completes.

## Usage

- `<refresh>` only supports vertical pull-to-refresh gestures.
- It accepts up to two direct children: `<refresh-header>` and `<view>` has vertically scrollable inside.

### Pull to refresh

Define the refresh effect through `<refresh-header>`, and set `enable-refresh` to true for `<refresh>`.

1. Pull to refresh: Drag down or call `autoStartRefresh` to lock the `<refresh-header>` at the top and fire the `startrefresh` event.

2. Finish loading: Call `finishRefresh` to animate the `<refresh-header>` out of view.

**This is an example below: refresh**

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

```tsx
// 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, useRef, useState } from "@lynx-js/react";
import type { NodesRef } from "@lynx-js/types";

const App = () => {
  const refreshViewRef = useRef<NodesRef>(null);
  const [refreshCount, setRefreshCount] = useState<number>(0);
  const [items, setItems] = useState<number[]>([0, 1, 2, 4, 5, 6, 7, 8]);
  const onStartRefresh = () => {
    console.log("on start refresh");
    setTimeout(() => {
      refreshViewRef.current?.invoke({
        method: "finishRefresh",
      }).exec();
      setItems([0, 1, 2, 4, 5, 6, 7, 8]);
      setRefreshCount(refreshCount + 1);
    }, 1000);
  };

  return (
    <view
      style={{
        width: "100%",
        height: "100%",
        flexDirection: "column",
        backgroundColor: "white",
      }}
    >
      {
        <refresh ref={refreshViewRef} style={{ width: "100%", height: "100%" }} bindstartrefresh={onStartRefresh}>
          <refresh-header
            style={{
              width: "100%",
              height: "50px",
              position: "absolute",
              justifyContent: "center",
              alignItems: "center",
              backgroundColor: "red",
            }}
          >
            <text style={{ fontSize: "30px" }}>Refreshing...</text>
          </refresh-header>
          <list style={{ width: "100%", height: "100%" }} scroll-orientation="vertical" bounces={true}>
            {items.map((item, index) => {
              return (
                <list-item key={item + ""} item-key={item + ""}>
                  <text
                    style={{
                      "height": "200px",
                      width: "100%",
                      fontSize: "100px",
                      color: refreshCount % 2 === 0 ? "red" : "green",
                      padding: "25px",
                      textAlign: "center",
                      border: "1px solid black",
                    }}
                  >
                    {`item-${index}`}
                  </text>
                </list-item>
              );
            })}
          </list>
        </refresh>
      }
    </view>
  );
};

root.render(<App />);

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

```

v0.7.0



## Attributes

### `enable-refresh`

Android
iOS
Harmony
```tsx
// @defaultValue: true
'enable-refresh'?: boolean;
```

Determines if dragging down or calling autoStartRefresh can trigger the startrefresh event.

## Events

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

### `bindheaderoffset`

Android
iOS
Harmony
```tsx
bindheaderoffset = (e: RefreshHeaderOffsetEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| isDragging | boolean | No | – | Android iOS Harmony |  | Indicates if  `<refresh-header>`  is being dragged |
| offsetPercent | number | No | – | Android iOS Harmony |  | The ratio of the pull-down movement distance to its own height |

Triggered during movement when
`<refresh-header>`
is exposed.

### `bindrefreshstatechange`

Android
iOS
Harmony
```tsx
bindrefreshstatechange = (e: RefreshStateChangeEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| state | RefreshState | No | – | Android iOS Harmony |  | Indicates if  `<refresh-header>`  is being dragged |

Triggered when
`<refresh-header>`
state changes.

### `bindstartrefresh`

Android
iOS
Harmony
```tsx
bindstartrefresh = (e: RefreshStartRefreshEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| isManual | boolean | No | – | Android iOS Harmony |  | Indicates whether the startrefresh event is triggered by manual drag |

Triggered when enable-refresh is true, and dragging down or calling autoStartRefresh (enters refresh state).

## Methods

Frontend can invoke component methods via the [SelectorQuery](/next/api/lynx-api/nodes-ref/nodes-ref-invoke.md) API.

### `autoStartRefresh`

Android
iOS
Harmony
```ts

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'autoStartRefresh',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

```

When enable-refresh is true, call this method to expose the entire
`<refresh-header>`
, triggering the startrefresh event, after which
`<refresh-header>`
will attach to the top edge of the refresh's viewport.

### `finishRefresh`

Android
iOS
Harmony
```ts

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'finishRefresh',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

```

Called after the startrefresh event to end the refresh state, making
`<refresh-header>`
rebound.

## Compatibility

**Compatibility Table**

**Query:** `elements.refresh`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| refresh | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| attributes | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| attributes.enable-refresh | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| events | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| events.bindstartrefresh | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| events.bindheaderoffset | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| events.bindrefreshstatechange | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | No |
| methods | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| methods.finishRefresh | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| methods.autoStartRefresh | Yes (3.8) | Yes (3.8) | Yes (3.8) | No | No | Yes |
| methods.boundingClientRect | Yes (3.8) | Yes (4.1) | Yes (3.8) | No | No | Yes |
| methods.requestAccessibilityFocus | Yes (3.8) | No | Yes (3.8) | No | No | No |
| methods.scrollIntoView | Yes (3.8) | Yes (4.1) | Yes (3.8) | No | No | Yes |
| methods.setFocus | No | No | No | No | No | No |
| methods.takeScreenshot | Yes (3.8) | Yes (4.1) | Yes (3.8) | No | No | No |

**`refresh`**

refresh

**`attributes`**

attributes

**`attributes.enable-refresh`**

<code>enable-refresh</code>

**`events`**

events

**`events.bindstartrefresh`**

<code>bindstartrefresh</code>

**`events.bindheaderoffset`**

<code>bindheaderoffset</code>

**`events.bindrefreshstatechange`**

<code>bindrefreshstatechange</code>

**`methods`**

methods

**`methods.finishRefresh`**

<code>finishRefresh</code>

**`methods.autoStartRefresh`**

<code>autoStartRefresh</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>

