简体   繁体   English

react-native图标不显示

[英]react-native icons does not show

I'm web enginneer in Japan and I'm studying react-native. 我是日本的网络工程师,并且正在研究本机。

I finished react-native tutorial here 我在这里完成了本机教程

And learn create tab here 在此处了解“创建”标签

But featuread tab and search tab not show... 但是Featuread标签和search标签没有显示...

I don't know why this... 我不知道为什么

please help me. 请帮我。

Thank you for your patient with my poor English. 谢谢您对我英语不好的耐心。

This is my codes. 这是我的代码。

【index.ios.js】 【index.ios.js】

    'use strict';

    var React = require('react-native');
    var Featured = require('./Featured');
    var Search = require('./Search');

    var {
        AppRegistry,
        TabBarIOS,
        Component
       } = React;

    class Qiita_Reader extends Component {

      constructor(props) {
        super(props);
        this.state = {
          selectedTab: 'featured'
        };
      }

      render() {
      return (
        <TabBarIOS selectedTab={this.state.selectedTab}>
          <TabBarIOS.Item
            selected={this.state.selectedTab === 'featured'}
            icon={{uri:'Featured'}}
              onPress={() => {
                this.setState({
                    selectedTab: 'featured'
                });
            }}>
           <Featured/>
           </TabBarIOS.Item>
             <TabBarIOS.Item
               selected={this.state.selectedTab === 'search'}
               icon={{uri:'search'}}
               onPress={() => {
                    this.setState({
                        selectedTab: 'search'
                    });
                }}>
                <Search/>
              </TabBarIOS.Item>
          </TabBarIOS>
        );
      }
    }

    AppRegistry.registerComponent('qiita_reader', () => Qiita_Reader);

【Featured.js】 【Featured.js】

    'use strict';

    var React = require('react-native');

    var {
      StyleSheet,
      Text,
      View,
    } = React;

    var FeaturedTab = React.createClass({
      render: function() {
        return (
          <View style={styles.container}>
            <Text style={styles.description}>This is Featured Tab !!</Text>
          </View>
        );
      }
    });

    var styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
      },
      description: {
        fontSize: 15,
        backgroundColor: '#FFFFFF'
      }
    });

    module.exports = FeaturedTab;

【Search.js】 【Search.js】

    'use strict';

    var React = require('react-native');

    var {
      StyleSheet,
      Text,
      View,
    } = React;

    var SearchTab = React.createClass({
      render: function() {
        return (
          <View style={styles.container}>
            <Text style={styles.description}>This is SearchTab !!</Text>
          </View>
        );
      }
    });

    var styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
      },
      description: {
        fontSize: 15,
        backgroundColor: '#FFFFFF'
      }
    });

    module.exports = SearchTab;

You need to use systemIcon instead of icon 您需要使用systemIcon而不是图标

<TabBarIOS.Item
  selected={this.state.selectedTab === 'featured'}
  systemIcon='featured'>
</TabBarIOS.Item>
<TabBarIOS.Item
  selected={this.state.selectedTab === 'featured'}
  systemIcon='featured'>
</TabBarIOS.Item>

Edit: I see the problem now. 编辑:我现在看到了问题。 Check the docs for the TabBarIOS.Item Component. 检查docs中的TabBarIOS.Item组件。 The icon property that you are using is only for custom icons that you upload into XCode. 您使用的icon属性仅用于您上载到XCode中的自定义图标。 If you want to use the system icons, including the ones for search and featured, you want to use the systemIcon prop, followed by the lower-case name of the icon. 如果要使用系统图标(包括要搜索的图标和精选图标), 则要使用systemIcon属性 ,后跟图标的小写名称。

It should be 它应该是

<TabBarIOS.Item
        selected={this.state.selectedTab === 'featured'}
        icon="featured"

and

<TabBarIOS.Item
        selected={this.state.selectedTab === 'search'}
        icon="search"

如果要使用静态图像,也可以使用以下代码:

icon={require('./myimage.png')}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM