简体   繁体   中英

React native android animation

I'm trying to animate the height of a View in react native. The animation is working as expected in iOS but is not working in Android. The animated View seems to always be full height regardless of the animation value. Relevant code is below:

var Facets = React.createClass({
  getInitialState: function() {
    return {
      h: new Animated.Value(0),
    };
  },

  _animate: function(newHeight) {
    Animated.timing(this.state.h, {
      duration: 300,
      toValue: newHeight
    }).start();
  },

  render: function() {
    var facetComponents = [];

    if (this.props.shown) {
      this._animate(MAX_HEIGHT);
    }
    else {
      this._animate(0);
    }

    facets.map( (facet, idx) => {
      facetComponents.push(
        <Facet
          key={idx}
          facet={facet}
          filterBy={this.props.filterBy} />);
    });

    return (
      <Animated.View style={{ maxHeight: this.state.h }}>
        {facetComponents}
      </Animated.View>
    );
  }
});

Try moving your Animated Value out of state:

componentDidMount() {
  this.h = new Animated.Value(0)
}

Then, refer to it as this.h as opposed to this.state.h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM