2017-10-12 22 views
0

我学习反应原生动画。当我console.log(this.position.x);它表明x下的函数名_interpolation那么,为什么我们这样做:函数`interpolate`来自

transform: [{ 
      rotate: this.position.x.interpolate({ 
      inputRange: [-200, 200], 
      outputRange: ['-45deg', '45deg'] // 0 : 150, 0.5 : 75, 1 : 0 
      }), 
     }], 

souldn't它是:

transform: [{ 
      rotate: this.position.x._interpolation({ 
      inputRange: [-200, 200], 
      outputRange: ['-45deg', '45deg'] // 0 : 150, 0.5 : 75, 1 : 0 
      }), 
     }], 

附: position来自this.position = new Animated.ValueXY();

enter image description here

回答

1

添加前缀_属性通常表示不应在外部访问私有/内部属性。所以你的问题的答案是:没有

此外,_interpolation似乎是一个对象“内部” this.position.x(即一个属性...的属性)的属性,以便访问它this.position.x不会反正工作。

在功能interpolate

未来它在AnimatedValue实例的原型可能定义。如果你不知道原型如何在JavaScript中工作,我建议看看YDKJS - this & object prototypes

+0

感谢您的帮助,AnimatedValue来自哪里? – farmcommand2

+0

您的屏幕截图显示该值是“AnimatedValue”的实例。 –

+0

以下是AnimatedValue源代码的链接:https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/Libraries/Animated/src/nodes/AnimatedValue.js –