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

# `<scroll-coordinator>`

APISummary
`<scroll-coordinator>` 是一个嵌套滚动协调组件，用于实现多层可滚动容器之间的联动滚动，常见于滚动吸顶等主流 APP 页面结构中，一般搭配 `<viewpager>` 和 `<list>` 等组件一起构建嵌套滚动 + 分页切换的复合场景。

:::info
`<scroll-coordinator>` 通过 `<scroll-coordinator-header>` 和 `<scroll-coordinator-slot>` 对嵌套结构进行协调，实现以下效果：

- 外层滚动到底部时，自动将滚动权交给内层
- 内层滚动到顶部时，自动将滚动权交还外层
- 滚动权的交接过程顺畅无断裂

```tsx
// ❌ 不支持：直接嵌套 listen
<scroll-view id="outer">
  <list id="inner" />
</scroll-view>

// ✅ 支持：使用 scroll-coordinator 协调嵌套滚动
<scroll-coordinator>
  <scroll-coordinator-header id="outer" />
  <scroll-coordinator-slot>
    <list id="inner" />
  </scroll-coordinator-slot>
</scroll-coordinator>
```

:::

## 使用指南

`<scroll-coordinator>` 的布局核心诉求是通过 CSS 控制：**`scroll-coordinator` 的高度 == `scroll-coordinator-slot` 的高度 + toolbar 的高度**。

### 布局规范

- `<scroll-coordinator>`：纵向 flex 布局，**`display: flex; flex-direction: column;`**
- `<scroll-coordinator-header>`：脱离布局流，**`position: absolute;`**
- `<scroll-coordinator-toolbar>`：参与布局，**`display: flex;`**
- `<scroll-coordinator-slot>`：填充剩余空间，**`flex: 1;`**

```css
.coordinator {
  width: 100%;
  height: 100%
  display: flex;
  flex-direction: column;
}

.coordinator-toolbar {
  display: flex;
  width: 100%;
}

.coordinator-header {
  position: absolute;
  width: 100%;
}

.coordinator-slot {
  width: 100%;
  flex-direction: column;
  flex: 1;
}
```

### 纵向协同滚动

> `<scroll-coordinator-slot>` 内须放置一个 `<list>` 完成纵向协同滚动
>
> ```tsx
> <scroll-coordinator class="coordinator">
>   <scroll-coordinator-header class="coordinator-header">
>     <Header />
>   </scroll-coordinator-header>
>   <scroll-coordinator-slot class="coordinator-slot">
>     <list />
>   </scroll-coordinator-slot>
> </scroll-coordinator>
> ```

**下面是一个示例: scroll-coordinator**

**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 } from "@lynx-js/react";

import image0 from "../assets/item_0.jpg";
import image1 from "../assets/item_1.jpg";
import image2 from "../assets/item_2.jpg";

