當前位置: 首頁>>代碼示例>>Java>>正文


Java ReactInstanceManager.getCurrentReactContext方法代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:petterh,項目名稱:react-native-android-activity,代碼行數:18,代碼來源:ActivityStarterModule.java

示例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);
}
 
開發者ID:alangpierce,項目名稱:react-native-android-audio-demo,代碼行數:17,代碼來源:AudioService.java

示例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);
    }
}
 
開發者ID:wix,項目名稱:react-native-notifications,代碼行數:10,代碼來源:GcmToken.java


注:本文中的com.facebook.react.ReactInstanceManager.getCurrentReactContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。