2016-07-22 50 views
0

我使用TabBarIOS在本機反應,並在android模擬器上運行它,但同時使用TabBarIOS .Item我收到以下錯誤認證的Element type is invalid expected a string(for built in components) or a class/function (for composite functions) but got undefined check render method of Approvals錯誤:元素類型無效期望一個字符串(用於內置組件)或一個類/函數(用於複合功能),但得到了undefined

渲染()方法如下

render(){ 

    return (
    <View style={styles.container}> 
     <View style={styles.strip}> 
      <Image style={{width:50, height:30,padding:10,top:5}} source={require('./drawable/drawable/asap.png')}/> 
      <Text style={{fontSize:20,color:'white',bottom:20,left:60,padding:10}}>Approvals</Text> 
     </View> 
     <TabBarIOS selectedTab={this.state.selectedTab}> 
      <TabBarIOS.Item 
      title="Pending" 
      icon={{uri:'./drawable/drawable/approvalbadge.png',scale:3}} 
       selected={this.state.selectedTab==='pending'} 
       onPress={() => { 
        this.setState({ 
         selectedTab: 'pending', 
        }); 
       }}> 
       <Pending> 
      </TabBarIOS.Item> 

     </TabBarIOS> 
    </View> 

); 

} 

的錯誤是在本節只如果我刪除TabBarIOS並把它不給任何錯誤引起。請幫我解決這個問題。

+0

你怎麼導入TabBarIOS成分?這看起來像與導入組件有關的錯誤。 –

+0

@TusharKhatiwada從'react-native'導入{TabBarIOS}; –

回答

1

當你導入TabBarIOS時,它被導入爲undefined,因爲你不能在android應用中使用它。 比你打電話

<TabBarIOS selectedTab={this.state.sele 

它被解釋爲undefined 您更好地使用外部實現,而不是(像https://github.com/exponentjs/react-native-tab-navigator)或自己編寫。

0

我沒有正確地閱讀這個問題。您正在嘗試爲Android應用使用IOS組件。但你不能。

帶有IOSAndroid後綴的組件分別僅適用於IOSAndroid應用程序。如果您需要使用跨平臺組件,那麼您必須使用不帶IOSAndroid後綴的組件,或者使用第三方組件。

例如,Navigator作品既iOS和AndroidNavigatorIOS只適用於iOS工作

在這種情況下,你將不得不使用的類似:

https://github.com/exponentjs/react-native-tab-navigator

https://github.com/alinz/react-native-tabbar

相關問題