const App = () => {
  const coverImages = [image0, image1, image2];
  const tabs = ["Featured", "Nearby", "Saved"];
  const listItems = Array.from({ length: 24 }, (_, index) => {
    return {
      image: coverImages[index % coverImages.length],
      title: `Scenic stop ${index + 1}`,
      subtitle: index % 2 === 0 ? "Quiet path with a wide lookout" : "Short trail near the water",
      tag: index % 3 === 0 ? "Fresh" : (index % 3 === 1 ? "Calm" : "Open"),
    };
  });

  return (
    <view
      style={{
        width: "100%",
        height: "100%",
        flexDirection: "column",
        display: "flex",
        padding: "24px",
        backgroundColor: "#F6F7F9",
        boxSizing: "border-box",
      }}
    >
      <text style={{ fontSize: "32px", fontWeight: "700", color: "#202124" }}>Scroll Coordinator</text>
      <scroll-coordinator
        style={{
          marginTop: "24px",
          width: "100%",
          height: "100%",
          flex: "1",
          display: "flex",
          flexDirection: "column",
          position: "relative",
          overflow: "hidden",
          backgroundColor: "#EDEFF2",
        }}
      >
        {
          /*
          Optional, fixed at the top of the scroll coordinator and won't collapse.
          When it exists, control scroll-coordinator.height == slot.height + toolbar.height through CSS.
          */
        }
        <scroll-coordinator-toolbar
          style={{
            display: "flex",
            width: "100%",
            height: "88rpx",
            alignItems: "center",
            justifyContent: "space-between",
            padding: "0 24rpx",
            backgroundColor: "#FFFFFFAA",
            boxSizing: "border-box",
          }}
        >
          <text style={{ fontSize: "26rpx", fontWeight: "700", color: "#202124" }}>Weekend Routes</text>
          <text style={{ fontSize: "22rpx", color: "#2D7D46" }}>3 picks</text>
        </scroll-coordinator-toolbar>

        {
          /*
          Required, it can be scrolled in scroll coordinator without affecting the layout,
          so it is recommended to set position: absolute.
          No need to place scroll-view or list inside.
        */
        }
        <scroll-coordinator-header
          style={{
            position: "absolute",
            width: "100%",
            height: "360rpx",
          }}
        >
          <view
            style={{
              width: "100%",
              height: "360rpx",
              overflow: "hidden",
            }}
          >
            <image
              mode="aspectFill"
              src={image0}
              style={{
                width: "100%",
                height: "360rpx",
              }}
            />
            <view
              style={{
                position: "absolute",
                left: "0",
                bottom: "0",
                width: "100%",
                padding: "24rpx",
                backgroundColor: "#00000066",
                boxSizing: "border-box",
              }}
            >
              <text style={{ fontSize: "34rpx", fontWeight: "700", color: "#FFFFFF" }}>Forest Ridge</text>
              <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#FFFFFF" }}>
                Sunrise views, shaded paths, and easy waypoints.
              </text>
            </view>
          </view>
        </scroll-coordinator-header>

        {
          /*
          Required, its size must be the same as scroll coordinator's size.
          If there is a toolbar, subtract its height.
          After the header is completely collapsed, the slot will occupy the entire scroll coordinator viewport.
          In its child nodes, scrolling can be achieved and can continue after the header is collapsed.
          When placing scroll-view, add enable-new-nested on scroll-view to support nested scrolling interactions.
        */
        }
        <scroll-coordinator-slot
          style={{
            width: "100%",
            flexDirection: "column",
            flex: "1",
            display: "flex",
          }}
        >
          {
            /*
            Optional sticky area. When the header is completely collapsed, it will stay at the top of the slot.
            You can place Tabs modules or any other content here.
            By default it accepts up and down dragging gestures. Use enable-drag to control it.
          */
          }
          <scroll-coordinator-slot-drag style={{ width: "100%" }}>
            <view
              style={{
                width: "100%",
                height: "96rpx",
                display: "flex",
                flexDirection: "row",
                alignItems: "center",
                padding: "0 16rpx",
                backgroundColor: "#FFFFFF",
                boxSizing: "border-box",
              }}
            >
              {tabs.map((tab, index) => {
                return (
                  <view
                    style={{
                      height: "56rpx",
                      padding: "0 20rpx",
                      marginRight: "12rpx",
                      justifyContent: "center",
                      borderRadius: "8px",
                      backgroundColor: index === 0 ? "#DDF3E5" : "#EEF1F4",
                    }}
                  >
                    <text style={{ fontSize: "22rpx", color: index === 0 ? "#1F7A4D" : "#4E5969" }}>{tab}</text>
                  </view>
                );
              })}
            </view>
          </scroll-coordinator-slot-drag>
          <list
            scroll-orientation="vertical"
            list-type="single"
            span-count={1}
            style={{
              width: "100%",
              height: "100%",
              flex: "1",
              listMainAxisGap: "12px",
              padding: "12px",
              boxSizing: "border-box",
            }}
          >
            {listItems.map((item) => {
              return (
                <list-item
                  item-key={item.title}
                  key={item.title}
                >
                  <view
                    style={{
                      width: "100%",
                      height: "144rpx",
                      display: "flex",
                      flexDirection: "row",
                      alignItems: "center",
                      padding: "12rpx",
                      borderRadius: "8px",
                      backgroundColor: "#FFFFFF",
                      boxSizing: "border-box",
                    }}
                  >
                    <image
                      mode="aspectFill"
                      src={item.image}
                      style={{
                        width: "120rpx",
                        height: "120rpx",
                        borderRadius: "8px",
                      }}
                    />
                    <view
                      style={{
                        marginLeft: "18rpx",
                        flex: 1,
                        flexDirection: "column",
                      }}
                    >
                      <text style={{ fontSize: "28rpx", fontWeight: "700", color: "#202124" }}>{item.title}</text>
                      <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#5F6673" }}>{item.subtitle}</text>
                      <text style={{ marginTop: "10rpx", fontSize: "20rpx", color: "#2D7D46" }}>{item.tag}</text>
                    </view>
                  </view>
                </list-item>
              );
            })}
          </list>
        </scroll-coordinator-slot>
      </scroll-coordinator>
    </view>
  );
};

root.render(<App />);

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

