Skip to content

Commit

Permalink
Merge pull request #1 from sehranhas/fix-accordion
Browse files Browse the repository at this point in the history
Fix accordion
  • Loading branch information
sehranhas authored Jun 4, 2018
2 parents 1cc6b83 + f2da8e7 commit cb77bdf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var YourComponent = React.createClass({
<Accordion
header={header}
content={content}
contentHeight={50}
easing="easeOutCubic"
/>
);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"homepage": "https://github.com/naoufal/react-native-accordion",
"dependencies": {
"react-tween-state": "0.0.5"
"create-react-class": "^15.6.3",
"react-tween-state": "^0.1.5"
}
}
30 changes: 16 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

import React, { PropTypes } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import tweenState from 'react-tween-state';
var createReactClass = require('create-react-class');

import {
StyleSheet,
Expand All @@ -10,19 +12,20 @@ import {
Text
} from 'react-native';

var Accordion = React.createClass({
var Accordion = createReactClass({
mixins: [tweenState.Mixin],

propTypes: {
activeOpacity: React.PropTypes.number,
animationDuration: React.PropTypes.number,
content: React.PropTypes.element.isRequired,
easing: React.PropTypes.string,
expanded: React.PropTypes.bool,
header: React.PropTypes.element.isRequired,
onPress: React.PropTypes.func,
underlayColor: React.PropTypes.string,
style: React.PropTypes.object
activeOpacity: PropTypes.number,
animationDuration: PropTypes.number,
content: PropTypes.element.isRequired,
easing: PropTypes.string,
expanded: PropTypes.bool,
header: PropTypes.element.isRequired,
onPress: PropTypes.func,
underlayColor: PropTypes.string,
style: PropTypes.object,
contentHeight: PropTypes.number.isRequired
},

getDefaultProps() {
Expand Down Expand Up @@ -54,11 +57,10 @@ var Accordion = React.createClass({

toggle() {
this.state.is_visible = !this.state.is_visible;

this.tweenState('height', {
easing: tweenState.easingTypes[this.props.easing],
duration: this.props.animationDuration,
endValue: this.state.height === 0 ? this.state.content_height : 0
endValue: this.state.height === 0 ? this.props.contentHeight : 0
});
},

Expand Down Expand Up @@ -103,7 +105,7 @@ var Accordion = React.createClass({
underlayColor={this.props.underlayColor}
style={this.props.style}
>
{this.props.header}
<View>{this.props.header}</View>
</TouchableHighlight>
<View
ref="AccordionContentWrapper"
Expand Down

0 comments on commit cb77bdf

Please sign in to comment.