React Native RNCNetinfo.getCurrentState获得3个参数,应为2个

slsn1g29  于 2023-03-09  发布在  React
关注(0)|答案(2)|浏览(100)

我正在用RN CLI开发一个应用程序,我的RN版本是0.62.2,当我尝试实现react-native-jitsi-meet库时,我得到这个错误消息RNCNetinfo.getCurrentState got 3 arguments, expected 2。在实现这个库之前Netinfo工作得非常好。只有当我包含react-native-jitsi-meet时才会发生。如果我从我的组件中排除Netinfo代码,jitsi meet开始工作。但我的申请表里需要这两样东西。谁能指出我漏掉了什么?
注意:我的minSdkVersion是21。
我的依赖项是:

"dependencies": {
    "@expo/vector-icons": "^10.2.0",
    "@react-native-community/async-storage": "^1.10.3",
    "@react-native-community/checkbox": "^0.4.1",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "^5.9.0",
    "@react-native-community/picker": "^1.6.1",
    "@react-navigation/bottom-tabs": "^5.5.1",
    "@react-navigation/drawer": "^5.8.1",
    "@react-navigation/native": "^5.5.0",
    "@react-navigation/stack": "^5.4.1",
    "native-base": "^2.13.12",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-jitsi-meet": "^2.1.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-loading-spinner-overlay": "^1.1.0",
    "react-native-reanimated": "^1.9.0",
    "react-native-responsive-screen": "^1.4.1",
    "react-native-safe-area-context": "^3.0.2",
    "react-native-screens": "^2.8.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sweet-alert": "^2.1.0",
    "react-native-vector-icons": "^6.6.0",
    "react-native-webview": "^10.2.3",
    "realm": "^6.0.2"
  },

我的一个组件:

// packages
import React, {  useContext, useEffect, useState }  from 'react';
import { Image, StyleSheet, Text, View } from 'react-native';
import { AuthContext } from './context';

// third party libraries
import { Button, Root } from 'native-base';
import Feather from 'react-native-vector-icons/Feather';
import McIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import NetInfo from "@react-native-community/netinfo";
import SpinnerOverlay from 'react-native-loading-spinner-overlay';
import AsyncStorage from '@react-native-community/async-storage';
import LinearGradient from 'react-native-linear-gradient';
import {
    widthPercentageToDP as wp,
    heightPercentageToDP as hp,
    listenOrientationChange as lor,
    removeOrientationListener as rol
} from 'react-native-responsive-screen';

// @TODO: This is to hide a Warning caused by NativeBase after upgrading to RN 0.62
import { YellowBox } from 'react-native';

YellowBox.ignoreWarnings([
    'Animated: `useNativeDriver` was not specified. This is a required option and must be explicitly set to `true` or `false`',
]);
// ------- END OF WARNING SUPPRESSION

// assets and components
import defaultImage from './../assets/avatar-default.png';

    export const DashboardScreen = ({ navigation }) => {
    
        const [student_details, setStudentDetails] = useState([]);
        const [isLoading, setIsLoading] = useState(false);
        const [site_url, setSiteUrl] = useState('');
        const { signOut } = useContext(AuthContext);
    
        useEffect(() => {
            lor();
    
            setIsLoading(true);
    
            // checking ineternet connectivity
            NetInfo.fetch().then(state => {
                if (state.isConnected && state.isInternetReachable) {
                    let getStudentDetails = async () => {
                        const userToken = await AsyncStorage.getItem('user_token');
                        const siteUrl = await AsyncStorage.getItem('site_url');
                        setSiteUrl(siteUrl);
    
                        // sending an api request to get student details
                        let studentDetailsResponse = await fetch(siteUrl + "/api/student_module/get_student_details", {
                            method: 'GET',
                            headers: {
                                'Accept': 'application/json',
                                'Content-Type': 'application/json',
                                'Authorization': 'Bearer ' + userToken
                            }
                        });
    
                        // processing the api request
                        let studentDetailsJson = await studentDetailsResponse.json();
    
                        if (studentDetailsJson.status == 'success') {
                            setIsLoading(false);
                            setStudentDetails(studentDetailsJson.student_details);
                        } else if (studentDetailsJson.status == 'token_error') {
                            setIsLoading(false);
                            signOut();
                        } else if (studentDetailsJson.error == 'token_expired') {
                            setIsLoading(false);
                            signOut();
                        } else {
                            setIsLoading(false);
    
                            Toast.show({
                                text: studentDetailsJson.message,
                                buttonText: "Okay",
                                type: "warning",
                                duration: 30000
                            });
                        }
                    }
    
                    getStudentDetails();
                } else {
                    setIsLoading(false);
    
                    Toast.show({
                        text: 'No internet connection!',
                        buttonText: "Okay",
                        type: "warning",
                        duration: 30000
                    });
                }
            });
    
            return () => {
                rol();
            };
        }, []);
    
        const onlinePayment = () => {
            navigation.navigate('OnlinePayment');
        }
    
        const homework = () => {
            navigation.navigate('Homework');
        }
    
        const syllabus = () => {
            navigation.navigate('Syllabus');
        }
    
        const onlineClassroom = () => {
            navigation.navigate('OnlineClass');
        }
    
        const styles = StyleSheet.create({
            header: {
                paddingTop: hp("3%"),
                height: hp("32%"),
                borderBottomLeftRadius: 20,
                borderBottomRightRadius: 20,
                backgroundColor: "#ff3542"
            },
            dashboardText: {
                color: "#FFFFFF",
                fontSize: 20,
                fontWeight: 'bold',
                alignSelf: 'center'
            },
            dashboardView: {
                marginLeft: 'auto',
                marginRight: 'auto',
                marginTop: -40,
                paddingLeft: wp("5%"),
                paddingRight: wp("5%"),
                width: '85%',
                display: 'flex',
                flexDirection: 'row',
                justifyContent: 'space-around',
                flexWrap: 'wrap',
            },
            menuView: {
                display: 'flex',
                flexDirection: 'column'
            },
            dashboardCategory: {
                height: 80,
                width: 80,
                borderRadius: 5,
                elevation: 5,
                display: 'flex',
                flexDirection: 'column',
                justifyContent: 'center',
                backgroundColor: '#FFFFFF'
            },
            iconStyle: {
                color: 'grey',
                fontSize: 35
            },
            buttonText: {
                marginTop: 10,
                paddingBottom: hp("2%"),
                color: '#4b2e80',
                width: '100%',
                textAlign:'center',
                fontSize: wp("3.9%")
            },
            defaultImage: {
                marginTop: hp("3%"),
                borderRadius: 50,
                width: hp("10%"),
                height: hp("10%"),
                marginRight: hp("2%"),
                marginLeft: wp("12%")
            },
            studnetDetailsWrapper: {
                marginTop: hp("1.7%"),
                display: 'flex',
                flexDirection: 'row',
                alignItems: 'center'
            },
            studentDetailsView: {
                marginTop: hp("3%"),
                paddingLeft: wp("4%")
            }
        });
    
        return (
            <Root>
                <SpinnerOverlay
                    visible={isLoading}
                    textContent={'Getting Student Details...'}
                    textStyle={styles.spinnerTextStyle}
                />
    
                <LinearGradient
                    start={{x: 0, y: 0}}
                    end={{x: 1, y: 0}}
                    colors={['#ff1a29', '#ff3542', '#ff4d58', '#ff8088']}
                    style={styles.header}>
    
                    <Button
                        transparent
                        style={{ position: 'absolute', left: wp("5%"), top: hp("1.8%") }}
                        onPress={() => navigation.openDrawer()}>
                        <Feather style={{ color: '#FFFFFF' }} name="menu" size={28} />
                    </Button>
                    <Text style={styles.dashboardText}>DASHBOARD</Text>
    
                    <View style={styles.studnetDetailsWrapper}>
                        {student_details.profile_image ? <Image source={{ uri: site_url + "/img/StudentPicture/" + student_details.profile_image }} style={styles.defaultImage} /> : <Image source={ defaultImage } style={styles.defaultImage} /> }
    
                        <View style={{ marginTop: hp("4%"), borderLeftWidth: 2, width: 2, height: 35, borderColor: "#FFFFFF" }}></View>
    
                        <View style={styles.studentDetailsView}>
                            <Text style={{ color: "#FFFFFF", fontWeight: 'bold', fontSize: hp("2.1%") }}>
                                {student_details.student_name}
                            </Text>
    
                            <View>
                                <Text style={{ color: "#FFFFFF", fontWeight: 'bold', fontSize: hp("1.9%"), marginTop: hp("0.2%") }}>
                                    Class:  {(typeof student_details.class_info !== 'undefined' && typeof student_details.class_info.ClassName !== 'undefined') ? student_details.class_info.ClassName : '-'}   |   Roll:  {student_details.roll_no}
                                </Text>
                                <Text style={{ color: "#FFFFFF", fontWeight: 'bold', fontSize: hp("1.9%"), marginTop: hp("0.2%") }}>
                                    Section:  {(typeof student_details.section !== 'undefined' && typeof student_details.section.SectionName !== 'undefined') ? student_details.section.SectionName : '-'}   |   Group:  {(typeof student_details.group !== 'undefined' && typeof student_details.group.GroupName !== 'undefined') ? student_details.group.GroupName : '-'}
                                </Text>
                            </View>
                        </View>
                    </View>
                </LinearGradient>
    
                <View style={styles.dashboardView}>
                    <View style={styles.menuView}>
                        <Button light style={styles.dashboardCategory} onPress={homework}>
                            <Feather style={styles.iconStyle} name="book" size={25} />
                        </Button>
                        <Text style={styles.buttonText}> Homework </Text>
                    </View>
    
                    <View>
                        <Button light style={styles.dashboardCategory} onPress={syllabus}>
                            <Feather style={styles.iconStyle} name="book-open" size={25} />
                        </Button>
                        <Text style={styles.buttonText}> Syllabus </Text>
                    </View>
    
                    <View>
                        <Button light style={styles.dashboardCategory} onPress={onlinePayment}>
                            <Feather style={styles.iconStyle} name='dollar-sign' size={25} />
                        </Button>
                        <Text style={styles.buttonText}> Pay Online </Text>
                    </View>
    
                    <View>
                        <Button light style={styles.dashboardCategory} onPress={onlineClassroom}>
                            <McIcons style={styles.iconStyle} name='google-classroom' size={25} />
                        </Button>
                        <Text style={styles.buttonText}> Online Class </Text>
                    </View>
                </View>
            </Root>
        )
    }
hmae6n7t

hmae6n7t1#

溶液

删除最新版本

npm uninstall @react-native-community/netinfo
npm uninstall @react-native-community/netinfo@5.9.0

安装旧版本

npm uninstall @react-native-community/netinfo@5.0.0

yarn add @react-native-community/netinfo@5.0.0
2g32fytz

2g32fytz2#

将react-native-offline降级到较低版本(版本5.0.0适用于我)

npm install react-native-offline@5.0.0

或者,如果已经安装了它,请在package.json文件中更改其版本并运行npm install

相关问题