```

v0.7.1



### 内部横向分页滚动

> `<scroll-coordinator-slot>` 内部能够感知 `<viewpager>` 的页面切换事件，并与其中的 `<list>` 重新绑定嵌套滚动关系。
>
> ```tsx
> <scroll-coordinator class="coordinator">
>   <scroll-coordinator-header class="coordinator-header">
>     <Header />
>   </scroll-coordinator-header>
>   <scroll-coordinator-slot class="coordinator-slot">
>     <Tabs />
>     <viewpager>
>       <viewpager-item>
>         <list />
>       </viewpager-item>
>     </viewpager>
>   </scroll-coordinator-slot>
> </scroll-coordinator>
> ```

**下面是一个示例: scroll-coordinator**

**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, useState } from "@lynx-js/react";

import image0 from "../assets/item_0.jpg";
import image1 from "../assets/item_1.jpg";
import image2 from "../assets/item_2.jpg";

const App = () => {
  const [currentPage, setCurrentPage] = useState(0);
  const coverImages = [image0, image1, image2];
  const tabs = ["Featured", "Nearby", "Saved"];
  const listPages = ["A", "B", "C"];
  const listItems = Array.from({ length: 24 }, (_, index) => {
    return {
      image: coverImages[index % coverImages.length],
      title: `Scenic stop ${index + 1}`,
      subtitle: index % 2 === 0 ? "Quiet path with a wide lookout" : "Short trail near the water",
      tag: index % 3 === 0 ? "Fresh" : (index % 3 === 1 ? "Calm" : "Open"),
    };
  });

  return (
    <view
      style={{
        width: "100%",
        height: "100%",
        flexDirection: "column",
        display: "flex",
        padding: "24px",
        backgroundColor: "#F6F7F9",
        boxSizing: "border-box",
      }}
    >
      <text style={{ fontSize: "32px", fontWeight: "700", color: "#202124" }}>Scroll Coordinator</text>
      <scroll-coordinator
        style={{
          marginTop: "24px",
          width: "100%",
          height: "100%",
          flex: "1",
          display: "flex",
          flexDirection: "column",
          position: "relative",
          overflow: "hidden",
          backgroundColor: "#EDEFF2",
        }}
      >
        {
          /*
          Optional, fixed at the top of the scroll coordinator and won't collapse.
          When it exists, control scroll-coordinator.height == slot.height + toolbar.height through CSS.
          */
        }
        <scroll-coordinator-toolbar
          style={{
            display: "flex",
            width: "100%",
            height: "88rpx",
            alignItems: "center",
            justifyContent: "space-between",
            padding: "0 24rpx",
            backgroundColor: "#FFFFFFAA",
            boxSizing: "border-box",
          }}
        >
          <text style={{ fontSize: "26rpx", fontWeight: "700", color: "#202124" }}>Weekend Routes</text>
          <text style={{ fontSize: "22rpx", color: "#2D7D46" }}>3 lists</text>
        </scroll-coordinator-toolbar>

        {
          /*
          Required, it can be scrolled in scroll coordinator without affecting the layout,
          so it is recommended to set position: absolute.
          No need to place scroll-view or list inside.
        */
        }
        <scroll-coordinator-header
          style={{
            position: "absolute",
            width: "100%",
            height: "360rpx",
          }}
        >
          <view
            style={{
              width: "100%",
              height: "360rpx",
              overflow: "hidden",
            }}
          >
            <image
              mode="aspectFill"
              src={image0}
              style={{
                width: "100%",
                height: "360rpx",
              }}
            />
            <view
              style={{
                position: "absolute",
                left: "0",
                bottom: "0",
                width: "100%",
                padding: "24rpx",
                backgroundColor: "#00000066",
                boxSizing: "border-box",
              }}
            >
              <text style={{ fontSize: "34rpx", fontWeight: "700", color: "#FFFFFF" }}>Forest Ridge</text>
              <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#FFFFFF" }}>
                Sunrise views, shaded paths, and easy waypoints.
              </text>
            </view>
          </view>
        </scroll-coordinator-header>

        {
          /*
          Required, its size must be the same as scroll coordinator's size.
          If there is a toolbar, subtract its height.
          After the header is completely collapsed, the slot will occupy the entire scroll coordinator viewport.
          In its child nodes, scrolling can be achieved and can continue after the header is collapsed.
          When placing scroll-view, add enable-new-nested on scroll-view to support nested scrolling interactions.
        */
        }
        <scroll-coordinator-slot
          style={{
            width: "100%",
            flexDirection: "column",
            flex: "1",
            display: "flex",
          }}
        >
          {
            /*
            Optional sticky area. When the header is completely collapsed, it will stay at the top of the slot.
            You can place Tabs modules or any other content here.
            By default it accepts up and down dragging gestures. Use enable-drag to control it.
          */
          }
          <scroll-coordinator-slot-drag style={{ width: "100%" }}>
            <view
              style={{
                width: "100%",
                height: "96rpx",
                display: "flex",
                flexDirection: "row",
                alignItems: "center",
                padding: "0 16rpx",
                backgroundColor: "#FFFFFF",
                boxSizing: "border-box",
              }}
            >
              {tabs.map((tab, index) => {
                const selected = currentPage === index;

                return (
                  <view
                    style={{
                      height: "56rpx",
                      padding: "0 20rpx",
                      marginRight: "12rpx",
                      justifyContent: "center",
                      borderRadius: "8px",
                      backgroundColor: selected ? "#DDF3E5" : "#EEF1F4",
                    }}
                  >
                    <text
                      style={{
                        fontSize: "22rpx",
                        fontWeight: selected ? "700" : "400",
                        color: selected ? "#1F7A4D" : "#4E5969",
                      }}
                    >
                      {tab}
                    </text>
                  </view>
                );
              })}
            </view>
          </scroll-coordinator-slot-drag>
          <viewpager
            style={{
              width: "100%",
              height: "100%",
              flex: "1",
              display: "flex",
              flexDirection: "row",
            }}
            bindwillchange={(e) => {
              setCurrentPage(e.detail.index);
            }}
          >
            {listPages.map((page) => {
              return (
                <viewpager-item
                  style={{
                    width: "100%",
                    height: "100%",
                    flexShrink: 0,
                  }}
                >
                  <list
                    scroll-orientation="vertical"
                    list-type="single"
                    span-count={1}
                    style={{
                      width: "100%",
                      height: "100%",
                      listMainAxisGap: "12px",
                      padding: "12px",
                      boxSizing: "border-box",
                    }}
                  >
                    {listItems.map((item, index) => {
                      return (
                        <list-item
                          item-key={`list-${page}-item-${index}`}
                          key={`list-${page}-item-${index}`}
                        >
                          <view
                            style={{
                              width: "100%",
                              height: "144rpx",
                              display: "flex",
                              flexDirection: "row",
                              alignItems: "center",
                              padding: "12rpx",
                              borderRadius: "8px",
                              backgroundColor: "#FFFFFF",
                              boxSizing: "border-box",
                            }}
                          >
                            <image
                              mode="aspectFill"
                              src={item.image}
                              style={{
                                width: "120rpx",
                                height: "120rpx",
                                borderRadius: "8px",
                              }}
                            />
                            <view
                              style={{
                                marginLeft: "18rpx",
                                flex: 1,
                                flexDirection: "column",
                              }}
                            >
                              <text style={{ fontSize: "28rpx", fontWeight: "700", color: "#202124" }}>
                                {`${item.title} ${page}`}
                              </text>
                              <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#5F6673" }}>
                                {item.subtitle}
                              </text>
                              <text style={{ marginTop: "10rpx", fontSize: "20rpx", color: "#2D7D46" }}>
                                {item.tag}
                              </text>
                            </view>
                          </view>
                        </list-item>
                      );
                    })}
                  </list>
                </viewpager-item>
              );
            })}
          </viewpager>
        </scroll-coordinator-slot>
      </scroll-coordinator>
    </view>
  );
};

root.render(<App />);

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

```

