Add ability to expose sync hooks from Java to JS

Summary:
This only works for the new cxx bridge (hopefully open sourcing soon!).

This diff allows Java native modules to expose synchronous hooks to JS via the ReactSyncHook annotation. The methods will appear in JS on the native module object (e.g. you would do `require('UIManager').mySyncHook('foo');`) which allows us to enforce that required native modules are installed at build time. In order to support remote debugging, both the args and return type must be JSON serializable (so that we can go back across to the device to resolve synchronous hooks).

Follow ups will be integration tests, adding support for return types besides void, and adding support for remote debugging.

Reviewed By: mhorowitz

Differential Revision: D3218794

fb-gh-sync-id: 7e3366a8254276f5a55eb806287419287ca9182b
fbshipit-source-id: 7e3366a8254276f5a55eb806287419287ca9182b
This commit is contained in:
Andy Street
2016-04-27 07:50:07 -07:00
committed by Facebook Github Bot 2
parent 171c7230b1
commit 50d8d46733
4 changed files with 198 additions and 51 deletions

View File

@@ -25,6 +25,13 @@ public interface NativeModule {
String getType();
}
/**
* A method that can be called from JS synchronously on the JS thread and return a result.
* @see ReactSyncHook
*/
interface SyncNativeHook {
}
/**
* @return the name of this module. This will be the name used to {@code require()} this module
* from javascript.