Java Code Examples for com.facebook.react.bridge.UiThreadUtil.isOnUiThread()

The following are Jave code examples for showing how to use isOnUiThread() of the com.facebook.react.bridge.UiThreadUtil class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   Source Code and License Vote up 6 votes
/**
 * @return a MessageQueueThreadImpl corresponding to Android's main UI thread.
 */
private static MessageQueueThreadImpl createForMainThread(
    String name,
    QueueThreadExceptionHandler exceptionHandler) {
  Looper mainLooper = Looper.getMainLooper();
  final MessageQueueThreadImpl mqt =
      new MessageQueueThreadImpl(name, mainLooper, exceptionHandler);

  if (UiThreadUtil.isOnUiThread()) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
    MessageQueueThreadRegistry.register(mqt);
  } else {
    UiThreadUtil.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
            MessageQueueThreadRegistry.register(mqt);
          }
        });
  }
  return mqt;
}
 
Example 2
Project: RNLearn_Project1   File: UIViewOperationQueue.java   Source Code and License Vote up 6 votes
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 3
Project: RNLearn_Project1   File: NativeAnimatedNodesManager.java   Source Code and License Vote up 6 votes
@Override
public void onEventDispatch(Event event) {
  // Only support events dispatched from the UI thread.
  if (!UiThreadUtil.isOnUiThread()) {
    return;
  }

  if (!mEventDrivers.isEmpty()) {
    // If the event has a different name in native convert it to it's JS name.
    String eventName = event.getEventName();
    Map<String, String> customEventType = mCustomEventTypes.get(eventName);
    if (customEventType != null) {
      eventName = customEventType.get("registrationName");
    }

    List<EventAnimationDriver> driversForKey = mEventDrivers.get(event.getViewTag() + eventName);
    if (driversForKey != null) {
      for (EventAnimationDriver driver : driversForKey) {
        event.dispatch(driver);
        mRunUpdateNodeList.add(driver.mValueNode);
      }
      updateNodes(mRunUpdateNodeList);
      mRunUpdateNodeList.clear();
    }
  }
}
 
Example 4
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   Source Code and License Vote up 6 votes
/**
 * @return a MessageQueueThreadImpl corresponding to Android's main UI thread.
 */
private static MessageQueueThreadImpl createForMainThread(
    String name,
    QueueThreadExceptionHandler exceptionHandler) {
  Looper mainLooper = Looper.getMainLooper();
  final MessageQueueThreadImpl mqt =
      new MessageQueueThreadImpl(name, mainLooper, exceptionHandler);

  if (UiThreadUtil.isOnUiThread()) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
    MessageQueueThreadRegistry.register(mqt);
  } else {
    UiThreadUtil.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
            MessageQueueThreadRegistry.register(mqt);
          }
        });
  }
  return mqt;
}
 
Example 5
Project: RNLearn_Project1   File: UIViewOperationQueue.java   Source Code and License Vote up 6 votes
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 6
Project: RNLearn_Project1   File: NativeAnimatedNodesManager.java   Source Code and License Vote up 6 votes
@Override
public void onEventDispatch(Event event) {
  // Only support events dispatched from the UI thread.
  if (!UiThreadUtil.isOnUiThread()) {
    return;
  }

  if (!mEventDrivers.isEmpty()) {
    // If the event has a different name in native convert it to it's JS name.
    String eventName = event.getEventName();
    Map<String, String> customEventType = mCustomEventTypes.get(eventName);
    if (customEventType != null) {
      eventName = customEventType.get("registrationName");
    }

    List<EventAnimationDriver> driversForKey = mEventDrivers.get(event.getViewTag() + eventName);
    if (driversForKey != null) {
      for (EventAnimationDriver driver : driversForKey) {
        event.dispatch(driver);
        mRunUpdateNodeList.add(driver.mValueNode);
      }
      updateNodes(mRunUpdateNodeList);
      mRunUpdateNodeList.clear();
    }
  }
}