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

Sid*_*ouk 8 android react-native react-native-android

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

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;
  }
Run Code Online (Sandbox Code Playgroud)

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;
  }
Run Code Online (Sandbox Code Playgroud)

3

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

invoke方法是在JavaMethodWrapper.java368行内定义的

   @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);
          }
....
}
Run Code Online (Sandbox Code Playgroud)

它是从JavaModuleWrapper.java162 开始调用的

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

    mMethods.get(methodId).invoke(mJSInstance, parameters);
  }
Run Code Online (Sandbox Code Playgroud)

我试过的事情:

  1. 在通过执行调用Timing.createTimer之前尝试防御空id if (id == null || id = '') { return null }
  2. 尝试打印在Timing.createTimer之前设置的id,但它导致应用程序停止响应,因为它几乎每秒触发

任何帮助都感激不尽.提前致谢

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

Dan*_*boy 0

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

弄清楚我的问题是什么,但这很奇怪。我只有一个正确的 V 形图标,所以我对后退按钮应用了 180 度旋转变换。当我按下 goBack 时,我遇到了同样的错误:类型错误:预期的动态类型“双”,但有类型“字符串”..如果我删除旋转变换,一切正常哈哈...很奇怪..