我正在React-native + WatermelonDb中为我的新项目创建基本代码。我遵循了他们的官方doc示例,在其文件夹结构中对其进行了一些细微更改。现在,我收到此错误NavigationStack.AppContainer不是一个函数。
index.js文件
import { AppRegistry, NativeModules } from "react-native";
import { name as appName } from "./app.json";
import { Database } from "@nozbe/watermelondb";
import SQLiteAdapter from "@nozbe/watermelondb/adapters/sqlite";
import { mySchema } from "./app/models/schema";
import Blog from "./app/models/Blog";
import Post from "./app/models/Post";
import Comment from "./app/models/Comment";
import { AppContainer } from "./app/navigation/NavigationStack";
const adapter = new SQLiteAdapter({
dbName: "WatermelonDemo",
schema: mySchema
});
const database = new Database({
adapter,
modelClasses: [Blog, Post, Comment],
actionsEnabled: true
});
const Navigation = AppContainer({ database });
AppRegistry.registerComponent(appName, () => Navigation);
NavigationStack.js
import React from "react";
import { createStackNavigator, createAppContainer } from "react-navigation";
import Splash from "../screens/Splash/SplashView";
import Home from "../screens/Home/HomeView";
const RNApp = props =>
createStackNavigator(
{
Splash: {
screen: ({ navigation }) => {
const { database } = navigation.state.params;
return (
<Splash
database={database}
navigation={navigation}
/>
);
},
navigationOptions: { header: null, gesturesEnabled: false }
},
Home: {
screen: Home,
navigationOptions: { header: null, gesturesEnabled: false }
}
},
{
initialRouteName: "Splash",
initialRouteParams: props
}
);
const AppContainer = createAppContainer(RNApp);
export default AppContainer;
我已经参考了他们的官方文档,下面提供了链接以供参考。 Navigation.js和index.js。这是我的文件夹结构。