React Native或NativeBase Picker可以包含包含图像的项目吗? [英] Can a React Native or NativeBase Picker have Items which include images?

查看:192
本文介绍了React Native或NativeBase Picker可以包含包含图像的项目吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是智能手机编程的新手,并且已经加入了使用React Native和NativeBase的项目.

I'm new to smartphone programming and have joined a project using React Native and NativeBase.

我想在Picker的每个项目中都包含一个图像/图标,这似乎不是一个奇特的概念,但是似乎并没有得到支持,我找不到任何讨论在上面进行此操作的人如此或通过谷歌搜索.

I'd like to include an image/icon in each Item in a Picker, which doesn't seem like an exotic concept, but it doesn't seem to be supported and I can't find anyone discussing doing it on SO or by Googling.

我尝试了几种在<Picker.Item></Picker.Item>内添加内容的方法,但是放置在其中的任何内容似乎都被忽略了.

I've tried a couple ways of adding things inside the <Picker.Item> and </Picker.Item> but anything put there seems to simply be ignored.

是否可以使用这些框架来完成我想做的事情?

Is it possible or is there a different approach to do what I want using these frameworks?

推荐答案

您可以尝试此软件包

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

您可以在此处查看完整示例

the complete example you can check here

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

这篇关于React Native或NativeBase Picker可以包含包含图像的项目吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