v0.7.1



### 整体下拉刷新

> 用`<refresh>`对`<scroll-coordinator>`进行包裹，并指定`refresh-mode="fold" bounces={true}`，构建页面级别的下拉刷新效果
>
> ```tsx
> <refresh>
>   <refresh-header>
>     <Loading />
>   </refresh-header>
>   <scroll-coordinator class="coordinator" bounces={true} refresh-mode="fold">
>     <scroll-coordinator-header class="coordinator-header">
>       <Header />
>     </scroll-coordinator-header>
>     <scroll-coordinator-slot class="coordinator-slot">
>       <viewpager>
>         <viewpager-item>
>           <list />
>         </viewpager-item>
>       </viewpager>
>     </scroll-coordinator-slot>
>   </scroll-coordinator>
> </refresh>
> ```

**下面是一个示例: scroll-coordinator**

**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";

import loadingGif from "../assets/bg_flower.gif";
import image0 from "../assets/item_0.jpg";
import image1 from "../assets/item_1.jpg";
import image2 from "../assets/item_2.jpg";

const App = () => {
  const refreshRef = useRef<NodesRef>(null);
  const [currentPage, setCurrentPage] = useState(0);
  const coverImages = [image0, image1, image2];
  const tabs = ["Featured", "Nearby", "Saved"];
  const listPages = ["A", "B", "C"];
  const listItems = Array.from({ length: 24 }, (_, index) => {
    return {
      image: coverImages[index % coverImages.length],
      title: `Scenic stop ${index + 1}`,
      subtitle: index % 2 === 0 ? "Quiet path with a wide lookout" : "Short trail near the water",
      tag: index % 3 === 0 ? "Fresh" : (index % 3 === 1 ? "Calm" : "Open"),
    };
  });

  const onStartRefresh = () => {
    setTimeout(() => {
      refreshRef.current?.invoke({
        method: "finishRefresh",
      }).exec();
    }, 2000);
  };

  return (
    <view
      style={{
        width: "100%",
        height: "100%",
        flexDirection: "column",
        display: "flex",
        padding: "24px",
        backgroundColor: "#F6F7F9",
        boxSizing: "border-box",
      }}
    >
      <text style={{ fontSize: "32px", fontWeight: "700", color: "#202124" }}>Scroll Coordinator</text>
      <refresh
        ref={refreshRef}
        bindstartrefresh={onStartRefresh}
        style={{
          marginTop: "24px",
          width: "100%",
          height: "100%",
          flex: "1",
        }}
      >
        <refresh-header
          style={{
            width: "100%",
            height: "104rpx",
            position: "absolute",
            justifyContent: "center",
            alignItems: "center",
            backgroundColor: "#F6F7F9",
          }}
        >
          <image
            mode="aspectFit"
            src={loadingGif}
            style={{
              width: "48rpx",
              height: "48rpx",
            }}
          />
          <text style={{ marginTop: "8rpx", fontSize: "20rpx", color: "#4E5969" }}>Refreshing routes...</text>
        </refresh-header>
        <scroll-coordinator
          refresh-mode="fold"
          style={{
            width: "100%",
            height: "100%",
            flex: "1",
            display: "flex",
            flexDirection: "column",
            position: "relative",
            overflow: "hidden",
            backgroundColor: "#EDEFF2",
          }}
        >
          {
            /*
          Required, it can be scrolled in scroll coordinator without affecting the layout,
          so it is recommended to set position: absolute.
          No need to place scroll-view or list inside.
        */
          }
          <scroll-coordinator-header
            style={{
              position: "absolute",
              width: "100%",
              height: "360rpx",
            }}
          >
            <view
              style={{
                width: "100%",
                height: "360rpx",
                overflow: "hidden",
              }}
            >
              <image
                mode="aspectFill"
                src={image0}
                style={{
                  width: "100%",
                  height: "360rpx",
                }}
              />
              <view
                style={{
                  position: "absolute",
                  left: "0",
                  bottom: "0",
                  width: "100%",
                  padding: "24rpx",
                  backgroundColor: "#00000066",
                  boxSizing: "border-box",
                }}
              >
                <text style={{ fontSize: "34rpx", fontWeight: "700", color: "#FFFFFF" }}>Forest Ridge</text>
                <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#FFFFFF" }}>
                  Sunrise views, shaded paths, and easy waypoints.
                </text>
              </view>
            </view>
          </scroll-coordinator-header>

          {
            /*
          Required, its size must be the same as scroll coordinator's size.
          If there is a toolbar, subtract its height.
          After the header is completely collapsed, the slot will occupy the entire scroll coordinator viewport.
          In its child nodes, scrolling can be achieved and can continue after the header is collapsed.
          When placing scroll-view, add enable-new-nested on scroll-view to support nested scrolling interactions.
        */
          }
          <scroll-coordinator-slot
            style={{
              width: "100%",
              flexDirection: "column",
              flex: "1",
              display: "flex",
            }}
          >
            {
              /*
            Optional sticky area. When the header is completely collapsed, it will stay at the top of the slot.
            You can place Tabs modules or any other content here.
            By default it accepts up and down dragging gestures. Use enable-drag to control it.
          */
            }
            <scroll-coordinator-slot-drag style={{ width: "100%" }}>
              <view
                style={{
                  width: "100%",
                  height: "96rpx",
                  display: "flex",
                  flexDirection: "row",
                  alignItems: "center",
                  padding: "0 16rpx",
                  backgroundColor: "#FFFFFF",
                  boxSizing: "border-box",
                }}
              >
                {tabs.map((tab, index) => {
                  const selected = currentPage === index;

                  return (
                    <view
                      style={{
                        height: "56rpx",
                        padding: "0 20rpx",
                        marginRight: "12rpx",
                        justifyContent: "center",
                        borderRadius: "8px",
                        backgroundColor: selected ? "#DDF3E5" : "#EEF1F4",
                      }}
                    >
                      <text
                        style={{
                          fontSize: "22rpx",
                          fontWeight: selected ? "700" : "400",
                          color: selected ? "#1F7A4D" : "#4E5969",
                        }}
                      >
                        {tab}
                      </text>
                    </view>
                  );
                })}
              </view>
            </scroll-coordinator-slot-drag>
            <viewpager
              style={{
                width: "100%",
                height: "100%",
                flex: "1",
                display: "flex",
                flexDirection: "row",
              }}
              bindwillchange={(e) => {
                setCurrentPage(e.detail.index);
              }}
            >
              {listPages.map((page) => {
                return (
                  <viewpager-item
                    style={{
                      width: "100%",
                      height: "100%",
                      flexShrink: 0,
                    }}
                  >
                    <list
                      scroll-orientation="vertical"
                      list-type="single"
                      span-count={1}
                      style={{
                        width: "100%",
                        height: "100%",
                        listMainAxisGap: "12px",
                        padding: "12px",
                        boxSizing: "border-box",
                      }}
                    >
                      {listItems.map((item, index) => {
                        return (
                          <list-item
                            item-key={`list-${page}-item-${index}`}
                            key={`list-${page}-item-${index}`}
                          >
                            <view
                              style={{
                                width: "100%",
                                height: "144rpx",
                                display: "flex",
                                flexDirection: "row",
                                alignItems: "center",
                                padding: "12rpx",
                                borderRadius: "8px",
                                backgroundColor: "#FFFFFF",
                                boxSizing: "border-box",
                              }}
                            >
                              <image
                                mode="aspectFill"
                                src={item.image}
                                style={{
                                  width: "120rpx",
                                  height: "120rpx",
                                  borderRadius: "8px",
                                }}
                              />
                              <view
                                style={{
                                  marginLeft: "18rpx",
                                  flex: 1,
                                  flexDirection: "column",
                                }}
                              >
                                <text style={{ fontSize: "28rpx", fontWeight: "700", color: "#202124" }}>
                                  {`${item.title} ${page}`}
                                </text>
                                <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#5F6673" }}>
                                  {item.subtitle}
                                </text>
                                <text style={{ marginTop: "10rpx", fontSize: "20rpx", color: "#2D7D46" }}>
                                  {item.tag}
                                </text>
                              </view>
                            </view>
                          </list-item>
                        );
                      })}
                    </list>
                  </viewpager-item>
                );
              })}
            </viewpager>
          </scroll-coordinator-slot>
        </scroll-coordinator>
      </refresh>
    </view>
  );
};

