【问题标题】:How to disable the touch actions while the other touch event performs in React native?如何在 React Native 中执行其他触摸事件时禁用触摸操作?
【发布时间】:2017-09-18 11:08:30
【问题描述】:

当我单击列表项索引之一中的按钮时,我正在使用索引值和一个按钮显示列表项,其他列表项应该显示为禁用。有可能吗?

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

【问题讨论】:

    标签: react-native react-native-listview react-native-flatlist touchableopacity touchablehighlight


    【解决方案1】:

    您可以将disabled 属性添加到TouchableOpacity,因为它需要来自TouchableWithoutFeedbackdisabled 属性,并且它的值应该是布尔值

    <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>
    

    【讨论】:

    • this.state.disable 指的是什么?
    • 只是用来控制 disabled 属性,可以设置为 true 或 false
    • 我们也可以使用 disabled 来禁用导航吗?
    • disabled 将禁用 onPress 执行,但我不确定您的意思是什么导航
    • {this.downloadLessonItems()}}> {!this.state.isDownloading && !this.state.isDownloaded && }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多