禁用TouchableHighlight onPress?

Mel*_*cuk 5 reactjs react-native

如果其中一组按下,如何禁用TouchableHighlight组?可能吗 ?例如,我有listview,并且每一行都有两个TouchableHighlights。如果其中之一被按下,我想禁用这两个可触摸对象的onPress功能。

Nis*_*kar -2

这里的一种选择是使用非常基本的信号量。单击其中一个按钮后,您可以将全局变量 x 设置为 true。在另一个 onPress 函数中,如果 x 为 true,则可以返回

onPressOne(){
 if(this.semaphore)
   return
 this.semaphore = true
 // other code here
}
onPressTwo(){
 if(this.semaphore)
   return
 this.semaphore = true
 // other code here
}
Run Code Online (Sandbox Code Playgroud)

在您重置之前,按钮不会执行任何操作this.semaphore = false 如果您想禁用 TouchableHighlight 的视觉突出显示,您可以在单击其中一个按钮时更改activeOpacity属性