root.render(<App />);

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

```

v0.7.1



### 局部下拉刷新

> 用`<refresh>`对`<scroll-coordinator-slot>`内的`<list>`进行包裹，并指定`refresh-mode="page" bounces={false}`，构建局部下拉刷新效果
>
> ```tsx
> <scroll-coordinator class="coordinator" bounces={false} refresh-mode="page">
>   <scroll-coordinator-header class="coordinator-header">
>     <Header />
>   </scroll-coordinator-header>
>   <scroll-coordinator-slot class="coordinator-slot">
>     <viewpager>
>       <viewpager-item>
>         <refresh>
>           <refresh-header />
>           <list />
>         </refresh>
>       </viewpager-item>
>     </viewpager>
>   </scroll-coordinator-slot>
> </scroll-coordinator>
> ```

**下面是一个示例: scroll-coordinator**

**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";

import loadingGif from "../assets/bg_flower.gif";
import image0 from "../assets/item_0.jpg";
import image1 from "../assets/item_1.jpg";
import image2 from "../assets/item_2.jpg";

const App = () => {
  const refreshRefs = useRef<Record<string, NodesRef | null>>({});
  const [currentPage, setCurrentPage] = useState(0);
  const coverImages = [image0, image1, image2];
  const tabs = ["Featured", "Nearby", "Saved"];
  const listPages = ["A", "B", "C"];
  const listItems = Array.from({ length: 24 }, (_, index) => {
    return {
      image: coverImages[index % coverImages.length],
      title: `Scenic stop ${index + 1}`,
      subtitle: index % 2 === 0 ? "Quiet path with a wide lookout" : "Short trail near the water",
      tag: index % 3 === 0 ? "Fresh" : (index % 3 === 1 ? "Calm" : "Open"),
    };
  });

  const onStartRefresh = (page: string) => {
    setTimeout(() => {
      refreshRefs.current[page]?.invoke({
        method: "finishRefresh",
      }).exec();
    }, 2000);
  };

  return (
    <view
      style={{
        width: "100%",
        height: "100%",
        flexDirection: "column",
        display: "flex",
        padding: "24px",
        backgroundColor: "#F6F7F9",
        boxSizing: "border-box",
      }}
    >
      <text style={{ fontSize: "32px", fontWeight: "700", color: "#202124" }}>Scroll Coordinator</text>
      <scroll-coordinator
        bounces={false}
        refresh-mode="page"
        style={{
          marginTop: "24px",
          width: "100%",
          height: "100%",
          flex: "1",
          display: "flex",
          flexDirection: "column",
          position: "relative",
          overflow: "hidden",
          backgroundColor: "#EDEFF2",
        }}
      >
        {
          /*
          Required, it can be scrolled in scroll coordinator without affecting the layout,
          so it is recommended to set position: absolute.
          No need to place scroll-view or list inside.
        */
        }
        <scroll-coordinator-header
          style={{
            position: "absolute",
            width: "100%",
            height: "360rpx",
          }}
        >
          <view
            style={{
              width: "100%",
              height: "360rpx",
              overflow: "hidden",
            }}
          >
            <image
              mode="aspectFill"
              src={image0}
              style={{
                width: "100%",
                height: "360rpx",
              }}
            />
            <view
              style={{
                position: "absolute",
                left: "0",
                bottom: "0",
                width: "100%",
                padding: "24rpx",
                backgroundColor: "#00000066",
                boxSizing: "border-box",
              }}
            >
              <text style={{ fontSize: "34rpx", fontWeight: "700", color: "#FFFFFF" }}>Forest Ridge</text>
              <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#FFFFFF" }}>
                Sunrise views, shaded paths, and easy waypoints.
              </text>
            </view>
          </view>
        </scroll-coordinator-header>

        {
          /*
          Required, its size must be the same as scroll coordinator's size.
          If there is a toolbar, subtract its height.
          After the header is completely collapsed, the slot will occupy the entire scroll coordinator viewport.
          In its child nodes, scrolling can be achieved and can continue after the header is collapsed.
          When placing scroll-view, add enable-new-nested on scroll-view to support nested scrolling interactions.
        */
        }
        <scroll-coordinator-slot
          style={{
            width: "100%",
            flexDirection: "column",
            flex: "1",
            display: "flex",
          }}
        >
          {
            /*
            Optional sticky area. When the header is completely collapsed, it will stay at the top of the slot.
            You can place Tabs modules or any other content here.
            By default it accepts up and down dragging gestures. Use enable-drag to control it.
          */
          }
          <scroll-coordinator-slot-drag style={{ width: "100%" }}>
            <view
              style={{
                width: "100%",
                height: "96rpx",
                display: "flex",
                flexDirection: "row",
                alignItems: "center",
                padding: "0 16rpx",
                backgroundColor: "#FFFFFF",
                boxSizing: "border-box",
              }}
            >
              {tabs.map((tab, index) => {
                const selected = currentPage === index;

                return (
                  <view
                    style={{
                      height: "56rpx",
                      padding: "0 20rpx",
                      marginRight: "12rpx",
                      justifyContent: "center",
                      borderRadius: "8px",
                      backgroundColor: selected ? "#DDF3E5" : "#EEF1F4",
                    }}
                  >
                    <text
                      style={{
                        fontSize: "22rpx",
                        fontWeight: selected ? "700" : "400",
                        color: selected ? "#1F7A4D" : "#4E5969",
                      }}
                    >
                      {tab}
                    </text>
                  </view>
                );
              })}
            </view>
          </scroll-coordinator-slot-drag>
          <viewpager
            style={{
              width: "100%",
              height: "100%",
              flex: "1",
              display: "flex",
              flexDirection: "row",
            }}
            bindwillchange={(e) => {
              setCurrentPage(e.detail.index);
            }}
          >
            {listPages.map((page) => {
              return (
                <viewpager-item
                  style={{
                    width: "100%",
                    height: "100%",
                    flexShrink: 0,
                  }}
                >
                  <refresh
                    ref={(element: NodesRef | null) => {
                      refreshRefs.current[page] = element;
                    }}
                    bindstartrefresh={() => {
                      onStartRefresh(page);
                    }}
                    style={{
                      width: "100%",
                      height: "100%",
                    }}
                  >
                    <refresh-header
                      style={{
                        width: "100%",
                        height: "104rpx",
                        position: "absolute",
                        justifyContent: "center",
                        alignItems: "center",
                        backgroundColor: "#F6F7F9",
                      }}
                    >
                      <image
                        mode="aspectFit"
                        src={loadingGif}
                        style={{
                          width: "48rpx",
                          height: "48rpx",
                        }}
                      />
                      <text style={{ marginTop: "8rpx", fontSize: "20rpx", color: "#4E5969" }}>
                        Refreshing routes...
                      </text>
                    </refresh-header>
                    <list
                      scroll-orientation="vertical"
                      list-type="single"
                      span-count={1}
                      style={{
                        width: "100%",
                        height: "100%",
                        listMainAxisGap: "12px",
                        padding: "12px",
                        boxSizing: "border-box",
                      }}
                    >
                      {listItems.map((item, index) => {
                        return (
                          <list-item
                            item-key={`list-${page}-item-${index}`}
                            key={`list-${page}-item-${index}`}
                          >
                            <view
                              style={{
                                width: "100%",
                                height: "144rpx",
                                display: "flex",
                                flexDirection: "row",
                                alignItems: "center",
                                padding: "12rpx",
                                borderRadius: "8px",
                                backgroundColor: "#FFFFFF",
                                boxSizing: "border-box",
                              }}
                            >
                              <image
                                mode="aspectFill"
                                src={item.image}
                                style={{
                                  width: "120rpx",
                                  height: "120rpx",
                                  borderRadius: "8px",
                                }}
                              />
                              <view
                                style={{
                                  marginLeft: "18rpx",
                                  flex: 1,
                                  flexDirection: "column",
                                }}
                              >
                                <text style={{ fontSize: "28rpx", fontWeight: "700", color: "#202124" }}>
                                  {`${item.title} ${page}`}
                                </text>
                                <text style={{ marginTop: "8rpx", fontSize: "22rpx", color: "#5F6673" }}>
                                  {item.subtitle}
                                </text>
                                <text style={{ marginTop: "10rpx", fontSize: "20rpx", color: "#2D7D46" }}>
                                  {item.tag}
                                </text>
                              </view>
                            </view>
                          </list-item>
                        );
                      })}
                    </list>
                  </refresh>
                </viewpager-item>
              );
            })}
          </viewpager>
        </scroll-coordinator-slot>
      </scroll-coordinator>
    </view>
  );
};

root.render(<App />);

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

```

