我试图在用户第一次发布时保持平底锅 Y 偏移 - 我已经查看了如何使用以下方法完成此操作,但偏移被忽略:
constructor(props) {
super(props);
this._pan = new Animated.ValueXY();
this._pan.addListener(value => {
this._value = value;
const {height: windowHeight} = Dimensions.get('window');
this.props.onZoomProgress(
Math.min(Math.max((value.y * -1) / windowHeight, 0), 0.5),
);
});
this._panResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onPanResponderGrant: (e, gestureState) => {
this._pan.setOffset({x: 0, y: gestureState.dy});
this._pan.setValue({x: 0, y: 0});
},
onPanResponderMove: (e, gestureState) => {
this._pan.setValue({y: gestureState.dy, x: 0});
console.log(this._pan.y);
},
onPanResponderRelease: (e, gestureState) => {
this._pan.extractOffset();
},
});
}
这是此功能的单独组件,因此我this.props.onZoomProgress()
用于传递值以用作主要组件中的缩放状态。
干杯!