如何在 Javascript 上的 React Native 中禁用“快速刷新”(不使用开发人员菜单)

gus*_*ard 2 reactjs react-native

快速刷新在一些排毒测试中被破坏,我需要从 Javascript 中禁用它,而不使用开发人员菜单

任何的想法?

gus*_*ard 6

源代码中找到了答案

对于版本0.61

import { NativeModules } from 'react-native';

if (__DEV__) {
  const { DevSettings } = NativeModules;
  DevSettings.setHotLoadingEnabled(false);
  DevSettings.setLiveReloadEnabled(false);
}
Run Code Online (Sandbox Code Playgroud)

对于版本 >= 0.62

import { DevSettings } from "react-native"

if (__DEV__) {
  DevSettings._nativeModule.setHotLoadingEnabled(false);
}
Run Code Online (Sandbox Code Playgroud)

  • 对于 React Native 0.62.2,`NativeModules` 中不再提供 `DevSettings`,因此直接使用 `import { DevSettings } from "react-native"` 导入,并使用 `DevSettings._nativeModule.setHotLoadingEnabled(false)` 使用该函数。`setLiveReloadEnabled()` [不再可用](https://github.com/facebook/react-native/blob/0.62-stable/Libraries/NativeModules/specs/NativeDevSettings.js) (2认同)