ReactNative Antd-Mobile OnPress & Icon 不起作用



我对下面的代码有两个问题,该项目是ReactNative,并使用antd-mobile作为UI组件。

反应原生:

"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 On按不工作onPress={ () => this.onChangeTab.bind(this, 'category') }

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

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>
        )
    }
}

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

尝试 <图标类型 大小="{20}/">

希望有效!

最新更新