繁体   English   中英

TypeError: undefined is not an object (评估'_$$_REQUIRE(_dependencyMap[32], "react-native-safe-area-context").SafeAreaView')

[英]TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[32], "react-native-safe-area-context").SafeAreaView')

我正在尝试使用 react-native 实现聊天应用程序,下面是我的依赖项

"dependencies": {
    "@react-native-async-storage/async-storage": "~1.17.3",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/bottom-tabs": "^6.3.3",
    "@react-navigation/native": "^6.0.11",
    "@react-navigation/stack": "^6.2.2",
    "@reduxjs/toolkit": "^1.8.5",
    "@types/react-redux": "^7.1.24",
    "@types/redux-logger": "^3.0.9",
    "expo": "~46.0.8",
    "expo-splash-screen": "^0.16.2",
    "expo-status-bar": "~1.4.0",
    "firebase": "^9.9.3",
    "native-base": "^3.4.13",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-hook-form": "^7.34.2",
    "react-native": "0.69.5",
    "react-native-gesture-handler": "^2.5.0",
    "react-native-gifted-chat": "^1.0.4",
    "react-native-reanimated": "~2.9.1",
    "react-native-safe-area": "^0.5.1",
    "react-native-safe-area-context": "4.3.1",
    "react-native-screens": "~3.15.0",
    "react-native-svg": "12.3.0",
    "react-native-vector-icons": "^9.2.0",
    "react-native-web": "~0.18.7",
    "react-redux": "^8.0.2",
    "redux": "^4.2.0",
    "redux-logger": "^3.0.6",
    "save-dev": "^0.0.1-security"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/react": "~18.0.14",
    "@types/react-native": "~0.69.1",
    "typescript": "~4.3.5"
  },

这是我的聊天画面

const ChatScreen = ({ navigation, route }: any) => {
    const { data } = route.params;
    const [messages, setMessages] = React.useState<any>([]);
    React.useLayoutEffect(() => {
        navigation.setOptions({
            headerTitle: () => (
                <HStack style={{ marginLeft: 0 }} justifyContent={'center'} fontWeight={'bold'} fontSize={'lg'} alignItems={'center'} space={3}>
                    <Avatar source={{ uri: data.avatar as any }}
                    />
                    <Text numberOfLines={1}>{`${data.lastName} ${data.firstName}`}</Text>
                </HStack>
            ),
        });
    }, [navigation]);
    React.useLayoutEffect(() => {
        setMessages([
            {
                _id: 1,
                text: 'Hello developer',
                createdAt: new Date(),
                user: {
                    _id: 2,
                    name: 'React Native',
                    avatar: 'https://placeimg.com/140/140/any',
                },
            },
        ])
    }, []);
    const onSend = React.useCallback((messages = []) => {
        setMessages((previousMessages: never[] | undefined) => GiftedChat.append(previousMessages, messages))
    }, []);
    return (
        <React.Fragment>
            <View style={{ flex: 1 }}>
                <GiftedChat
                    messages={messages}
                    showAvatarForEveryMessage={true}
                    onSend={messages => onSend(messages as any)}
                    user={{
                        _id: auth?.currentUser?.email as any,
                        name: auth?.currentUser?.displayName as any,
                        avatar: auth?.currentUser?.photoURL as any
                    }}
                />
            </View>
            {
                Platform.OS === 'android' && 
                <KeyboardAvoidingView behavior="padding" keyboardVerticalOffset ={50} />
            }
        </React.Fragment>
    )
}
export default memo(ChatScreen);

但是在运行我的应用程序后,出现以下错误错误日志 1 在此处输入图像描述 错误日志 2 在此处输入图像描述 错误日志 3 在此处输入图像描述 错误日志 4 在此处输入图像描述 来自日志 1 的错误

TypeError: undefined is not an object (evalating '_$$_REQUIRE(_dependencyMap[32], "react-native-safe-area-context").SafeAreaView') 来自日志 2 的错误不变违规:试图注册两个视图同名RNCSafeAreaView

来自日志 3 的错误

错误:需要模块“node_modules\react-native-gifted-chat\node_modules\react-native-safe-area-context\src\index.tsx”,引发异常:Invariant Violation: Tried to register two views with the same名称 RNCSafeAreaView

来自日志 4 的错误

TypeError: undefined is not an object (评估'_$$_REQUIRE(_dependencyMap[32], "react-native-safe-area-context").SafeAreaView')

目前我不知道该怎么办,我需要帮助。

react-native-safe-area-context 需要包装这些东西(我认为)。 重要的是要注意,提供程序不应位于使用 Animated 或 ScrollView 进行动画处理的 View 内,因为它可能会导致非常频繁的更新。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM