Friday, May 29, 2015

Using accordion in React Native app


Great instruction from naoufal.


react-native-accordion is an easy to use Accordion component for React Native app.

Using accordion in React Native app

Install

npm i --save react-native-accordion

Usage

Using an Accordion in your app will usually look like this:
var Accordion = require('react-native-accordion');

var YourComponent = React.createClass({
  getInitialState() {
    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    return {
      dataSource: ds.cloneWithRows(_.range(25)),
    };
  },

  render() {
    return (
      <ListView
        dataSource={this.state.dataSource}
        renderRow={this._renderRow}
      />
    );
  },

  _renderRow() {
    var header = (
      <View style={...}>
        <Text>Click to Expand</Text>
      </View>
    );

    var content = (
      <View style={...}>
        <Text>This content is hidden in the accordion</Text>
      </View>
    );

    return (
      <Accordion
        header={header}
        content={content}
        easing="easeOutCubic"
      />
    );
  }
});

Example

Here are a few examples of how you can use an accordion in your app:

Props

The following props can be used to modify the Accordion's style and/or behaviour:
PropTypeOpt/RequiredDefaultNote
activeOpacityNumberOptional1The active opacity of the TouchableHighlight.
animationDurationNumberOptional300The duration of the animation.
contentElementRequiredN/AThe content you want hidden in the collapse accordion.
easingStringOptionallinearA tweening function from tween-functions.
headerElementRequiredN/AThe element that will expand the accordion when pressed.
underlayColorStringOptional#000The underlay color of the TouchableHighlight.
styleObjectOptional{}The styles you want to set on the accordion element.

Source: https://github.com/naoufal/react-native-accordion

No comments:

Post a Comment