gpt4 book ai didi

android - 路由 'EnableNotification' 应该声明一个屏幕

转载 作者:太空狗 更新时间:2023-10-29 16:12:08 25 4
gpt4 key购买 nike

我正在研究 react-native 并尝试集成 react-navigation https://reactnavigation.org/docs/intro/用于导航。我在实现过程中遇到了一些困难。

index.android.js

**
* https://github.com/facebook/react-native
* @flow
*/

import React, { Component } from "react";
import {
AppRegistry,
Image,
View,
Text,
Button,
StyleSheet
} from "react-native";
import { StackNavigator } from "react-navigation";
import EnableNotificationScreen from "./EnableNotification";

class SplashScreen extends Component {
render() {
console.disableYellowBox = true;
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<Image source={require("./img/talk_people.png")} />
<Text style={{ fontSize: 22, textAlign: "center" }}>
Never forget to stay in touch with the people that matter to you.
</Text>
<View style={{ width: 240, marginTop: 30 }}>
<Button
title="CONTINUE"
color="#FE434C"
onPress={() => navigate("EnableNotification")}
/>
</View>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
backgroundColor: "#FFFFFF",
alignItems: "center",
justifyContent: "center",
padding: 16,
flex: 1,
flexDirection: "column"
}
});

const ScheduledApp = StackNavigator(
{
Splash: { screen: SplashScreen },
EnableNotification: { screen: EnableNotificationScreen }
},
{
initialRouteName: "Splash"
}
);

AppRegistry.registerComponent("Scheduled", () => ScheduledApp);

启用通知.js

/**
* https://github.com/facebook/react-native
* @flow
*/

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

export class EnableNotification extends Component {
render() {
return <View><Text>Enable Notification</Text></View>;
}
}

enter image description here

最佳答案

在您的 EnableNotification.js 中,您在没有默认情况下导出您的 EnableNotification 类(这是命名导出)。

然后您在 index.android.js 中使用 import EnableNotificationScreen from "./EnableNotification" 导入它,这导致了错误。

你应该

a) 导出默认的 EnableNotification 屏幕即 export default class EnableNotification extends Component

b) 更改为 import { EnableNotification } from "./EnableNotification"

阅读更多关于导出类型的信息 here

关于android - 路由 'EnableNotification' 应该声明一个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43470494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com