@animatereactnative/accordion

中文文档
0.1.5发布于 2025/01/23MITTypeScriptESM + CJS零依赖近 30 天下载 1850

A React Native Accordion component, powered by React Native Reanimated layout animation that's capable of rendering and animating content that has a dynamic height.

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Props
  4. Contributing
  5. License

React Native Accordion component, a cross-platform accordion component, powered by Reanimated, that's capable of displaying dynamic height content and animate the layout changes/transitions between Collapsable and Expandable states.

If you are going to use this component along with other components (as siblings), it is recommended to use Accordion.Sibling and wrap the Siblings with it. This is because the exposed Sibling component will use Layout animations as well so there are no layout shifts or sudden movements, keeping everything smooth.

  • 🔋 Powered by Reanimated
  • 📱 Works with Expo
  • ✅ Cross-platform (iOS, Android, Web - wip)
  • ⚡️ 60-120fps
  • 🪝 Works with any React Native element/component
  • 🎼 Composition ready
  • ⌨️ Written in TypeScript

Installation

npm install @animatereactnative/accordion

Also, you need to install react-native-reanimated, and follow their installation instructions.

Usage

import { Accordion } from '@animatereactnative/accordion';

// ...

export function Example() {
  return (
    <Accordion.Accordion>
      <Accordion.Header>
        <Text>AnimateReactNative.com</Text>
        <Accordion.HeaderIcon>
          <ChevronUp />
        </Accordion.HeaderIcon>
      </Accordion.Header>

      <Accordion.Collapsed>
        <Text>Visible !expanded</Text>
      </Accordion.Collapsed>
      <Accordion.Always>
        <Text>Always visible</Text>
      </Accordion.Always>

      <Accordion.Expanded>
        <Text>Expanded content</Text>
        {loading && <ActivityIndicator />}
        {data & <MyList data={data} />}
      </Accordion.Expanded>
    </Accordion.Accordion>
  );
}

Props

Accordion = {
  /**
   * The main component that will handle the state of the accordion.
   *
   * @param isOpen boolean
   * @param onChange (value: boolean) => void
   */
  Accordion
  /**
   * The header of the accordion.
   */
  Header,
  /**
   * The component that will wrap any children and it will apply a rotation to it.
   *
   * @param children
   * @param rotation clockwise | counter-clockwise
   */
  HeaderIcon
  /**
   * This is the content that will be displayed when the accordion is open
   */
  Expanded,
  /**
   * This is the content that will be displayed when the accordion is closed
   */
  Collapsed,
  /**
   * This is the content that will always be displayed
   */
  Always,
  /**
   *
   * This is a component that will add the layout transition to any
   * sibling components. Useful when you are rendering other components
   * that are not direct children of the Accordion component.
   */
  Sibling,
};

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


AnimateReactNative.com - Premium and Custom React Native animations.

版本与发布记录

@animatereactnative/accordion 共发布 6 个版本,首次发布于 2024/11/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.5latest2025/01/231.8 年前
0.1.42025/01/231.8 年前
0.1.32025/01/231.8 年前
0.1.22025/01/231.8 年前
0.1.12024/11/202 年前
0.1.02024/11/202 年前

关于 @animatereactnative/accordion 的常见问题

@animatereactnative/accordion 是什么?

A React Native Accordion component, powered by React Native Reanimated layout animation that's capable of rendering and animating content that has a dynamic height.

如何安装 @animatereactnative/accordion?

在项目目录运行 npm install @animatereactnative/accordion,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)、react-native-reanimated(>=2.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@animatereactnative/accordion 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@animatereactnative/accordion 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@animatereactnative/accordion 可以商用吗?

@animatereactnative/accordion 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@animatereactnative/accordion 的下载量有多少?

根据 npm 官方下载统计,@animatereactnative/accordion 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,850 次,日均约 62 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@animatereactnative/accordion 还在维护吗?

最新版本 0.1.5 发布于 2025/01/23(1.8 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/11/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。