diff --git a/releases/next/docs/native-modules-android.html b/releases/next/docs/native-modules-android.html index 828c97e279b..52e0da82e62 100644 --- a/releases/next/docs/native-modules-android.html +++ b/releases/next/docs/native-modules-android.html @@ -104,7 +104,9 @@ ToastAndroid.(x, y, width, height) => { console.log(x + ':' + y + ':' + width + ':' + height); } -);

A native module is supposed to invoke its callback only once. It can, however, store the callback and invoke it later.

It is very important to highlight that the callback is not invoked immediately after the native function completes - remember that bridge communication is asynchronous, and this too is tied to the run loop.

Promises #

Native modules can also fulfill a promise, which can simplify your code, especially when using ES2016's async/await syntax. When the last parameter of a bridged native method is a Promise, its corresponding JS method will return a JS Promise object.

Refactoring the above code to use a promise instead of callbacks looks like this:

public class UIManagerModule extends ReactContextBaseJavaModule { +);

A native module is supposed to invoke its callback only once. It can, however, store the callback and invoke it later.

It is very important to highlight that the callback is not invoked immediately after the native function completes - remember that bridge communication is asynchronous, and this too is tied to the run loop.

Promises #

Native modules can also fulfill a promise, which can simplify your code, especially when using ES2016's async/await syntax. When the last parameter of a bridged native method is a Promise, its corresponding JS method will return a JS Promise object.

Refactoring the above code to use a promise instead of callbacks looks like this:

import com.facebook.react.bridge.Promise; + +public class UIManagerModule extends ReactContextBaseJavaModule { ... private static final String E_LAYOUT_ERROR = "E_LAYOUT_ERROR";