简体   繁体   English

Flatlist产生的怪异结果导致本机具有可触摸的不透明性

[英]weird results from flatlist in react native with touchable opacity

I have a FlatList in a React Native project. 我在React Native项目中有一个FlatList。 The touchable opacity does register as the view loads, for each row, the console prints selected item.name.. (so, without being touched) however, touching the item does not do anything. 当视图加载时,可触摸的不透明度确实会注册,对于每一行,控制台都会打印选定的item.name ..(因此,不会被触摸),但是,触摸该项不会执行任何操作。

render() {
  return(
        <FlatList
          data={stores.databaseStore.sites.slice()}
          keyExtractor={ (item, index) => item.id}
          numColumns={1}
          extraData={stores.databaseStore.isLoadingSites}
          onRefresh={() => this.onRefresh()}
          refreshing={stores.databaseStore.isLoadingSites}
          renderItem={({item}) => this._renderFlatListItem(item)}
          ItemSeparatorComponent={this._renderSeparator}
          ListHeaderComponent={this._renderHeader}
          ListFooterComponent={this._renderFooter}
        />
  )
}


_renderFlatListItem(item) {
  return (
      <View style={styles.row}>
         <TouchableOpacity onPress={this._showSiteDetails(site)}>
          <View style={styles.cellLeft} >
              <PivotCircle site={item}/>
          </View>
         </TouchableOpacity>
      </View>

  )
}

_showSiteDetails(site){
 console.log(`selected ${site.name}`);
}

found it with the help of some gents on slack 在一些绅士的帮助下找到了它

onPress={this._showSiteDetails(site)} 

should be 应该

onPress={ () => this._showSiteDetails(item)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM