Skip to content

Commit

Permalink
Merge pull request #2 from alexrabarts/public-methods
Browse files Browse the repository at this point in the history
Public methods for open/close/toggle
  • Loading branch information
naoufal committed Jul 3, 2015
2 parents ea3a313 + 75ea974 commit d74145d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ The following props can be used to modify the Accordion's style and/or behaviour
|__`underlayColor`__|_String_|Optional|`#000`|The underlay color of the [TouchableHighlight](https://facebook.github.io/react-native/docs/touchablehighlight.html).
|__`style`__|_Object_|Optional|`{}`|The styles you want to set on the accordion element.

## Methods
The following methods can be used to open and close the accordion:

| Method | Parameters | Note |
|---|---|---|
|__`open`__|`N/A`|Open the accordion.
|__`close`__|`N/A`|Close the accordion.
|__`toggle`__|`N/A`|Toggle the accordion.

## License
Copyright (c) 2015, Naoufal Kadhom
Expand Down
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,26 @@ var Accordion = React.createClass({
};
},

_toggleAccordion() {
close() {
this.state.is_visible && this.toggle();
},

open() {
!this.state.is_visible && this.toggle();
},

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
});
},

_onPress() {
this.toggle();

if (this.props.onPress) {
this.props.onPress.call(this);
Expand Down Expand Up @@ -80,7 +92,7 @@ var Accordion = React.createClass({
>
<TouchableHighlight
ref="AccordionHeader"
onPress={this._toggleAccordion}
onPress={this._onPress}
underlayColor={this.props.underlayColor}
style={this.props.style}
>
Expand Down

0 comments on commit d74145d

Please sign in to comment.