当另一个触摸事件在React Native中执行时,如何禁用触摸动作



我使用索引值以及按钮显示列表项目,而我单击列表项目索引中的一个按钮其他列表项目应显示为禁用。会有可能吗?

<TouchableOpacity onPress={() => {this.downloadLessonItems()}}>
 {!this.state.isDownloading && !this.state.isDownloaded &&
  <Image
    style={styles.imgContainer}
    source={this.state.downloadImageURI} />}
</TouchableOpacity>

您可以将 disabled prop添加到touchableOpacity中,因为它从touchableWithableWithOutFeedback中获取disabled Prop,并且值应为boolean

<TouchableOpacity disabled={this.state.disabled} onPress={this._onPressButton}>
  <Image
    style={styles.button}
    source={require('./myButton.png')}
  />
</TouchableOpacity>

对于您的代码,您可以

<TouchableOpacity
  disabled={!this.state.isDownloading && !this.state.isDownloaded}
  onPress={() => {this.downloadLessonItems()}}
 >
  {!this.state.isDownloading && !this.state.isDownloaded &&
    <Image style={styles.imgContainer} source={this.state.downloadImageURI} />}
</TouchableOpacity>

最新更新