期望动态类型为“double”,但是类型为“null”(在索引1处为Timing.createTimer构造参数)

时间:2018-05-30 23:15:09

标签: android react-native react-native-android

当我运行react-native android时,我一直收到此错误Expected dynamic type `double', but had type `null' (Constructing arguments for Timing.createTimer at index 1)。当我尝试定位Timing.createTimer时,我发现它在node_modules/react-native/Libraries/Core/Timers/JSTimers.js内的3个位置使用:

1

setTimeout: function(
func: Function,
duration: number,
...args?: any
): number {
    if (__DEV__ && IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
      console.warn(
        ANDROID_LONG_TIMER_MESSAGE +
          '\n' +
          '(Saw setTimeout with duration ' +
          duration +
          'ms)',
      );
    }
    const id = _allocateCallback(
      () => func.apply(undefined, args),
      'setTimeout',
    );
    Timing.createTimer(id, duration || 0, Date.now(), /* recurring */ false);
    return id;
  }

2

setInterval: function(
func: Function,
duration: number,
...args?: any


): number {
    if (__DEV__ && IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
      console.warn(
        ANDROID_LONG_TIMER_MESSAGE +
          '\n' +
          '(Saw setInterval with duration ' +
          duration +
          'ms)',
      );
    }
    const id = _allocateCallback(
      () => func.apply(undefined, args),
      'setInterval',
    );
    Timing.createTimer(id, duration || 0, Date.now(), /* recurring */ true);
    return id;
  }

3

  requestAnimationFrame: function(func: Function) {
    const id = _allocateCallback(func, 'requestAnimationFrame');
    Timing.createTimer(id, 1, Date.now(), /* recurring */ false);
    return id;
  }

调用方法是在JavaMethodWrapper.java 368行

中定义的
   @Override
   public void invoke(JSInstance jsInstance, ReadableNativeArray parameters) {
    ....
        try {
            for (; i < mArgumentExtractors.length; i++) {
              mArguments[i] = mArgumentExtractors[i].extractArgument(
                jsInstance, parameters, jsArgumentsConsumed);
              jsArgumentsConsumed += mArgumentExtractors[i].getJSArgumentsNeeded();
            }
          } catch (UnexpectedNativeTypeException e) {
            throw new NativeArgumentsParseException(
              e.getMessage() + " (constructing arguments for " + traceName + " at argument index " +
                getAffectedRange(jsArgumentsConsumed, mArgumentExtractors[i].getJSArgumentsNeeded()) +
                ")",
              e);
          }
....
}

它是从JavaModuleWrapper.java 162

调用的
    @DoNotStrip
  public void invoke(int methodId, ReadableNativeArray parameters) {
    if (mMethods == null || methodId >= mMethods.size()) {
      return;
    }

    mMethods.get(methodId).invoke(mJSInstance, parameters);
  }

我尝试的事情:

  1. 在通过if (id == null || id = '') { return null }
  2. 调用Timing.createTimer之前尝试防御空id
  3. 尝试打印在Timing.createTimer之前设置的ID,但它导致应用程序停止响应,因为它几乎每秒触发
  4. 任何帮助将不胜感激。提前致谢

    PS:我读到有关此问题的每个帖子都找不到适用的解决方案

1 个答案:

答案 0 :(得分:0)

您应该在此处尝试解决方案(针对不同用户的多种解决方案): https://github.com/react-navigation/react-navigation/issues/2387

  

弄清楚我的问题是什么,但是很奇怪。.我只有一个正确的V形图标,因此我在后退按钮上应用了180度旋转变换。.当我按下goBack时,我有这个相同的错误:TypeError:预期的动态类型为'double',但类型为'string'。