Javascript 制作动画时,无效的道具“paddingLeft”

Javascript 制作动画时,无效的道具“paddingLeft”,javascript,react-native,Javascript,React Native,我试图使用React本地动画将填充设置为0,然后将其放回,从而删除填充 以下代码用于管理动画: componentWillMount() { this.animatedValueLateralPadding = new Animated.Value(Constants.LIST_ITEM_MARGIN * this.props.dimensions.windowWidth); } componentWillReceiveProps(nextProps) { if(n

我试图使用React本地动画将填充设置为0,然后将其放回,从而删除填充

以下代码用于管理动画:

  componentWillMount() {
    this.animatedValueLateralPadding = new Animated.Value(Constants.LIST_ITEM_MARGIN * this.props.dimensions.windowWidth);
  }



componentWillReceiveProps(nextProps) {
    if(nextProps.index == this.props.element.ordinalNumber) {
      Animated.stagger(Constants.RESIZED_TIME, [
        Animated.parallel([
          Animated.timing(this.animatedValueLateralPadding, {
              toValue: 0,
              duration: Constants.RESIZE_TRANSITION_TIME
            }),
          ]),
        Animated.parallel([
          Animated.timing(this.animatedValueLateralPadding, {
              toValue: Constants.LIST_ITEM_MARGIN * nextProps.dimensions.windowWidth,
              duration: Constants.RESIZE_TRANSITION_TIME
            }),
          ])
      ]).start();
    }
  }
在我的渲染方法中,我指定如下样式:

  const animatedStyle = {paddingLeft: this.animatedValueLateralPadding, paddingRight: this.animatedValueLateralPadding};
然后在该组件中使用animatedStyle,返回:

    <ScrollView
      contentContainerStyle={[listStyles.container, animatedStyle]}
      > 
     //some other code
问题是填充物没有消失,我收到了以下警告:

Failed prop type:Invalid prop 'paddingLeft' supplied to 'ScrollView'. Bad object:
{
  "backgroundColor": "#000000",
  "minHeight": "100%",
  "paddingLeft": 18,
  "paddingRight": 18
}
我不明白为什么它不喜欢我指定的paddingLeft

我尝试将字符串而不是Int all传递给动画.Value对象:

然而,我得到:

Error while updating property: 'paddingLeft' in shadow node of type: RCTView

null

Unknown value: function String() {
   [native code]
}0
那么,为什么我指定填充的方式会有问题呢?你知道如何解决这个问题吗?

你需要使用动画组件,如Animated.View、Animated.Text来制作这个动画。 考虑阅读以下内容:


只需将ScrollView更改为动画。ScrollView

这是React原生样式,而不是CSS。名字用驼色大写。
this.animatedValueLateralPadding = new Animated.Value(String.valueOf(Constants.LIST_ITEM_MARGIN * this.props.dimensions.windowWidth));
 toValue: String.valueOf(0),
 toValue: String.valueOf(Constants.LIST_ITEM_MARGIN * nextProps.dimensions.windowWidth)
Error while updating property: 'paddingLeft' in shadow node of type: RCTView

null

Unknown value: function String() {
   [native code]
}0