1

I have two questions regarding the below code, The project is ReactNative and using antd-mobile for the UI Component.

ReactNative:

"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. The Icon is not working icon={ <Icon type='home' /> }
  2. Tab.Item OnPress not working onPress={ () => this.onChangeTab.bind(this, 'category') }

From the expo terminal, each time I click the tab.item it didn't log it.

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>
        )
    }
}
Herman
  • 2,832
  • 6
  • 25
  • 37

1 Answers1

0

From online examples it is clear that icon names is not used in RN instead unicode strings to be used for non-basic icons

Try <Icon type={'\ue65e'} size={20} />

Hope that works!