DevinClark / react-native-collapsible

Animated collapsible component for React Native, good for accordions, toggles etc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

var Collapsible = require('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 Wether to show the child components or not true
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

Accordion Usage

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

var Accordion = require('react-native-collapsible/Accordion');
<Accordion 
  sections={['Section 1', 'Section 2', 'Section 3']}
  renderHeader={this._renderHeader}
  renderContent={this._renderContent}
/>

Properties

| Prop | Description | |---|---|---| |sections|An array of sections passed to the render methods| |renderHeader(content, index)|A function that should return a renderable representing the header| |renderContent(content, index)|A function that should return a renderable representing the content| |onChange(index)|An optional function that is called when currently active section is changed, index === false when collapsed| |align|See Collapsible| |duration|See Collapsible| |easing|See Collapsible|

Demo

demo

Example

Check full example in the Example folder.

var React = require('react-native');
var Accordion = require('react-native-collapsible/Accordion');

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

var AccordionView = React.createClass({
  _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>
    );
  },

  render: function() {
    return (
      <Accordion
        sections={SECTIONS}
        renderHeader={this._renderHeader}
        renderContent={this._renderContent}
      />
    );
  }
});

License

MIT License. © Joel Arvidsson 2015

About

Animated collapsible component for React Native, good for accordions, toggles etc

License:MIT License


Languages

Language:JavaScript 52.8%Language:Objective-C 33.5%Language:Java 13.7%