0.57.4 navigator issus



  • index.android.js

    /** @format */

    import {AppRegistry} from 'react-native';
    import HomeScreen from './HomeScreen';
    import {name as appName} from './app.json';
    import {createStackNavigator} from "react-navigation";
    import Detail from './Detail'
    import React, {Component} from 'react';
    import {StackNavigator} from 'react-navigation';
    import {Navigator} from "react-native-deprecated-custom-components";
    import ProfileScreen from "./ProfileScreen";
    AppRegistry.registerComponent(appName, () => HomeScreen);

    const RootStack = createStackNavigator({
    Home: { screen: HomeScreen },
    Profile: { screen: ProfileScreen },
    });
    export default RootStack;

    HomeScreen.js

    import React, {Component} from 'react';
    import {Platform, StyleSheet, Text, View,Style,Image,Button,PixelRatio,Navigator,Alert,TouchableOpacity} from 'react-native'
    import LinearGradient from 'react-native-linear-gradient';
    import {DrawerNavigator,TabNavigator,StackNavigator} from 'react-navigation';
    import Details from "./Detail";

    export default class HomeScreen extends React.Component {
    static navigationOptions = {
    title: 'Welcome',
    };
    render() {
    const { navigate } = this.props.navigation;
    return (
    <Button
    title="Go to Jane's profile"
    onPress={() =>
    navigate('Profile', { name: 'Jane' })
    }
    />
    );
    }
    }

    然后报错undefined this.props.navigation,navigate 这个我是按照官网文档写的

    环境:mac os
    android studio:3.2
    webstorm:2018
    0.57.4文档环境



  • 这都什么乱七八糟拼凑的代码
    0.57.4哪来的index.android.js? 从0.49开始这个文件就作废了
    什么StackNavigator,什么Navigator,这也早都作废了



  • @bruceewang0.57.4 navigator issus 中说:

    AppRegistry.registerComponent(appName, () => HomeScreen);

    该注册的组件应该是 RootStack, AppRegistry.registerComponent(appName, () => RootStack);



  • @晴明 是index.js



  • @mirghojam 谢谢我试试,初学不会用