React Native Android Undefined不起作用

时间:2018-11-26 06:08:22

标签: android react-native

反应本地android:

当我从一个屏幕导航到下一屏幕时

  

undefined不是函数(计算'(0,   _reactNavigation.StackNavigator)({设置屏幕:{屏幕:_settings.default},主屏幕:{屏幕:_Home.default}})')

App.js

import React, {Component} from 'react';
import { AppRegistry} from 'react-native';
import { Button } from 'react-native';
import {Navigation} from 'react-native'
import { StackNavigator } from 'react-navigation';

import Settings from './screens/Settings';
import Home from './screens/Home';

const AppNavigator = StackNavigator({
  SettingScreen: { screen: Settings },
  HomeScreen: { screen: Home }
});

export default class App extends Component<Props> {

    render() {
    return (
        <AppNavigator />
    );
  }
}

Setting.js

import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';

export class Settings extends Component {
  render() {
    return (
      <View>
        <Text>This is the Settings screen</Text>
        <Button onPress={() => this.props.navigation.navigate('HomeScreen')} title="Home"/>
      </View>
    )
  }
};

export default Settings;

Home.js

import React, { Component } from 'react';
import { View, Text } from 'react-native';

export class Home extends Component {
  render() {
    return (
      <View>
        <Text>This is the home screen</Text>
      </View>
    )
  }
}

export default Home

3 个答案:

答案 0 :(得分:1)

  1. 将您的App.js更新为以下内容。

    const App = createStackNavigator({  主页:主屏幕,  个人资料:ProfileScreen, });

    导出默认的createAppContainer(App);

  2. 删除行导出默认设置;

  3. 删除行导出默认主页;

答案 1 :(得分:0)

请,尝试以下更改。

import { createStackNavigator } from "react-navigation";

const AppNavigator = createStackNavigator(
 {
    SettingScreen: { screen: Settings },
    HomeScreen: { screen: Home }
  }
)

答案 2 :(得分:0)

请尝试如下更新的功能。

const App = createStackNavigator({
Home: {screen: HomeScreen},
Profile: {screen: ProfileScreen},
});