nStartShouldSetResponder和onRespo

nStartShouldSetResponder和onRespo

本文介绍了反应本机onStartShouldSetResponder和onResponderRelease吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个按钮,希望在单击该按钮时调用该功能,然后在释放时再次调用该功能.正常的TouchableOpacity或其他功能仅在释放单击时会触发功能,我需要在单击和释放时都使用功能.

I've created a button that I want to have call a function on click and then again on release. A normal TouchableOpacity or other will trigger a function upon release of a click only, I need functions on both click AND release.

<View
    style={styles.touchbutton}
    onStartShouldSetResponder={() => this.clickOn()}
    onResponderRelease={() => this.clickRelease()}>
    <Text style={styles.dark}>Button</Text>
</View>

上面的代码仅在单击时有效,但在发布时无效.我也尝试了onResponderReject,但这也不起作用.很难找到命令应该是什么.

The above code works on click but not on release. I also tried onResponderReject but that doesn't work either. Hard to find what the command should be.

推荐答案

出现相同的问题. onStartShouldSetResponder 需要返回 true .

Had the same problem. onStartShouldSetResponder needs to return true.

onStartShouldSetResponder={(e) => {
    /*do whatever*/;
    return true
}}

这篇关于反应本机onStartShouldSetResponder和onResponderRelease吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:20