代码之家  ›  专栏  ›  技术社区  ›  Ronald Zwiers

如何使用flatList React Native动态创建图标

  •  0
  • Ronald Zwiers  · 技术社区  · 6 年前

    我想通过在列表组件上使用一个属性来发送一个图标名称。所以我可以通过给道具图标的图标名来设置列表中的正确图标。我的代码是这样的:

    import React from 'react';
    import { Text, View, FlatList } from 'react-native';
    import PropTypes from 'prop-types';
    import styled from 'styled-components/native';
    import { List, ListItem } from 'react-native-elements';
    
    class ListLi extends React.Component {
    constructor(props){
        super(props);
    };
    
    renderRow ({ item }) {
        let node;
    
        React.Children.forEach(item, component => {
            node = component;
        });
    
      return (
        <ListItem onPressRightIcon title={node} rightIcon={{name:icon}}/>
      )
    }
    
    render () {
      const { children, icon } = this.props;
    
      return (
        <StyledList>
            <List>
              <FlatList
                data={children}
                extraData={icon}
                renderItem={this.renderRow}
                keyExtractor={item => item.name}
              />
            </List>
        </StyledList>
      )
     }
    }
    
    export default ListLi;
    

    图标属性包含图标的名称,我想在rightIcon中呈现它 rightIcon={{name:icon}} 有什么想法吗?

    0 回复  |  直到 6 年前