React Native 或 NativeBase Picker 可以拥有包含图像的项目吗?

2024-02-11

我是智能手机编程新手,加入了一个使用 React Native 和 NativeBase 的项目。

我想在选择器的每个项目中包含一个图像/图标,这似乎不是一个异国情调的概念,但它似乎不受支持,而且我找不到任何人讨论这样做或通过谷歌搜索。

我尝试了几种在其中添加内容的方法<Picker.Item> and </Picker.Item>但放在那里的任何东西似乎都被忽略了。

是否有可能或者是否有不同的方法来使用这些框架来做我想做的事情?


你可以试试这个包

https://github.com/sohobloo/react-native-modal-dropdown https://github.com/sohobloo/react-native-modal-dropdown

完整的例子你可以在这里查看

https://github.com/sohobloo/react-native-modal-dropdown/blob/master/example/index.js https://github.com/sohobloo/react-native-modal-dropdown/blob/master/example/index.js

使用是这样的

_dropdown_2_renderRow(rowData, rowID, highlighted) {
let icon = highlighted ? require('./images/heart.png') : require('./images/flower.png');
let evenRow = rowID % 2;
return (
  <TouchableHighlight underlayColor='cornflowerblue'>
    <View style={[styles.dropdown_2_row, {backgroundColor: evenRow ? 'lemonchiffon' : 'white'}]}>
      <Image style={styles.dropdown_2_image}
             mode='stretch'
             source={icon}
      />
      <Text style={[styles.dropdown_2_row_text, highlighted && {color: 'mediumaquamarine'}]}>
        {`${rowData.name} (${rowData.age})`}
      </Text>
    </View>
  </TouchableHighlight>
);
}

最终产品示例如下所示:

所有版权属于:https://github.com/sohobloo https://github.com/sohobloo

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

React Native 或 NativeBase Picker 可以拥有包含图像的项目吗? 的相关文章