如何在列表项中有条件地更改rightIcon。我正在使用本机元素

安基·库玛(Ankit kumar)

我是react-native的新手,并且我正在使用react-native的元素库。我尝试在rightIcon内调用以下函数,但未呈现rightIcon

  renderItem = ({item}) => (
    console.log('renderItem', item),
    (
      <ListItem
        title={item.name}
        subtitle={<Text style={{color: 'red'}}>{item.subtitle}</Text>}
        leftIcon={<Image source={item.avatar_url} />}
        rightIcon={
          // name: 'ios-arrow-forward',
          // type: 'ionicon',
          () => this.changeIcon(item)
        }
        onPress={this.navigateToScreen(item.route)}
      />
    )
  );
  changeIcon = item => {
    console.log('changeItem', item);
    if (item.subtitle != 'Completed')
      return <Image source={require('../../../assets/icons/menu.png')} />;
  };
LonelyCpp

() => this.changeIcon(item)返回函数引用,但ListItem需要一个组件。

尝试

rightIcon={this.changeIcon(item)}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章