首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReactNative Antd-移动OnPress &图标不工作

ReactNative Antd-移动OnPress &图标不工作
EN

Stack Overflow用户
提问于 2018-04-14 15:50:07
回答 1查看 706关注 0票数 1

关于下面的代码,我有两个问题,这个项目是ReactNative,UI组件使用and。

ReactNative:

代码语言:javascript
复制
"dependencies": {
"expo": "^26.0.0",
"react": "16.3.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz",
"antd-mobile": "^2.1.8" }
  1. 图标不工作icon={ <Icon type='home' /> }
  2. Tab.Item OnPress不工作onPress={ () => this.onChangeTab.bind(this, 'category') }

在世博会终端上,每次我点击tab.item,它都没有记录它。

代码语言:javascript
复制
import React, { Component } from 'react'
import { View, Text } from 'react-native'
import { TabBar, Icon } from 'antd-mobile'

export class TabBarNav extends Component<any, any> {
    constructor(props) {
        super(props)

        this.state = {
            selectedTab: 'home'
        }

        console.log('selectedTab: ' + this.state.selectedTab)
    }

    renderContent(pageText: any) {
        return (
          <View style={{ flex: 1, alignItems: 'center', backgroundColor: 'white' }}>
            <Text style={{ margin: 50 }}>{pageText}</Text>
          </View>
        )
    }
    onChangeTab(tab) {
        console.log('Selected Tab: ' + tab)
        this.setState({
            selectedTab: tab
        })
    }

    render() {
        return (
            <View>
                <TabBar unselectedTintColor='#949494'
                        tintColor='#33A3F4'
                        barTintColor='#ccc'
                >
                    <TabBar.Item title='Home'
                                 key='home'
                                 selected={ this.state.selectedTab === 'home' }
                                 onPress={ () => this.onChangeTab.bind(this, 'home') } // This is not working
                                 icon={ <Icon type='home' /> } // This is not working
                    >
                        { this.renderContent('home') }
                    </TabBar.Item>
                    <TabBar.Item title='Category'
                                 key='category'
                                 selected={ this.state.selectedTab === 'category' }
                                 onPress={ () => this.onChangeTab.bind(this, 'category') }
                                 icon={ require('../../../artifacts/images/category.png')} // This is working
                    >
                        { this.renderContent('category') }
                    </TabBar.Item>
                </TabBar>
            </View>
        )
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-05-24 02:47:31

从在线示例可以清楚地看出,在RN中没有使用图标名,而是要用于非基本图标的unicode字符串。

尝试<图标type={'\ue65e'} size={20} />

希望能成功!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49833289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档