标签: react-native-community-netinfo

错误:构建反应本机应用程序时,com.facebook.react.bridge 包不存在

我有一个反应本机应用程序,可以毫无问题地构建,但是今天在尝试在模拟器上启动该应用程序时,出现以下错误:

my_local_path_to_node_modules\node_modules@react-native-community\netinfo\android\src\main\java\com\reactnativecommunity\netinfo\BroadcastReceiverConnectivityReceiver.java:16:错误:包com.facebook.react.bridge不存在

导入 com.facebook.react.bridge.ReactApplicationContext;

我尝试删除整个 node_modules 文件夹并重新安装 package.json 中的所有内容,使用 gradle 进行清理和构建,但无济于事。

这是我的 package.json

{
  "name": "sgeapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "android_bundle": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/netinfo": "^5.9.10",
    "i18n-js": "^3.8.0",
    "lodash.memoize": "^4.1.2",
    "native-base": "^2.13.14",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-easy-grid": "^0.2.2",
    "react-native-elements": "^1.2.7",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-localize": "^1.4.3",
    "react-native-reanimated": "^1.13.3",
    "react-native-screens": "2.14.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sqlite-storage": "^5.0.0", …
Run Code Online (Sandbox Code Playgroud)

android gradle react-native react-native-community-netinfo

11
推荐指数
1
解决办法
2万
查看次数

@react-native-community/netinfo:安装最新版本后 NativeModule.RNCNetInfo 为空

我已将 react native 版本从0.57更新到 0.59.1。成功更新后,它会在反应本机信息中引发错误,因此我安装了@react-native-community/netinfo 并从反应本机中删除了 Netinfo。

我已经运行以下命令来安装最新版本的 netinfo:

npm install --save @react-native-community/netinfo

react-native 链接@react-native-community/netinfo

cd ios && pod 安装

在运行我的项目时成功链接后,我收到错误 @react-native-community/netinfo: NativeModule.RNCNetInfo is null ...

我也尝试过 netinfo 的第 3 版,但发生了同样的错误。

版本:

@react-native-community/netinfo: ^5.3.2

反应:^16.8.3

反应原生”:^0.59.1

如果有人对此有解决方案,请帮助我。

谢谢。

npm react-native npm-install react-native-community-netinfo

8
推荐指数
1
解决办法
1106
查看次数

如何降级 expo 并安装特定的软件包?

您项目的某些依赖项与当前安装的 expo 软件包版本不兼容: - @react-native-community/netinfo - 预期版本范围:5.5.1 - 实际安装版本:^5.8.0 在安装之前,您的项目可能无法正常工作软件包的正确版本。要安装这些软件包的正确版本,请运行:expo install [package-name ...]

我收到上述警告。是否有任何 cli 命令可以安装特定的 expo 软件包?如果是,请提供。谢谢。

reactjs metro.js react-native expo react-native-community-netinfo

5
推荐指数
1
解决办法
1万
查看次数

React Native - 网络重新连接时不触发 NetInfo.addEventListener

我正在尝试在客户端 React Native 应用程序中实现离线(尚未添加 - 但连接也较低)网络错误弹出消息。

这是我的完整视图代码:

import React, {useState, useEffect} from 'react';
import {Dimensions, View, Text} from 'react-native';
import NetInfo from '@react-native-community/netinfo';
import * as Animatable from 'react-native-animatable';

export default function InternetCheck() {
  const APP_NAME = 'Security App';
  const [isConnected, setIsConnected] = useState(false);
  const [mounted, setMounted] = useState(false);

  useEffect(() => {
    //Intial status

    NetInfo.fetch().then((state) => {
      
        setIsConnected(state.isInternetReachable);
    });

    //Internet connection listener
    NetInfo.addEventListener((state) => {
      console.warn('called');
      console.warn(state.isInternetReachable);

      setIsConnected(state.isInternetReachable);

    });
  }, []);

  return (
    <React.Fragment>
      {!isConnected && (
        <Animatable.View
          style={{
            backgroundColor: …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native react-native-community-netinfo

2
推荐指数
1
解决办法
4665
查看次数

编写一个单元测试来检查应用程序是否在react-native中离线

我有以下组件,如果应用程序离线,它会在应用程序上显示文本。

\n
import React from 'react';\n\nimport { useNetInfo } from '@react-native-community/netinfo';\n\nimport { Label } from 'components/ui';\n\nconst OfflineNotice = () => {\n  const netInfo = useNetInfo();\n\n  if (netInfo.type !== 'unknown' && netInfo.isInternetReachable === false) {\n    return <Label size={18} text='No Internet Connection' />;\n  }\n\n  return null;\n};\n\nexport default OfflineNotice;\n
Run Code Online (Sandbox Code Playgroud)\n

我想为此编写一个单元测试来检查它是否正常工作。我该怎么做?\n我是单元测试新手。我不明白如何嘲笑这个。

\n

我使用打字稿和测试库/反应本机。

\n

更新: \n为什么第一次测试失败?它不应该为空。但它失败了。错误是,

\n
OfflineNotice component \xe2\x80\xba test\n\nexpect(received).not.toBeNull()\n\nReceived: null\n\n  15 | \n  16 |     const { queryByText } = render(<OfflineNotice />);\n> 17 |     expect(queryByText(/no internet connection/i)).not.toBeNull();\n     |                                                        ^\n  18 …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs react-native react-native-community-netinfo react-native-testing-library

1
推荐指数
1
解决办法
4505
查看次数