当前位置: 首页>>代码示例>>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;未经允许,请勿转载。