From ea26cbad5d7e4c6618af438280735f00022a8e18 Mon Sep 17 00:00:00 2001 From: Alex Rabarts Date: Fri, 19 Jun 2015 16:09:47 +0100 Subject: [PATCH 1/2] Add open/close/toggle public methods --- README.md | 8 ++++++++ src/index.js | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d70ab0d..86b748c 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,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 diff --git a/src/index.js b/src/index.js index f9fd31f..04b25f6 100644 --- a/src/index.js +++ b/src/index.js @@ -42,7 +42,15 @@ var Accordion = React.createClass({ }; }, - _toggleAccordion() { + close() { + this.state.is_visible && this._toggleAccordion(); + }, + + open() { + !this.state.is_visible && this._toggleAccordion(); + }, + + toggle() { this.state.is_visible = !this.state.is_visible; this.tweenState('height', { @@ -50,6 +58,10 @@ var Accordion = React.createClass({ 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); @@ -80,7 +92,7 @@ var Accordion = React.createClass({ > From 75ea974dd52552c5836447d0f2612ee498876e6d Mon Sep 17 00:00:00 2001 From: Alex Rabarts Date: Fri, 19 Jun 2015 16:12:43 +0100 Subject: [PATCH 2/2] Fix calling of method that has been renamed --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 04b25f6..7c68763 100644 --- a/src/index.js +++ b/src/index.js @@ -43,11 +43,11 @@ var Accordion = React.createClass({ }, close() { - this.state.is_visible && this._toggleAccordion(); + this.state.is_visible && this.toggle(); }, open() { - !this.state.is_visible && this._toggleAccordion(); + !this.state.is_visible && this.toggle(); }, toggle() {