react-native - 使用 PanResponder React Native(版本 0.60.5)在 Tap 上将动画视图缩小到默认位置
问题描述
我想设计一个如下的屏幕:-
底部屏幕(通道)是垂直滑动的,当拖动开始时高度会增加。我可以用 panresonder 做到这一点,在垂直滑动后它将有一个全屏高度,里面会有一个滚动视图,但是当每当我点击这个屏幕时,当它的高度已满时,它就会缩小到原来的位置。
这是我写的代码:-
componentWillMount() {
this._panResponder = PanResponder.create({
onMoveShouldSetPanResponder: (e, gestureState) => true,
//When dragging the screen change the height
onPanResponderMove: (e, gestureState) => {
this.setState({
bottomHeight: gestureState.moveY > (this.state.deviceHeight - 40) ? 40 : this.state.deviceHeight - gestureState.moveY,
})
},
// After reaching a certain height when releasing the finger make bottom screen full height.
onPanResponderRelease: (e, gestureState) => {
if (gestureState.dy != 0) {
if (gestureState.dy < 0 && Math.abs(gestureState.dy) > 30) {
this.setState({
bottomHeight: this.state.deviceHeight - 200,
collapsed: false,
opacity: 0.7,
backgroundColor: '#191919'
})
} else if (gestureState.dy > 10) {
this.setState({
bottomHeight: 100,
collapsed: true,
opacity: 1,
backgroundColor: '#FFFFFF'
})
} else {
this.setState({
bottomHeight: this.state.deviceHeight - 200,
collapsed: false,
opacity: 0.7,
backgroundColor: '#191919'
})
}
}
}
});
}
JSX 部分
<Animated.View
style={{
borderTopWidth: 15,
borderTopColor: '#FFD200',
backgroundColor: '#FFFFFF',
position: 'absolute',
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
bottom: 0,
left: 0,
right: 0,
minHeight: 150,
maxHeight: this.state.deviceHeight - 200,
height: this.state.bottomHeight
}}
{...this._panResponder.panHandlers}
>
</Animated.View>
我使用了 rn-sliding-up-panel库,但是当我拖动底部屏幕时,性能 ios 不太好,这就是我自己编写的原因。有没有办法忽略点击手势或任何其他方式来实现这一点。我对动画不太擅长,这方面的初学者,可能这个问题很傻。任何形式的帮助表示赞赏。
解决方案
推荐阅读
- scala - 如果另一个未来失败了,如何取消未来的行动?
- java - 如何将 java apis 与 HTML 页面集成
- deep-learning - 如何组合图像 id 图像并使用 pytorch 转换为张量
- json - 在列表视图中切换排序
- python - 两个相同的 python 脚本,但只有一个在气流中工作,而另一个不工作?
- testing - 基于 API 的测试是黑盒测试还是灰盒测试?
- google-ads-api - Google Ads - 类别错误
- python - 在堆栈图的弹出窗口中打印图例
- python - 如何在 np.where 中使用表示条件的变量作为 pandas 中具有列表值的列?
- powershell - 暂停 Windows 更新长达 35 天,并通过 powershell 找出暂停更新的日期