本文整理汇总了Java中com.facebook.react.ReactInstanceManager.getCurrentReactContext方法的典型用法代码示例。如果您正苦于以下问题:Java ReactInstanceManager.getCurrentReactContext方法的具体用法?Java ReactInstanceManager.getCurrentReactContext怎么用?Java ReactInstanceManager.getCurrentReactContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.react.ReactInstanceManager
的用法示例。
在下文中一共展示了ReactInstanceManager.getCurrentReactContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callJavaScript
import com.facebook.react.ReactInstanceManager; //导入方法依赖的package包/类
@ReactMethod
void callJavaScript() {
Activity activity = getCurrentActivity();
if (activity != null) {
MainApplication application = (MainApplication) activity.getApplication();
ReactNativeHost reactNativeHost = application.getReactNativeHost();
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if (reactContext != null) {
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
WritableNativeArray params = new WritableNativeArray();
params.pushString("Hello, JavaScript!");
catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params);
}
}
}
示例2: onCreate
import com.facebook.react.ReactInstanceManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
ReactInstanceManager reactInstanceManager =
ReactInstanceSingleton.getReactInstanceManager(getApplication());
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if (reactContext != null) {
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
serviceTopLevel = catalystInstance.getJSModule(ServiceTopLevel.class);
mRemoteViewsModule = catalystInstance.getJSModule(RemoteViewsModule.class);
} else {
Log.e(TAG, "Couldn't grab JS service code");
}
serviceTopLevel.initService(0);
}
示例3: sendTokenToJS
import com.facebook.react.ReactInstanceManager; //导入方法依赖的package包/类
protected void sendTokenToJS() {
final ReactInstanceManager instanceManager = ((ReactApplication) mAppContext).getReactNativeHost().getReactInstanceManager();
final ReactContext reactContext = instanceManager.getCurrentReactContext();
// Note: Cannot assume react-context exists cause this is an async dispatched service.
if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(TOKEN_RECEIVED_EVENT_NAME, sToken);
}
}