React Native TouchableHighlight不使用Sectionlist

时间:2017-08-23 22:01:31

标签: react-native react-native-android

我有SectionList,对于列表中的每一行,我希望能够检测到点击事件。

renderList() {
if (this.state.searching) {
  return (
    <SectionList
      sections={this.state.data}
      renderSectionHeader={this.props.renderSectionHeader}
      renderItem={this.props.renderItem}
    />
  );
}

return null;
}

render() {
return (
  <View style={styles.container}>

    <Animated.View
      style={{ opacity: 1 - this.state.backgroundColor }}
      pointerEvents={this.state.searching ? 'none' : undefined}
    >
      {this.props.children}
    </Animated.View>

    <Animated.View
      style={[
        styles.backgroundColorView,
        { opacity: this.state.backgroundColor },
      ]}
    />

    <Animated.View
      style={[styles.searchResults, { top: this.state.yPos }]}
    >
      <TextInput
        ref={(input) => { this.searchBar = input; }}
        style={styles.textInput}
        value={this.props.query}
        onChangeText={this.onChangeText}
        maxLength={100}
        placeholder={this.props.placeholder}
        onFocus={this.onFocus}
        onBlur={this.onUnSearch}
      />

      {this.renderList()}

    </Animated.View>
  </View>
);

对于我的renderItem方法,我传递了以下PureComponent,这只是Text中包含的TouchableHighlight

class SubjectSearchItem extends React.PureComponent {
render() {
const item = this.props.item;
return (
  <TouchableHighlight
    onPress={() => console.log(item)}
  >
    <View style={{
      marginHorizontal: 20,
      marginVertical: 10,
    }}
    >
      <Text>{`${item.item.long_name} (${item.item.short_name})`}</Text>
    </View>
  </TouchableHighlight>
);
}
}

这是我传递的renderItem道具

const renderItem = item => (
      <SubjectSearchItem
        item={item}
      />
    );

问题是,没有检测到点击事件。该行未突出显示,并且onPress未被触发。有任何想法吗?

注意:这似乎是Windows.ApplicationModel.StartupTask一段时间

0 个答案:

没有答案