v0.7.1



## 属性

### `android-nested-scroll-as-child`

Android
```tsx
// @默认值: false
'android-nested-scroll-as-child'?: boolean;
```

Android foldview 基于 CoordinateLayout，但它仅实现了 NestedScrollingParent，因此不支持作为子组件嵌套在其他滚动组件中，将此属性设置为 true 可使其正常工作。

### `bounces`

iOS
Harmony
```tsx
// @默认值: true
bounces?: boolean;
```

当 coordinator 滚动超出边界时启用回弹效果。

### `enable-scroll`

Android
iOS
Harmony
Clay Android
Clay iOS
```tsx
// @默认值: true
'enable-scroll'?: boolean;
```

设置 coordinator 是否可以垂直滚动。

### `enable-scroll-bar`

iOS
Harmony
```tsx
// @默认值: false
'enable-scroll-bar'?: boolean;
```

设置 coordinator 滚动时滚动条是否可见。

### `granularity`

Android
iOS
Harmony
Clay Android
Clay iOS
```tsx
// @默认值: 0.01
granularity?: number;
```

bindoffset 的事件响应粒度，一旦滚动距离超过可滚动距离的 granularity 倍，即可能触发。默认值为 0.01，但不一定每 0.01 都会触发。

### `header-over-slot`

Android
iOS
Harmony
Clay Android
Clay iOS
```tsx
// @默认值: false
'header-over-slot'?: boolean;
```

此属性控制 header 层级是否高于 slot，当 header 溢出时，将显示在 slot 之上。否则，将显示在 slot 之下。建议显式设置此属性，而不是使用默认值。

### `ios-force-scroll-detach`

iOS
```tsx
// @默认值: false
'ios-force-scroll-detach'?: boolean;
```

是否强制使 foldview 的 nested-vertical-scroll-behavior 在 iOS 上失效，此设置对其他平台无效。

### `ios-scrolls-to-top`

iOS
```tsx
// @默认值: false
'ios-scrolls-to-top'?: boolean;
```

当用户点击状态栏时，距离状态栏最近的触摸下方的滚动视图将滚动到顶部。仅限 iOS 功能。

### `refresh-mode`

iOS
```tsx
// @默认值: 'none'
'refresh-mode'?: 'page' | 'none' | 'fold';
```

foldview 的下拉刷新模式，none（无，默认值）、page（分类下拉刷新）、fold（整体下拉刷新）。

## 事件

前端可以绑定相应的事件回调来监听元素的运行时行为，如下所示。

### `bindoffset`

Android
iOS
Harmony
Clay Android
Clay iOS
```tsx
bindoffset = (e: ScrollCoordinatorOffsetEvent) => {};
```

