2017-10-12 20 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 –