[英]react-native-svg onPress event not working
我正在使用react-native-svg,正如文檔所述,可以在svg元素上觸發onPress事件,但它不起作用。
<Svg width={370} height={180} {...props} viewBox="0 0 385 185" >
<Path
d="M5.607 13.536l9.267 9.267a2.5 2.5 0 0 1-3.535 3.536L.732 15.732a2.497 2.497 0 0 1-.695-2.196 2.497 2.497 0 0 1 .695-2.197L11.34.732a2.5 2.5 0 0 1 3.535 3.536l-9.267 9.268z"
fill="white"
onPress={() => alert('Press on Circle')}
/>
</Svg>
然后,我嘗試了文檔中編寫的示例:
<Svg
height="100"
width="100"
>
<Circle
cx="50%"
cy="50%"
r="38%"
fill="red"
onPress={() => alert('Press on Circle')}
/>
</Svg>
但是作為第一個它是行不通的
該問題是由panResponder引起的,因為它具有比按鈕更高的優先級,因此解決方案是不從onMoveShouldSetPanResponderCapture返回始終為true的結果。 例如:
componentWillMount() {
this.panResponder = PanResponder.create({
onMoveShouldSetPanResponderCapture: this.onShouldDrag,
onPanResponderMove: Animated.event(
[null, { dx: this.state.pan.x }]
),
onPanResponderRelease: this.onReleaseItem,
onPanResponderTerminate: this.onReleaseItem,
});
}
onShouldDrag = (e, gesture) => {
const { dx } = gesture;
return Math.abs(dx) > 2;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.