All Projects → oblador → React Native Collapsible

oblador / React Native Collapsible

Licence: mit
Animated collapsible component for React Native, good for accordions, toggles etc

Programming Languages

javascript
184084 projects - #8 most used programming language
java
68154 projects - #9 most used programming language
objective c
16641 projects - #2 most used programming language
Starlark
911 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to React Native Collapsible

React Sanfona
Accessible react accordion component
Stars: ✭ 248 (-88.61%)
Mutual labels:  accordion, collapsible
BeefUp
Just a jQuery accordion plugin
Stars: ✭ 41 (-98.12%)
Mutual labels:  accordion, collapsible
react-collapse
Component-wrapper for collapse animation with CSS for elements with variable and dynamic height
Stars: ✭ 143 (-93.43%)
Mutual labels:  accordion, collapsible
Azexpandableiconlistview
An expandable/collapsible view component written in Swift.
Stars: ✭ 284 (-86.96%)
Mutual labels:  accordion, collapsible
react-native-panel
A Customizable React Native Panel for Android and iOS
Stars: ✭ 35 (-98.39%)
Mutual labels:  accordion, collapsible
React Collapsible
React component to wrap content in Collapsible element with trigger to open and close.
Stars: ✭ 402 (-81.54%)
Mutual labels:  accordion, collapsible
React Native Collapsible Toolbar
Pure JS based collapsible toolbar for react native on Android and iOS
Stars: ✭ 50 (-97.7%)
Mutual labels:  collapsible
Hibiscus.js
Native Angular directives for Bootstrap4
Stars: ✭ 115 (-94.72%)
Mutual labels:  accordion
Ionic2accordion
This is a simple variant implementation of an accordion within ionic 2
Stars: ✭ 44 (-97.98%)
Mutual labels:  accordion
React Collapsing Table
react-collapsing-table: a React rewrite of the jQuery table plugin from "datatables.net". Inspired by a lack of similar table behaviors, notably collapsibility and responsivity.
Stars: ✭ 21 (-99.04%)
Mutual labels:  collapsible
Emaccordiontableviewcontroller
Accordion effect for UITableView
Stars: ✭ 158 (-92.75%)
Mutual labels:  accordion
Houdini
A simple, accessible show-and-hide/accordion script.
Stars: ✭ 148 (-93.2%)
Mutual labels:  accordion
Collapsible Resource Manager
A custom sidebar menu with collapsible groups
Stars: ✭ 100 (-95.41%)
Mutual labels:  collapsible
Fancyaccordionview
An Android fancy accordion view
Stars: ✭ 64 (-97.06%)
Mutual labels:  accordion
React Native Collapsible Header Views
ScrollView, FlatList, SectionList with collapsible headers + HOC for wrapping custom scrollables
Stars: ✭ 120 (-94.49%)
Mutual labels:  collapsible
Octopatcher
Arrgh Some Patchy Goodness to GitHub!
Stars: ✭ 49 (-97.75%)
Mutual labels:  collapsible
Niui
Lightweight, feature-rich, accessible front-end library
Stars: ✭ 152 (-93.02%)
Mutual labels:  accordion
Ng Bootstrap
Angular powered Bootstrap
Stars: ✭ 7,872 (+261.43%)
Mutual labels:  accordion
Accordion
Accordion module created in pure javascript & CSS. Very useful to create FAQ lists on your website.
Stars: ✭ 94 (-95.68%)
Mutual labels:  accordion
Abexpandableview
Expandable, collapsible, filterable and single/multi selectable table view.
Stars: ✭ 138 (-93.66%)
Mutual labels:  collapsible

react-native-collapsible

Animated collapsible component for React Native using the Animated API

Pure JavaScript, supports dynamic content heights and components that is aware of its collapsed state (good for toggling arrows etc).

Installation

npm install --save react-native-collapsible

Collapsible Usage

import Collapsible from 'react-native-collapsible';

() => (
  <Collapsible collapsed={isCollapsed}>
    <SomeCollapsedView />
  </Collapsible>
);

Properties

Prop Description Default
align Alignment of the content when transitioning, can be top, center or bottom top
collapsed Whether to show the child components or not true
collapsedHeight Which height should the component collapse to 0
enablePointerEvents Enable pointer events on collapsed view false
duration Duration of transition in milliseconds 300
easing Function or function name from Easing (or tween-functions if < RN 0.8). Collapsible will try to combine Easing functions for you if you name them like tween-functions. easeOutCubic
renderChildrenCollapsed Render children in collapsible even if not visible. true
style Optional styling for the container
onAnimationEnd Callback when the toggle animation is done. Useful to avoid heavy layouting work during the animation () => {}

