这个 React-Native 方法示例中的类"Promise"应该来自哪里?



这是React Native Android文档中使用Native模块(java类)实现承诺的一个示例:

@ReactMethod
  public void measureLayout(
      int tag,
      int ancestorTag,
      Promise promise) 

https://facebook.github.io/react-native/docs/native-modules-android.html#content

我得到错误"找不到符号"指向Promise,而Android API似乎没有任何可导入的内容。我应该在哪里/如何获得Promise类?

Promise类从com.facebook.react.bridge包导入。

它是在react native 0.15中添加的,因此请确保android/app/build.gradle编译的版本>0.15。

例如,我的是:

...
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.facebook.react:react-native:0.15.+'
    ...
}