我是 React native 的新手,学习 Animation 发现了 Blow 代码,差不多一个星期试图了解如果它在构造函数中如何继续调用此函数,以及文档中描述的这种技术在哪里,请解释甚至更好地参考文档在哪里描述。
this._x = fixValue(this.pan)
完整代码:
import React, { Component } from "react";
import { Animated, View, StyleSheet, PanResponder, Text } from "react-native";
function fixValue( valueX ){
// some code here
return valueX;
}
export default class App extends Component {
constructor(props){
super(props);
this.pan = new Animated.Value(0);
this.panResponder = PanResponder.create({
onMoveShouldSetPanResponder: () => true,
onPanResponderMove: Animated.event([
null,
{ dx: this.pan }
], {useNativeDriver: false}),
});
this._x = fixValue(this.pan);
}
render() {
return (
<View style={styles.container}>
<Animated.View
style={{
transform: [{ translateX: this._x }]
}}
{...this.panResponder.panHandlers}
>
<View style={styles.box} />
</Animated.View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center"
},
box: {
height: 100,
width: 100,
backgroundColor: "blue",
borderRadius: 5
}
});