[英]Allow Panresponder only when I am moving my fingers React native
I am very new to react native animations.我对原生动画反应很陌生。 I want to create sliding up panel, though there are many libraries for this, but I don't want to use these for self learning purpose.
我想创建滑动面板,尽管有很多库用于此,但我不想将这些用于自学目的。
The code I have written:-我写的代码:-
constructor(props){
super(props);
this.animatedHeight = new Animated.Value(100);
this.panresponder = PanResponder.create({
onMoveShouldSetPanResponder:()=>true,
onPanResponderMove:(e,gesture)=>{
if( gesture.dy < 0 && gesture.vy < 0 )
this.animatedHeight.setValue(Math.abs(gesture.dy) + 100) // increasing the height. Original height + delta y
else if(gesture.dy > 0 && gesture.vy > 0){
// code for decreasing the height
}
}
})
}
render(){
return(
<Animated.View
style={[styles.movableContainer,{height:this.animatedHeight}]}
{...this.panresponder.panHandlers}
></Animated.View>
)
}
const styles = StyleSheet.create({
movableContainer:{
bottom: 0,
width:'100%',
backgroundColor:'red',
position:'absolute',
zIndex:9999
}
})
After releasing whenever I am putting my finger back to screen the panel shrinks.每当我将手指放回屏幕时松开后,面板就会缩小。 I want to shrink the panel when ever I am moving my finger
当我移动手指时,我想缩小面板
Try adding below code when create PanResponder
创建
PanResponder
时尝试添加以下代码
onPanResponderGrant: (evt, gestureState) => {
this.animatedHeight.setOffset(this.animatedHeight._value);
}
onPanResponderRelease: (e, { vx, vy }) => {
this.animatedHeight.flattenOffset();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.