Skip to content

Commit

Permalink
Merge pull request #7 from sehranhas/reset-height-on-props
Browse files Browse the repository at this point in the history
reset height if refresh is true
  • Loading branch information
sehranhas authored Jul 3, 2018
2 parents 4d87649 + 5b9417b commit 25675af
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';

import {
StyleSheet,
TouchableHighlight,
View,
Text,
Animated,
Platform
Animated
} from 'react-native';

const propTypes = {
Expand All @@ -21,7 +18,8 @@ const propTypes = {
header: PropTypes.element.isRequired,
onPress: PropTypes.func,
underlayColor: PropTypes.string,
style: PropTypes.object
style: PropTypes.object,
refresh: PropTypes.bool
}

const defaultProps = {
Expand All @@ -30,7 +28,8 @@ const defaultProps = {
easing: 'linear',
expanded: false,
underlayColor: '#000',
style: {}
style: {},
refresh: false
}

class Accordion extends Component {
Expand Down Expand Up @@ -90,9 +89,13 @@ class Accordion extends Component {
setTimeout(this._getContentHeight);
}

componentWillReceiveProps() {
this.state.height.setValue(0);
this.setState({expanded: this.props.expanded});
componentWillReceiveProps(nextProps) {
// Force to refresh height if your component containing the accordion does not mount every time
// when viewing the expandable list (e.g when you have tabs)
if (nextProps.refresh) {
this.state.height.setValue(0);
this.setState({expanded: this.props.expanded});
}
}

render() {
Expand Down

0 comments on commit 25675af

Please sign in to comment.