android - React native - 重新加载什么都不做

标签 android react-native

我刚开始使用 React Native。我连接了智能手机,在 react-native run-android 之后,我可以在屏幕上看到“Hello World”。但是,当我将“Hello World”更改为其他内容、保​​存文件,然后点击我设备上的重新加载命令(摇动手机后)时,我看不到任何更改。我需要再次 react-native run-android 才能看到新的东西。我在 Windows 10 上工作。构建也需要很多时间。我读过类似的东西,但没有找到任何合理的解决方案。谁能帮忙?

另外:有时,当我点击Reload 时,我需要在 packager 服务器终端中按 enter 键以重新加载 View ,但更改不会出现。

最佳答案

我遇到了同样的问题,并找到了几种解决方案。以下对我有用:

使用 >0.29 react-native-versions 启用生命重载

  1. go to file: yourProjectFolder//node_modules/react-native/local-cli/server/server.js
    • Commend the line (62): process.exit(11) -> //process.exit(11)

关于第 2 点:我不确定从什么时候开始 2.1 的解决方案。是需要的,但我认为 ~ react-native v.33。如果有人确切知道,请更正此问题。因为你只要看看你是否在 2 或 2.1 找到了 index.js。路径。

  • 2.1 (Older Path of React-Native FileWatcher index.js) Go to file: yourProjectFolder//node_modules/react-native/node_modules\node-haste\lib\FileWatcher\index.js"

  • 2.2 (Newer Path of React-Native FileWatcher index.js) Go to file: yourProjectFolder\node_modules\react-native\packager\react-packager\src\node-haste\FileWatcher\index.js

2.1 + 2.2 的第 1 步:

    index.js文件的顶部
  • 增加:MAX_WAIT_TIME=120000 > MAX_WAIT_TIME=360000
  • 函数 (_createWatcher) 更改为:

2.1 的第 2 步(index.js 的旧路径)

key: '_createWatcher',
    value: function _createWatcher(rootConfig) {
        var watcher = new WatcherClass(rootConfig.dir, {
            glob: rootConfig.globs,
            dot: false
        });

        return new Promise(function (resolve, reject) {

        const rejectTimeout = setTimeout(function() {
            reject(new Error([
                'Watcher took too long to load',
                'Try running `watchman version` from your terminal',
                'https://facebook.github.io/watchman/docs/troubleshooting.html',
                ].join('\n')));
        }, MAX_WAIT_TIME);

        watcher.once('ready', function () {
          clearTimeout(rejectTimeout);
          resolve(watcher);
        });
    });
}

2.2 的第 2 步(index.js 的新路径)

_createWatcher(rootConfig) {
    var watcher = new WatcherClass(rootConfig.dir, {
        glob: rootConfig.globs,
        dot: false
      });

    return new Promise(function (resolve, reject) {

        const rejectTimeout = setTimeout(function() {
          reject(new Error([
            'Watcher took too long to load',
            'Try running `watchman version` from your terminal',
            'https://facebook.github.io/watchman/docs/troubleshooting.html',
          ].join('\n')));
        }, MAX_WAIT_TIME);

        watcher.once('ready', function () {
          clearTimeout(rejectTimeout);
          resolve(watcher);
        });
    });
}

这个解决方案对我很有效。如果我错了,希望我能帮助你并纠正我。

关于android - React native - 重新加载什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40274012/

相关文章:

react-native - React Native - 使用 resizeMode "contain"垂直对齐图像

xcode - 从 v0.61.5 手动升级到 v0.63.3 后如何修复 'ReactCommon/CallInvoker.h file not found'

java - 如何让信任 anchor 在 Android API 级别 16-19 上正常工作

javascript - 在 .csv 文件中写入度数符号

android - *BindingImpl 类 : cannot inherit from final *Binding

react-native - 避免在 Release模式下在 native react 中缩小

javascript - 升级到 WebStorm 2018.1 后,我在 this.setState 的 React Native 中得到了 "Protected member is not accessible"

javascript - React Native - 导航问题 "undefined is not an object (this.props.navigation.navigate)"

android - Tab里面的ListView不填充高度?

java - AsyncTask android - ExecutionException 错误