2017-04-19 109 views
0

我想要实现标签航海家反应native.The链接从我得到的代码是 https://reactnavigation.org/docs/navigators/tab 的问题是,当我运行的代码我得到错误500型我也在最后附上error.Plz的图像解决问题,如果有任何人知道关于它的代码是....TabNavigator的是如何实现在本地做出反应

import React from 'react'; 
import { 
    AppRegistry, 
    Text, 
} from 'react-native'; 
import { StackNavigator } from 'react-navigation'; 
class MyHomeScreen extends React.Component { 
    static navigationOptions = { 
    tabBarLabel: 'Home', 
    // Note: By default the icon is only shown on iOS. Search the showIcon option below. 
    tabBarIcon: ({ tintColor }) => (
     <Image 
     source={require('./chats-icon.png')} 
     style={[styles.icon, {tintColor: tintColor}]} 
     /> 
    ), 
    }; 

    render() { 
    return (
     <Button 
     onPress={() => this.props.navigation.navigate('Notifications')} 
     title="Go to notifications" 
     /> 
    ); 
    } 
} 

class MyNotificationsScreen extends React.Component { 
    static navigationOptions = { 
    tabBarLabel: 'Notifications', 
    tabBarIcon: ({ tintColor }) => (
     <Image 
     source={require('./notif-icon.png')} 
     style={[styles.icon, {tintColor: tintColor}]} 
     /> 
    ), 
    }; 

    render() { 
    return (
     <Button 
     onPress={() => this.props.navigation.goBack()} 
     title="Go back home" 
     /> 
    ); 
    } 
} 

const styles = StyleSheet.create({ 
    icon: { 
    width: 26, 
    height: 26, 
    }, 
}); 

const MyApp = TabNavigator({ 
    Home: { 
    screen: MyHomeScreen, 
    }, 
    Notifications: { 
    screen: MyNotificationsScreen, 
    }, 
}, { 
    tabBarOptions: { 
    activeTintColor: '#e91e63', 
    }, 
}); 
AppRegistry.registerComponent('TabNavigator',() => MyApp); 

当我运行这段代码我得到错误

enter image description here 即使我使用那个时候简单的堆栈导航器也是一样的错误 堆栈导航器的代码,我从这个链接

https://reactnavigation.org/docs/intro/

+0

这是'source = {require('./ chats-icon.png')}'你的线还是只是示例代码? –

回答

0

错误告诉你有一个本地图像无法找到获得。 有两个选项:

  1. 创建chats-icon.pngnotif-icon.png并把他们两个的目录中的文件复制从在内容。

  2. source={require('./chats-icon.png')}source={require('./chats-icon.png')}替换为source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}以使用示例远程图像。

这应该消除500错误并让您继续工作。

+0

sory安娜我附上了错误的图片现在chk错误图像我更新了这个... – hammad

+0

那么,退房:https://github.com/react-community/react-navigation/issues/923 –

+0

我chk他们说安装最新版本,我安装最新版本,但不工作..如果你有一个堆栈导航器和标签导航器的其他代码,然后plz告诉..可能对我有帮助... Thans sis响应....:p – hammad

相关问题