本文整理匯總了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);
}
}