| 字段 | 类型 | 是否可选 | 默认值 | 平台 | 版本 | 描述 |
| --- | --- | --- | --- | --- | --- | --- |
| height | 数字 | 否 | – | Android iOS Harmony Clay Android Clay iOS |  | 可滚动距离的绝对值（header 高度 - toolbar 高度），单位为 px |
| offset | 数字 | 否 | – | Android iOS Harmony Clay Android Clay iOS |  | header 滚动偏移量的绝对值，单位为 px |

折叠进度回调

## 方法

前端可以通过 [SelectorQuery](/next/zh/api/lynx-api/nodes-ref/nodes-ref-invoke.md) API 调用组件方法。

### `setFoldExpanded`

```ts

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'setFoldExpanded',
      params: {
        /**
         * 偏移量，支持 px 和 rpx
         * @Android
         * @iOS
         * @Harmony
         * @Web
         * @PC
         */
        offset: '0px',
        /**
         * 折叠时是否需要动画
         * @Android
         * @iOS
         * @Harmony
         * @Web
         * @PC
         */
        smooth: true,
      },
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

```

## 兼容性

**Compatibility Table**

**Query:** `elements.scroll-coordinator`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| scroll-coordinator | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes |
| attributes | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Partial |
| attributes.ios-scrolls-to-top | No | No | Yes (3.9) | No | No | No |
| attributes.header-over-slot | Yes (3.9) | Yes (3.9) | Yes (3.9) | No | No | Yes |
| attributes.enable-scroll | Yes (3.9) | Yes (3.9) | Yes (3.9) | No | No | No |
| attributes.bounces | No | Yes (3.9) | Yes (3.9) | No | No | No |
| attributes.enable-scroll-bar | No | Yes (3.9) | Yes (3.9) | No | No | No |
| attributes.android-nested-scroll-as-child | Yes (3.9) | No | No | No | No | No |
| attributes.ios-force-scroll-detach | No | No | Yes (3.9) | No | No | No |
| attributes.granularity | Yes (3.9) | Yes (3.9) | Yes (3.9) | No | No | Yes |
| attributes.refresh-mode | No | No | Yes (3.9) | No | No | No |
| attributes.enable-drag | Yes (3.9) | No | Yes (3.9) | No | No | No |
| events | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes |
| events.bindoffset | Yes (3.9) | Yes (3.9) | Yes (3.9) | No | No | Yes |
| methods | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes (3.9) | Yes |
| methods.setFoldExpanded | Yes (3.9) | Yes (3.9) | Yes (3.9) | No | No | Yes |
| methods.boundingClientRect | Yes (3.9) | Yes (4.0) | Yes (4.0) | No | No | Yes |
| methods.requestAccessibilityFocus | Yes (3.9) | No | Yes (4.0) | No | No | No |
| methods.scrollIntoView | Yes (4.0) | Yes (4.0) | Yes (4.0) | No | No | Yes |
| methods.setFocus | No | No | No | No | No | No |
| methods.takeScreenshot | Yes (4.0) | Yes (4.0) | Yes (4.0) | No | No | No |

**`scroll-coordinator`**

scroll-coordinator

**`attributes`**

attributes

- **Web — Supported (version unknown):** Partial support; Supports header-over-slot and granularity. Web scroll controls use scroll-enable and scroll-bar-enable instead of enable-scroll and enable-scroll-bar.

**`attributes.ios-scrolls-to-top`**

<code>ios-scrolls-to-top</code>

**`attributes.header-over-slot`**

<code>header-over-slot</code>

**`attributes.enable-scroll`**

<code>enable-scroll</code>

**`attributes.bounces`**

<code>bounces</code>

**`attributes.enable-scroll-bar`**

<code>enable-scroll-bar</code>

**`attributes.android-nested-scroll-as-child`**

<code>android-nested-scroll-as-child</code>

**`attributes.ios-force-scroll-detach`**

<code>ios-force-scroll-detach</code>

**`attributes.granularity`**

<code>granularity</code>

**`attributes.refresh-mode`**

<code>refresh-mode</code>

**`attributes.enable-drag`**

<code>enable-drag</code>

**`events`**

events

**`events.bindoffset`**

<code>bindoffset</code>

**`methods`**

methods

**`methods.setFoldExpanded`**

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

