Java Code Examples for com.facebook.react.bridge.ReactContext#hasActiveCatalystInstance()

The following examples show how to use com.facebook.react.bridge.ReactContext#hasActiveCatalystInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactIdleDetectionUtil.java    From react-native-GPay with MIT License 6 votes vote down vote up
private static void waitForJSIdle(ReactContext reactContext) {
  if (!reactContext.hasActiveCatalystInstance()) {
    return;
  }
  final CountDownLatch latch = new CountDownLatch(1);

  reactContext.runOnJSQueueThread(
      new Runnable() {
        @Override
        public void run() {
          latch.countDown();
        }
      });

  try {
    if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
      throw new RuntimeException("Timed out waiting for JS thread");
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 2
Source File: ReactNativeUtils.java    From native-navigation with MIT License 6 votes vote down vote up
/** Emits a JS event with the provided name and data if the rect context is initialized */
static void maybeEmitEvent(ReactContext context, String name, Object data) {
  if (context == null) {
    throw new IllegalArgumentException(
        String.format("reactContext is null (calling event: %s)", name));
  }
  if (context.hasActiveCatalystInstance()) {
    try {
      context.getJSModule(RCTDeviceEventEmitter.class).emit(name, data);
    } catch (RuntimeException e) {
      // the JS bundle hasn't finished executing, so this call is going to be lost.
      // In the future, we could maybe set something up to queue the call, and then pass them through once
      // the bundle has finished getting parsed, but for now I am going to just swallow the error.
    }
  }
}
 
Example 3
Source File: RNCAppearanceModule.java    From react-native-appearance with MIT License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
    if (reactContext.hasActiveCatalystInstance()) {
        FLog.i("sendEvent", eventName + ": " + params.toString());
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    }

}
 
Example 4
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Detach given {@param rootView} from current catalyst instance. It's safe to call this method
 * multiple times on the same {@param rootView} - in that case view will be detached with the
 * first call.
 */
@ThreadConfined(UI)
public void detachRootView(ReactRootView rootView) {
  UiThreadUtil.assertOnUiThread();
  if (mAttachedRootViews.remove(rootView)) {
    ReactContext currentContext = getCurrentReactContext();
    if (currentContext != null && currentContext.hasActiveCatalystInstance()) {
      detachViewFromInstance(rootView, currentContext.getCatalystInstance());
    }
  }
}
 
Example 5
Source File: FusedLocationModule.java    From react-native-fused-location with MIT License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
    if (reactContext.hasActiveCatalystInstance()) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    } else {
        Log.d(TAG, "Waiting for Catalyst Instance...");
    }
}
 
Example 6
Source File: RNShakeEventModule.java    From react-native-shake with MIT License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
  if (reactContext.hasActiveCatalystInstance()) {
    reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
  }
}
 
Example 7
Source File: RNLocationModule.java    From react-native-gps with MIT License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
  if (reactContext.hasActiveCatalystInstance()) {
    reactContext
      .getJSModule(RCTDeviceEventEmitter.class)
      .emit(eventName, params);
  } else {
    Log.i(TAG, "Waiting for CatalystInstance...");
  }
}
 
Example 8
Source File: ReactNativeUtil.java    From react-native-azurenotificationhub with MIT License 5 votes vote down vote up
public static void emitEvent(ReactContext reactContext,
                             String eventName,
                             @Nullable Object params) {
    if (reactContext.hasActiveCatalystInstance()) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    }
}
 
Example 9
Source File: FirestackUtils.java    From react-native-firestack with MIT License 5 votes vote down vote up
/**
* send a JS event
**/
public static void sendEvent(final ReactContext context,
  final String eventName,
  final WritableMap params) {
  if (context.hasActiveCatalystInstance()) {
    context
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit(eventName, params);
  } else {
    Log.d(TAG, "Waiting for CatalystInstance before sending event");
  }
}