Accordion Usage

This is a convenience component for a common use case, see demo below.

import Accordion from 'react-native-collapsible/Accordion';

() => (
  <Accordion
    activeSections={[0]}
    sections={['Section 1', 'Section 2', 'Section 3']}
    renderSectionTitle={this._renderSectionTitle}
    renderHeader={this._renderHeader}
    renderContent={this._renderContent}
    onChange={this._updateSections}
  />
);

Properties

Prop Description
sections An array of sections passed to the render methods
renderHeader(content, index, isActive, sections) A function that should return a renderable representing the header
renderContent(content, index, isActive, sections) A function that should return a renderable representing the content
renderFooter(content, index, isActive, sections) A function that should return a renderable representing the footer
renderSectionTitle(content, index, isActive) A function that should return a renderable representing the title of the section outside the touchable element
onChange(indexes) A function that is called when the currently active section(s) are updated.
keyExtractor(item, index) Used to extract a unique key for a given item at the specified index.
activeSections Control which indices in the sections array are currently open. If empty, closes all sections.
underlayColor The color of the underlay that will show through when tapping on headers. Defaults to black.
touchableComponent The touchable component used in the Accordion. Defaults to TouchableHighlight
touchableProps Properties for the touchableComponent
disabled Set whether the user can interact with the Accordion
align See Collapsible
duration See Collapsible
easing See Collapsible
onAnimationEnd(key, index) See Collapsible.
expandFromBottom Expand content from the bottom instead of the top
expandMultiple Allow more than one section to be expanded. Defaults to false.
sectionContainerStyle Optional styling for the section container.
containerStyle Optional styling for the Accordion container.
renderAsFlatList Optional rendering as FlatList (defaults to false).

Demo

demo

Example

Check full example in the Example folder.

import React, { Component } from 'react';
import Accordion from 'react-native-collapsible/Accordion';

const SECTIONS = [
  {
    title: 'First',
    content: 'Lorem ipsum...',
  },
  {
    title: 'Second',
    content: 'Lorem ipsum...',
  },
];

class AccordionView extends Component {
  state = {
    activeSections: [],
  };

  _renderSectionTitle = (section) => {
    return (
      <View style={styles.content}>
        <Text>{section.content}</Text>
      </View>
    );
  };

  _renderHeader = (section) => {
    return (
      <View style={styles.header}>
        <Text style={styles.headerText}>{section.title}</Text>
      </View>
    );
  };

  _renderContent = (section) => {
    return (
      <View style={styles.content}>
        <Text>{section.content}</Text>
      </View>
    );
  };

  _updateSections = (activeSections) => {
    this.setState({ activeSections });
  };

  render() {
    return (
      <Accordion
        sections={SECTIONS}
        activeSections={this.state.activeSections}
        renderSectionTitle={this._renderSectionTitle}
        renderHeader={this._renderHeader}
        renderContent={this._renderContent}
        onChange={this._updateSections}
      />
    );
  }
}

Transition backgrounds

If you combine with the react-native-animatable library you can easily transition the background color between the active and inactive state or add animations.

Lets augment the example above with:

import * as Animatable from 'react-native-animatable';

(...)

  _renderHeader(section, index, isActive, sections) {
    return (
      <Animatable.View
        duration={300}
        transition="backgroundColor"
        style={{ backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)') }}>
        <Text style={styles.headerText}>{section.title}</Text>
      </Animatable.View>
    );
  }

  _renderContent(section, i, isActive, sections) {
    return (
      <Animatable.View
        duration={300}
        transition="backgroundColor"
        style={{ backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)') }}>
        <Animatable.Text
          duration={300}
          easing="ease-out"
          animation={isActive ? 'zoomIn' : false}>
          {section.content}
        </Animatable.Text>
      </Animatable.View>
    );
  }

(...)

To produce this (slowed down for visibility):

accordion-demo

Contributing

Interested in contributing to this repo? Have a look at our Contributing Guide

Maintainers


Joel Arvidsson

Author

License

MIT License. © Joel Arvidsson and contributors 2015-2021

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].