反应原生的android动画

时间:2016-01-27 18:54:10

标签: android animation react-native animated

我正在尝试使用本机的视图设置动画的高度。动画在iOS中按预期工作,但在Android中无效。无论动画值如何,动画视图似乎总是全高。相关代码如下:

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

1 个答案:

答案 0 :(得分:-1)

尝试将动画值移出状态:

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

然后,将其称为this.h,而不是this.state.h