代码之家  ›  专栏  ›  技术社区  ›  Hemadri Dasari

TypeError:undefined不是对象(计算this.getActiveTab().barColor)

  •  0
  • Hemadri Dasari  · 技术社区  · 6 年前

    TypeError:undefined不是对象(正在计算)

    import React, { Component } from 'react';
    import { StyleSheet, Text, View } from 'react-native';
    import home from "../../../assets/home.png";
    import form from "../../../assets/home.png";
    import contact from "../../../assets/home.png";
    import BottomNavigation, {
      FullTab, Tab
    } from 'react-native-material-bottom-navigation';
    
    import Icon from 'react-native-vector-icons/MaterialIcons';
    export default class BottomView extends Component {
      constructor(props){
        super(props);
        this.state = { activeTab: 0 };
      }
    
      handleTabChange = (newTabIndex, oldTabIndex) => {
            this.setState({ activeTab: newTabIndex });
            if (newTabIndex === oldTabIndex) {
              null;
            }
            if (this.state.activeTab === 0) {
            } else if (this.state.activeTab === 1) {
            } else {
            }
        }
    
      render(){
        return(
          <View style={styles.container}>   
                    <BottomNavigation
                        activeTab={this.state.activeTab}
                        labelColor="#5c007a"
                        rippleColor="white"
                        style={{
                          height: 56,
                          elevation: 8,
                          position: 'absolute',
                          left: 0,
                          bottom: 0,
                          right: 0
                        }}
                        onTabChange={this.handleTabChange}
                    >
                        <Tab 
                          barBackgroundColor="#fff"
                          label="Home"
                          icon={<Icon size={24} color="#5c007a" name="home" />}
                        />
                        <Tab 
                          barBackgroundColor="#fff"
                          label="Categories"
                          icon={<Icon size={24} color="#5c007a" name="list" />}
                        />
                        <Tab
                          barBackgroundColor="#fff"
                          label="Profile"
                          icon={<Icon size={24} color="#5c007a" name="person" />}
                        />
                    </BottomNavigation>
                </View>
        )
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
      }
    });
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Nick Fleischhauer    6 年前

    两个潜在的问题是。。

    1) 看起来您正试图从“react native material bottom navigation”导入选项卡组件,但是从他们的API文档显示的内容来看,这个包提供的组件似乎是:

    • 海底航行
    • 完整标签
    • IconTab公司

    https://github.com/timomeh/react-native-material-bottom-navigation/tree/master/docs/api

    我建议深入研究他们的文档,了解如何使用他们提供的组件。

    2) 您正在从“react native vector icons/MaterialIcons”导入图标。

    我看了他们文档的那一部分,你的实现方式与他们建议你的方式不符。要解决该特定问题,请将 Icon 具有 MaterialIcons

    https://github.com/oblador/react-native-vector-icons/blob/master/MaterialIcons.js