{"id":3962,"url":"https://github.com/oblador/react-native-collapsible","last_synced_at":"2025-05-13T21:09:00.142Z","repository":{"id":33372918,"uuid":"37017815","full_name":"oblador/react-native-collapsible","owner":"oblador","description":"Animated collapsible component for React Native, good for accordions, toggles etc","archived":false,"fork":false,"pushed_at":"2024-08-27T20:12:04.000Z","size":1217,"stargazers_count":2530,"open_issues_count":95,"forks_count":452,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-27T18:02:06.951Z","etag":null,"topics":["accordion","animation","collapsible","react-native"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oblador.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.MD","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["oblador"]}},"created_at":"2015-06-07T13:36:23.000Z","updated_at":"2025-04-26T11:37:06.000Z","dependencies_parsed_at":"2025-01-21T03:02:06.544Z","dependency_job_id":"2d8e97f6-288a-4548-b700-f6b953da7236","html_url":"https://github.com/oblador/react-native-collapsible","commit_stats":{"total_commits":203,"total_committers":44,"mean_commits":4.613636363636363,"dds":0.5960591133004927,"last_synced_commit":"2bd7f8d50c2f3d876119bc65da8e7681c38563ad"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oblador%2Freact-native-collapsible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oblador%2Freact-native-collapsible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oblador%2Freact-native-collapsible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oblador%2Freact-native-collapsible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oblador","download_url":"https://codeload.github.com/oblador/react-native-collapsible/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219600,"owners_count":21554444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accordion","animation","collapsible","react-native"],"created_at":"2024-01-05T20:16:56.661Z","updated_at":"2025-04-28T12:06:11.816Z","avatar_url":"https://github.com/oblador.png","language":"JavaScript","funding_links":["https://github.com/sponsors/oblador"],"categories":["Components","JavaScript","组件","Libraries","Others"],"sub_categories":["UI","Collapsable"],"readme":"# react-native-collapsible\n\n_Animated collapsible component for React Native using the Animated API_\n\nPure JavaScript, supports dynamic content heights and components that is aware of its `collapsed` state (good for toggling arrows etc).\n\n## Installation\n\n```bash\nnpm install --save react-native-collapsible\n```\n\n## Collapsible Usage\n\n```js\nimport Collapsible from 'react-native-collapsible';\n\n() =\u003e (\n  \u003cCollapsible collapsed={isCollapsed}\u003e\n    \u003cSomeCollapsedView /\u003e\n  \u003c/Collapsible\u003e\n);\n```\n\n## Properties\n\n| Prop                          | Description                                                                                                                                                                                                                                                                                                             | Default        |\n| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |\n| **`align`**                   | Alignment of the content when transitioning, can be `top`, `center` or `bottom`                                                                                                                                                                                                                                         | `top`          |\n| **`collapsed`**               | Whether to show the child components or not                                                                                                                                                                                                                                                                             | `true`         |\n| **`collapsedHeight`**         | Which height should the component collapse to                                                                                                                                                                                                                                                                           | `0`            |\n| **`enablePointerEvents`**     | Enable pointer events on collapsed view                                                                                                                                                                                                                                                                                 | `false`        |\n| **`duration`**                | Duration of transition in milliseconds                                                                                                                                                                                                                                                                                  | `300`          |\n| **`easing`**                  | Function or function name from [`Easing`](https://github.com/facebook/react-native/blob/master/Libraries/Animated/src/Easing.js) (or [`tween-functions`](https://github.com/chenglou/tween-functions) if \u003c RN 0.8). Collapsible will try to combine `Easing` functions for you if you name them like `tween-functions`. | `easeOutCubic` |\n| **`renderChildrenCollapsed`** | Render children in collapsible even if not visible.                                                                                                                                                                                                                                                                     | `true`         |\n| **`style`**                   | Optional styling for the container                                                                                                                                                                                                                                                                                      |                |\n| **`onAnimationEnd`**          | Callback when the toggle animation is done. Useful to avoid heavy layouting work during the animation                                                                                                                                                                                                                   | `() =\u003e {}`     |\n\n## Accordion Usage\n\nThis is a convenience component for a common use case, see demo below.\n\n```js\nimport Accordion from 'react-native-collapsible/Accordion';\n\n() =\u003e (\n  \u003cAccordion\n    activeSections={[0]}\n    sections={['Section 1', 'Section 2', 'Section 3']}\n    renderSectionTitle={this._renderSectionTitle}\n    renderHeader={this._renderHeader}\n    renderContent={this._renderContent}\n    onChange={this._updateSections}\n  /\u003e\n);\n```\n\n## Properties\n\n| Prop                                                    | Description                                                                                                    |\n| ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |\n| **`sections`**                                          | An array of sections passed to the render methods                                                              |\n| **`renderHeader(content, index, isActive, sections)`**  | A function that should return a renderable representing the header                                             |\n| **`renderContent(content, index, isActive, sections)`** | A function that should return a renderable representing the content                                            |\n| **`renderFooter(content, index, isActive, sections)`**  | A function that should return a renderable representing the footer                                             |\n| **`renderSectionTitle(content, index, isActive)`**      | A function that should return a renderable representing the title of the section outside the touchable element |\n| **`onChange(indexes)`**                                 | A function that is called when the currently active section(s) are updated.                                    |\n| **`keyExtractor(item, index)`**                         | Used to extract a unique key for a given item at the specified index.                                          |\n| **`activeSections`**                                    | Control which indices in the `sections` array are currently open. If empty, closes all sections.               |\n| **`underlayColor`**                                     | The color of the underlay that will show through when tapping on headers. Defaults to black.                   |\n| **`touchableComponent`**                                | The touchable component used in the Accordion. Defaults to `TouchableHighlight`                                |\n| **`touchableProps`**                                    | Properties for the `touchableComponent`                                                                        |\n| **`disabled`**                                          | Set whether the user can interact with the Accordion                                                           |\n| **`align`**                                             | See `Collapsible`                                                                                              |\n| **`duration`**                                          | See `Collapsible`                                                                                              |\n| **`easing`**                                            | See `Collapsible`                                                                                              |\n| **`onAnimationEnd(key, index)`**                        | See `Collapsible`.                                                                                             |\n| **`expandFromBottom`**                                  | Expand content from the bottom instead of the top                                                              |\n| **`expandMultiple`**                                    | Allow more than one section to be expanded. Defaults to false.                                                 |\n| **`sectionContainerStyle`**                             | Optional styling for the section container.                                                                    |\n| **`containerStyle`**                                    | Optional styling for the Accordion container.                                                                  |\n| **`renderAsFlatList`**                                  | Optional rendering as FlatList (defaults to false).                                                            |\n\n## Demo\n\n![demo](https://cloud.githubusercontent.com/assets/378279/8047315/0237ca2c-0e44-11e5-9a16-1da052406eb0.gif)\n\n## Example\n\nCheck full example in the `Example` folder.\n\n```js\nimport React, { Component } from 'react';\nimport Accordion from 'react-native-collapsible/Accordion';\n\nconst SECTIONS = [\n  {\n    title: 'First',\n    content: 'Lorem ipsum...',\n  },\n  {\n    title: 'Second',\n    content: 'Lorem ipsum...',\n  },\n];\n\nclass AccordionView extends Component {\n  state = {\n    activeSections: [],\n  };\n\n  _renderSectionTitle = (section) =\u003e {\n    return (\n      \u003cView style={styles.content}\u003e\n        \u003cText\u003e{section.content}\u003c/Text\u003e\n      \u003c/View\u003e\n    );\n  };\n\n  _renderHeader = (section) =\u003e {\n    return (\n      \u003cView style={styles.header}\u003e\n        \u003cText style={styles.headerText}\u003e{section.title}\u003c/Text\u003e\n      \u003c/View\u003e\n    );\n  };\n\n  _renderContent = (section) =\u003e {\n    return (\n      \u003cView style={styles.content}\u003e\n        \u003cText\u003e{section.content}\u003c/Text\u003e\n      \u003c/View\u003e\n    );\n  };\n\n  _updateSections = (activeSections) =\u003e {\n    this.setState({ activeSections });\n  };\n\n  render() {\n    return (\n      \u003cAccordion\n        sections={SECTIONS}\n        activeSections={this.state.activeSections}\n        renderSectionTitle={this._renderSectionTitle}\n        renderHeader={this._renderHeader}\n        renderContent={this._renderContent}\n        onChange={this._updateSections}\n      /\u003e\n    );\n  }\n}\n```\n\n### Transition backgrounds\n\nIf you combine with the [`react-native-animatable`](https://github.com/oblador/react-native-animatable) library you can easily transition the background color between the active and inactive state or add animations.\n\nLets augment the example above with:\n\n```js\nimport * as Animatable from 'react-native-animatable';\n\n(...)\n\n  _renderHeader(section, index, isActive, sections) {\n    return (\n      \u003cAnimatable.View\n        duration={300}\n        transition=\"backgroundColor\"\n        style={{ backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)') }}\u003e\n        \u003cText style={styles.headerText}\u003e{section.title}\u003c/Text\u003e\n      \u003c/Animatable.View\u003e\n    );\n  }\n\n  _renderContent(section, i, isActive, sections) {\n    return (\n      \u003cAnimatable.View\n        duration={300}\n        transition=\"backgroundColor\"\n        style={{ backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)') }}\u003e\n        \u003cAnimatable.Text\n          duration={300}\n          easing=\"ease-out\"\n          animation={isActive ? 'zoomIn' : false}\u003e\n          {section.content}\n        \u003c/Animatable.Text\u003e\n      \u003c/Animatable.View\u003e\n    );\n  }\n\n(...)\n```\n\nTo produce this (slowed down for visibility):\n\n![accordion-demo](https://cloud.githubusercontent.com/assets/378279/10767769/2ddfe234-7cb4-11e5-8ef1-c0f8c67ead58.gif)\n\n## Contributing\n\nInterested in contributing to this repo? Have a look at our [Contributing Guide](https://github.com/oblador/react-native-collapsible/blob/master/.github/CONTRIBUTING.MD)\n\n## Maintainers\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/oblador\"\u003e\n          \u003cimg width=\"150\" height=\"150\" src=\"https://github.com/oblador.png?v=3\u0026s=150\"\u003e\n          \u003cbr\u003e\n          \u003cstrong\u003eJoel Arvidsson\u003c/strong\u003e\n        \u003c/a\u003e\n        \u003cbr\u003e\n        Author\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\n## License\n\n[MIT License](http://opensource.org/licenses/mit-license.html). © Joel Arvidsson and contributors 2015-2021\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foblador%2Freact-native-collapsible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foblador%2Freact-native-collapsible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foblador%2Freact-native-collapsible/lists"}